summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-30 12:20:58 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:34 -0400
commit18aaf588ab55dfef5556e27ab69491f4c77ad303 (patch)
tree2a0d2d3afb537d93f23085f0b9cbe6b9cf8562a4 /src/value.cc
parent21af83013f3b1bae511a61b9e27224ab3de235c1 (diff)
downloadfork-ledger-18aaf588ab55dfef5556e27ab69491f4c77ad303.tar.gz
fork-ledger-18aaf588ab55dfef5556e27ab69491f4c77ad303.tar.bz2
fork-ledger-18aaf588ab55dfef5556e27ab69491f4c77ad303.zip
Added use of boost::optional<> to amount.h
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc97
1 files changed, 85 insertions, 12 deletions
diff --git a/src/value.cc b/src/value.cc
index c5c67b34..74a3bd8f 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1981,12 +1981,24 @@ value_t value_t::price() const
case DATETIME:
throw_(value_error, "Cannot find the price of a date/time");
- case AMOUNT:
- return ((amount_t *) data)->price();
- case BALANCE:
- return ((balance_t *) data)->price();
- case BALANCE_PAIR:
- return ((balance_pair_t *) data)->quantity.price();
+ case AMOUNT: {
+ optional<amount_t> temp = ((amount_t *) data)->price();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE: {
+ optional<balance_t> temp = ((balance_t *) data)->price();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE_PAIR: {
+ optional<balance_t> temp = ((balance_pair_t *) data)->price();
+ if (! temp)
+ return false;
+ return *temp;
+ }
case STRING:
throw_(value_error, "Cannot find the price of a string");
@@ -2018,12 +2030,73 @@ value_t value_t::date() const
case DATETIME:
return *this;
- case AMOUNT:
- return ((amount_t *) data)->date();
- case BALANCE:
- return ((balance_t *) data)->date();
- case BALANCE_PAIR:
- return ((balance_pair_t *) data)->quantity.date();
+ case AMOUNT: {
+ optional<moment_t> temp = ((amount_t *) data)->date();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE: {
+ optional<moment_t> temp = ((balance_t *) data)->date();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE_PAIR: {
+ optional<moment_t> temp = ((balance_pair_t *) data)->date();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+
+ case STRING:
+ throw_(value_error, "Cannot find the date of a string");
+
+ case XML_NODE:
+ return (*(xml::node_t **) data)->to_value().date();
+
+ case POINTER:
+ throw_(value_error, "Cannot find the date of a pointer");
+ case SEQUENCE:
+ throw_(value_error, "Cannot find the date of a sequence");
+
+ default:
+ assert(0);
+ break;
+ }
+ assert(0);
+ return value_t();
+}
+
+value_t value_t::tag() const
+{
+ switch (type) {
+ case BOOLEAN:
+ throw_(value_error, "Cannot find the date of a boolean");
+ case INTEGER:
+ throw_(value_error, "Cannot find the date of an integer");
+
+ case DATETIME:
+ return *this;
+
+ case AMOUNT: {
+ optional<string> temp = ((amount_t *) data)->tag();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE: {
+ optional<string> temp = ((balance_t *) data)->tag();
+ if (! temp)
+ return false;
+ return *temp;
+ }
+ case BALANCE_PAIR: {
+ optional<string> temp = ((balance_pair_t *) data)->tag();
+ if (! temp)
+ return false;
+ return *temp;
+ }
case STRING:
throw_(value_error, "Cannot find the date of a string");