diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/amount.cc | 18 | ||||
-rw-r--r-- | src/commodity.cc | 25 | ||||
-rw-r--r-- | src/commodity.h | 17 | ||||
-rw-r--r-- | src/global.cc | 3 |
4 files changed, 28 insertions, 35 deletions
diff --git a/src/amount.cc b/src/amount.cc index 6d94cee1..5d44251a 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -1014,19 +1014,13 @@ void amount_t::print(std::ostream& _out) const comm.print(out); } - // If there are any annotations associated with this commodity, - // output them now. - - if (comm.annotated) { - annotated_commodity_t& ann(static_cast<annotated_commodity_t&>(comm)); - assert(! ann.details.price || &*ann.details.price != this); - ann.write_annotations(out); - } - - // Things are output to a string first, so that if anyone has - // specified a width or fill for _out, it will be applied to the - // entire amount string, and not just the first part. + // If there are any annotations associated with this commodity, output them + // now. + comm.write_annotations(out); + // Things are output to a string first, so that if anyone has specified a + // width or fill for _out, it will be applied to the entire amount string, + // and not just the first part. _out << out.str(); } diff --git a/src/commodity.cc b/src/commodity.cc index c65ad0a4..1721697c 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -737,17 +737,21 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep) return *new_comm; } -void annotated_commodity_t::write_annotations(std::ostream& out, - const annotation_t& info) +void annotated_commodity_t::write_annotations(std::ostream& out) const { - if (info.price) - out << " {" << *info.price << '}'; + details.print(out, parent().keep_base); +} + +void annotation_t::print(std::ostream& out, bool keep_base) const +{ + if (price) + out << " {" << (keep_base ? *price : price->unreduced()).rounded() << '}'; - if (info.date) - out << " [" << format_date(*info.date, string("%Y/%m/%d")) << ']'; + if (date) + out << " [" << format_date(*date, string("%Y/%m/%d")) << ']'; - if (info.tag) - out << " (" << *info.tag << ')'; + if (tag) + out << " (" << *tag << ')'; } bool compare_amount_commodities::operator()(const amount_t * left, @@ -817,7 +821,8 @@ bool compare_amount_commodities::operator()(const amount_t * left, } } -commodity_pool_t::commodity_pool_t() : default_commodity(NULL) +commodity_pool_t::commodity_pool_t() + : default_commodity(NULL), keep_base(false) { TRACE_CTOR(commodity_pool_t, ""); null_commodity = create(""); @@ -894,7 +899,7 @@ namespace { std::ostringstream name; comm.print(name); - annotated_commodity_t::write_annotations(name, details); + details.print(name, comm.parent().keep_base); DEBUG("amounts.commodities", "make_qualified_name for " << comm.qualified_symbol << std::endl << details); diff --git a/src/commodity.h b/src/commodity.h index d2c778c2..93b5bf1d 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -391,11 +391,8 @@ struct annotation_t : public equality_comparable<annotation_t> } void parse(std::istream& in); - void print(std::ostream& out) const { - out << "price " << (price ? price->to_string() : "NONE") << " " - << "date " << (date ? *date : date_t()) << " " - << "tag " << (tag ? *tag : "NONE"); - } + + void print(std::ostream& out, bool keep_base = false) const; bool valid() const { assert(*this); @@ -486,13 +483,7 @@ public: } virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep); - - virtual void write_annotations(std::ostream& out) const { - annotated_commodity_t::write_annotations(out, details); - } - - static void write_annotations(std::ostream& out, - const annotation_t& info); + virtual void write_annotations(std::ostream& out) const; }; inline annotated_commodity_t& @@ -535,6 +526,8 @@ public: commodity_t * null_commodity; commodity_t * default_commodity; + bool keep_base; + public: boost::function<optional<amount_t> (commodity_t& commodity, diff --git a/src/global.cc b/src/global.cc index e3969481..c0c95b5e 100644 --- a/src/global.cc +++ b/src/global.cc @@ -373,7 +373,8 @@ void global_scope_t::normalize_report_options(const string& verb) report_t& rep(report()); // jww (2009-02-09): These global are a hack, but hard to avoid. - item_t::use_effective_date = rep.HANDLED(effective); + item_t::use_effective_date = rep.HANDLED(effective); + rep.session.commodity_pool->keep_base = rep.HANDLED(base); if (rep.HANDLED(date_format_)) { output_datetime_format = rep.HANDLER(date_format_).str() + " %H:%M:%S"; |