summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-05 17:40:07 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-05 17:43:28 -0500
commit5e3f3d7f4730dd2990b6b56352e4a09cdde9a234 (patch)
treed9418af372ffea3886f15f5faf562ac852a0daa9 /src/value.cc
parent1bdb9330e56e49ecd660f3aafdc2d349a20e3044 (diff)
downloadfork-ledger-5e3f3d7f4730dd2990b6b56352e4a09cdde9a234.tar.gz
fork-ledger-5e3f3d7f4730dd2990b6b56352e4a09cdde9a234.tar.bz2
fork-ledger-5e3f3d7f4730dd2990b6b56352e4a09cdde9a234.zip
Report sought magnitude when balancing errors occur
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/value.cc b/src/value.cc
index 4529300a..e2c9dc8b 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -279,6 +279,35 @@ void value_t::in_place_simplify()
#endif
}
+value_t value_t::number() const
+{
+ switch (type()) {
+ case VOID:
+ return 0L;
+ case BOOLEAN:
+ return as_boolean() ? 1L : 0L;
+ case INTEGER:
+ return as_long();
+ case AMOUNT:
+ return as_amount().number();
+ case BALANCE:
+ return as_balance().number();
+ case SEQUENCE:
+ if (! as_sequence().empty()) {
+ value_t temp;
+ foreach (const value_t& value, as_sequence())
+ temp += value.number();
+ return temp;
+ }
+ break;
+ default:
+ break;
+ }
+
+ throw_(value_error, _("Cannot determine numeric value of %1") << label());
+ return false;
+}
+
value_t& value_t::operator+=(const value_t& val)
{
if (is_string()) {