summaryrefslogtreecommitdiff
path: root/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-08 23:00:53 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:29 -0400
commit47e2a341764b1747a0b010b3304233f7643f2a70 (patch)
tree593daa0b64c83657dc0d5e2dfcea9b78e37ca0c2 /value.cc
parentf1d5716b95e770b53a43a5794782a34c78f0ae9f (diff)
downloadfork-ledger-47e2a341764b1747a0b010b3304233f7643f2a70.tar.gz
fork-ledger-47e2a341764b1747a0b010b3304233f7643f2a70.tar.bz2
fork-ledger-47e2a341764b1747a0b010b3304233f7643f2a70.zip
*** empty log message ***
Diffstat (limited to 'value.cc')
-rw-r--r--value.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/value.cc b/value.cc
index 758a9c9b..a60de5bd 100644
--- a/value.cc
+++ b/value.cc
@@ -1331,6 +1331,55 @@ value_t& value_t::add(const amount_t& amount, const amount_t * cost)
return *this;
}
+value_context::value_context(const value_t& _bal,
+ const std::string& desc) throw()
+ : bal(new value_t(_bal)), error_context(desc) {}
+
+value_context::~value_context() throw()
+{
+ delete bal;
+}
+
+void value_context::describe(std::ostream& out) const throw()
+{
+ if (! desc.empty())
+ out << desc << std::endl;
+
+ ledger::balance_t * ptr = NULL;
+
+ out << std::right;
+ out.width(20);
+
+ switch (bal->type) {
+ case ledger::value_t::BOOLEAN:
+ out << (*((bool *) bal->data) ? "true" : "false");
+ break;
+ case ledger::value_t::INTEGER:
+ out << *((long *) bal->data);
+ break;
+ case ledger::value_t::DATETIME:
+ out << *((datetime_t *) bal->data);
+ break;
+ case ledger::value_t::AMOUNT:
+ out << *((ledger::amount_t *) bal->data);
+ break;
+ case ledger::value_t::BALANCE:
+ ptr = (ledger::balance_t *) bal->data;
+ // fall through...
+
+ case ledger::value_t::BALANCE_PAIR:
+ if (! ptr)
+ ptr = &((ledger::balance_pair_t *) bal->data)->quantity;
+
+ ptr->write(out, 20);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ out << std::endl;
+}
+
} // namespace ledger
#ifdef USE_BOOST_PYTHON