summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-29 16:25:22 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-29 16:25:22 -0500
commit0f180b917ae00b7b247db367020fd29823000877 (patch)
tree632df80d2f2a1387dfd4f6b67eda1baf2c2e08d8
parent7422fa5f3e2505dfa8f5494e4ce9e987440a57a1 (diff)
downloadfork-ledger-0f180b917ae00b7b247db367020fd29823000877.tar.gz
fork-ledger-0f180b917ae00b7b247db367020fd29823000877.tar.bz2
fork-ledger-0f180b917ae00b7b247db367020fd29823000877.zip
Improved some error messages
-rw-r--r--src/amount.cc18
-rw-r--r--src/annotate.h8
-rw-r--r--src/commodity.cc2
-rw-r--r--src/commodity.h5
4 files changed, 20 insertions, 13 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 8c5ae574..2f7b434e 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -398,8 +398,8 @@ int amount_t::compare(const amount_t& amt) const
if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity())
throw_(amount_error,
- _("Cannot compare amounts with different commodities: %1 and %2")
- << commodity().symbol() << amt.commodity().symbol());
+ _("Cannot compare amounts with different commodities: '%1' and '%2'")
+ << commodity() << amt.commodity());
return mpq_cmp(MP(quantity), MP(amt.quantity));
}
@@ -430,12 +430,11 @@ amount_t& amount_t::operator+=(const amount_t& amt)
throw_(amount_error, _("Cannot add two uninitialized amounts"));
}
- if (has_commodity() && amt.has_commodity() &&
- commodity() != amt.commodity())
+ if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) {
throw_(amount_error,
- _("Adding amounts with different commodities: %1 != %2")
- << (has_commodity() ? commodity().symbol() : _("NONE"))
- << (amt.has_commodity() ? amt.commodity().symbol() : _("NONE")));
+ _("Adding amounts with different commodities: '%1' != '%2'")
+ << commodity() << amt.commodity());
+ }
_dup();
@@ -464,9 +463,8 @@ amount_t& amount_t::operator-=(const amount_t& amt)
if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity())
throw_(amount_error,
- _("Subtracting amounts with different commodities: %1 != %2")
- << (has_commodity() ? commodity().symbol() : _("NONE"))
- << (amt.has_commodity() ? amt.commodity().symbol() : _("NONE")));
+ _("Subtracting amounts with different commodities: '%1' != '%2'")
+ << commodity() << amt.commodity());
_dup();
diff --git a/src/annotate.h b/src/annotate.h
index 85a34662..878d6148 100644
--- a/src/annotate.h
+++ b/src/annotate.h
@@ -262,6 +262,14 @@ public:
const datetime_t& oldest = datetime_t()) const;
virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
+
+ virtual void print(std::ostream& out, bool elide_quotes = false,
+ bool print_annotations = false) const {
+ commodity_t::print(out, elide_quotes);
+ if (print_annotations)
+ write_annotations(out);
+ }
+
virtual void write_annotations(std::ostream& out,
bool no_computed_annotations = false) const;
diff --git a/src/commodity.cc b/src/commodity.cc
index 51b8f29c..bc04c3db 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -384,7 +384,7 @@ void commodity_t::parse_symbol(char *& p, string& symbol)
throw_(amount_error, _("Failed to parse commodity"));
}
-void commodity_t::print(std::ostream& out, bool elide_quotes) const
+void commodity_t::print(std::ostream& out, bool elide_quotes, bool) const
{
string sym = symbol();
if (elide_quotes && has_flags(COMMODITY_STYLE_SEPARATED) &&
diff --git a/src/commodity.h b/src/commodity.h
index ba47a572..d6885ee9 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -303,7 +303,8 @@ public:
return temp;
}
- void print(std::ostream& out, bool elide_quotes = false) const;
+ virtual void print(std::ostream& out, bool elide_quotes = false,
+ bool print_annotations = false) const;
bool valid() const;
struct compare_by_commodity {
@@ -338,7 +339,7 @@ private:
};
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
- comm.print(out);
+ comm.print(out, false, true);
return out;
}