summaryrefslogtreecommitdiff
path: root/src/commodity.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-09 13:25:45 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-09 13:25:45 -0500
commit865c0ff828f88ed1d00eea73a3fc55b3e57d21b3 (patch)
tree5acdfae32811b25fb46271bf349a216bea41fddb /src/commodity.cc
parent55c7792c9329f97dd19fc5aeca466cb2de4fbf9c (diff)
parent9b396b41220646cf73fcd2a8afebcee06dde2a29 (diff)
downloadfork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.tar.gz
fork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.tar.bz2
fork-ledger-865c0ff828f88ed1d00eea73a3fc55b3e57d21b3.zip
Merge branch 'next'
Diffstat (limited to 'src/commodity.cc')
-rw-r--r--src/commodity.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/commodity.cc b/src/commodity.cc
index 0d6c11c6..49e82b53 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -654,4 +654,51 @@ bool compare_amount_commodities::operator()(const amount_t * left,
}
}
+void to_xml(std::ostream& out, const commodity_t& comm,
+ bool commodity_details)
+{
+ push_xml x(out, "commodity", true);
+
+ out << " flags=\"";
+ if (! (comm.has_flags(COMMODITY_STYLE_SUFFIXED))) out << 'P';
+ if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << 'S';
+ if (comm.has_flags(COMMODITY_STYLE_THOUSANDS)) out << 'T';
+ if (comm.has_flags(COMMODITY_STYLE_EUROPEAN)) out << 'E';
+ out << '"';
+
+ x.close_attrs();
+
+ {
+ push_xml y(out, "symbol");
+ out << y.guard(comm.symbol());
+ }
+
+ if (commodity_details) {
+ if (comm.is_annotated())
+ to_xml(out, as_annotated_commodity(comm).details);
+
+ if (comm.varied_history()) {
+ push_xml y(out, "varied-history");
+
+ foreach (const commodity_t::history_by_commodity_map::value_type& pair,
+ comm.varied_history()->histories) {
+ {
+ push_xml z(out, "symbol");
+ out << y.guard(pair.first->symbol());
+ }
+ {
+ push_xml z(out, "history");
+
+ foreach (const commodity_t::history_map::value_type& inner_pair,
+ pair.second.prices) {
+ push_xml w(out, "price-point");
+ to_xml(out, inner_pair.first);
+ to_xml(out, inner_pair.second);
+ }
+ }
+ }
+ }
+ }
+}
+
} // namespace ledger