summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-03 06:11:04 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:36 -0400
commitc59018c29ddfc7a46aeb951fbcd5cb5b93f47ec0 (patch)
tree204d28bfa2bdbfe8d7f550877faa114c1e93859f /src/value.cc
parentf9f24fab933266ab8e12da7eef4cc2a906f77350 (diff)
downloadfork-ledger-c59018c29ddfc7a46aeb951fbcd5cb5b93f47ec0.tar.gz
fork-ledger-c59018c29ddfc7a46aeb951fbcd5cb5b93f47ec0.tar.bz2
fork-ledger-c59018c29ddfc7a46aeb951fbcd5cb5b93f47ec0.zip
Revised how commodities are dealt with.
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc126
1 files changed, 58 insertions, 68 deletions
diff --git a/src/value.cc b/src/value.cc
index b181df8f..e1cfa736 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1647,7 +1647,7 @@ void value_t::in_place_cast(type_t cast_type)
break;
}
if (alldigits) {
- long temp = lexical_cast<long>((*(string **) data)->c_str());
+ long temp = std::atol((*(string **) data)->c_str());
destroy();
*(long *) data = temp;
} else {
@@ -1840,7 +1840,7 @@ bool value_t::realzero() const
return 0;
}
-value_t value_t::value(const moment_t& moment) const
+value_t value_t::value(const optional<moment_t>& moment) const
{
switch (type) {
case BOOLEAN:
@@ -1849,16 +1849,30 @@ value_t value_t::value(const moment_t& moment) const
throw_(value_error, "Cannot find the value of a date/time");
case INTEGER:
return *this;
- case AMOUNT:
- return ((amount_t *) data)->value(moment);
- case BALANCE:
- return ((balance_t *) data)->value(moment);
- case BALANCE_PAIR:
- return ((balance_pair_t *) data)->quantity.value(moment);
+
+ case AMOUNT: {
+ if (optional<amount_t> val = ((amount_t *) data)->value(moment))
+ return *val;
+ return false;
+ }
+ case BALANCE: {
+ if (optional<balance_t> bal = ((balance_t *) data)->value(moment))
+ return *bal;
+ return false;
+ }
+ case BALANCE_PAIR: {
+ if (optional<balance_t> bal =
+ ((balance_pair_t *) data)->quantity.value(moment))
+ return *bal;
+ return false;
+ }
+
case STRING:
throw_(value_error, "Cannot find the value of a string");
+
case XML_NODE:
return (*(xml::node_t **) data)->to_value().value(moment);
+
case POINTER:
throw_(value_error, "Cannot find the value of a pointer");
case SEQUENCE:
@@ -1954,45 +1968,37 @@ value_t value_t::unround() const
return value_t();
}
-value_t value_t::price() const
+value_t value_t::annotated_price() const
{
switch (type) {
case BOOLEAN:
- throw_(value_error, "Cannot find the price of a boolean");
+ throw_(value_error, "Cannot find the annotated price of a boolean");
case INTEGER:
return *this;
case DATETIME:
- throw_(value_error, "Cannot find the price of a date/time");
+ throw_(value_error, "Cannot find the annotated price of a date/time");
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();
+ optional<amount_t> temp = ((amount_t *) data)->annotation_details().price;
if (! temp)
return false;
return *temp;
}
+ case BALANCE:
+ throw_(value_error, "Cannot find the annotated price of a balance");
+ case BALANCE_PAIR:
+ throw_(value_error, "Cannot find the annotated price of a balance pair");
case STRING:
- throw_(value_error, "Cannot find the price of a string");
+ throw_(value_error, "Cannot find the annotated price of a string");
case XML_NODE:
- return (*(xml::node_t **) data)->to_value().price();
+ return (*(xml::node_t **) data)->to_value().annotated_price();
case POINTER:
- throw_(value_error, "Cannot find the price of a pointer");
+ throw_(value_error, "Cannot find the annotated price of a pointer");
case SEQUENCE:
- throw_(value_error, "Cannot find the price of a sequence");
+ throw_(value_error, "Cannot find the annotated price of a sequence");
default:
assert(0);
@@ -2002,46 +2008,38 @@ value_t value_t::price() const
return value_t();
}
-value_t value_t::date() const
+value_t value_t::annotated_date() const
{
switch (type) {
case BOOLEAN:
- throw_(value_error, "Cannot find the date of a boolean");
+ throw_(value_error, "Cannot find the annotated date of a boolean");
case INTEGER:
- throw_(value_error, "Cannot find the date of an integer");
+ throw_(value_error, "Cannot find the annotated date of an integer");
case DATETIME:
return *this;
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();
+ optional<moment_t> temp = ((amount_t *) data)->annotation_details().date;
if (! temp)
return false;
return *temp;
}
+ case BALANCE:
+ throw_(value_error, "Cannot find the annotated date of a balance");
+ case BALANCE_PAIR:
+ throw_(value_error, "Cannot find the annotated date of a balance pair");
case STRING:
- throw_(value_error, "Cannot find the date of a string");
+ throw_(value_error, "Cannot find the annotated date of a string");
case XML_NODE:
- return (*(xml::node_t **) data)->to_value().date();
+ return (*(xml::node_t **) data)->to_value().annotated_date();
case POINTER:
- throw_(value_error, "Cannot find the date of a pointer");
+ throw_(value_error, "Cannot find the annotated date of a pointer");
case SEQUENCE:
- throw_(value_error, "Cannot find the date of a sequence");
+ throw_(value_error, "Cannot find the annotated date of a sequence");
default:
assert(0);
@@ -2051,46 +2049,38 @@ value_t value_t::date() const
return value_t();
}
-value_t value_t::tag() const
+value_t value_t::annotated_tag() const
{
switch (type) {
case BOOLEAN:
- throw_(value_error, "Cannot find the date of a boolean");
+ throw_(value_error, "Cannot find the annotated tag of a boolean");
case INTEGER:
- throw_(value_error, "Cannot find the date of an integer");
+ throw_(value_error, "Cannot find the annotated tag 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();
+ optional<string> temp = ((amount_t *) data)->annotation_details().tag;
if (! temp)
return false;
return *temp;
}
+ case BALANCE:
+ throw_(value_error, "Cannot find the annotated tag of a balance");
+ case BALANCE_PAIR:
+ throw_(value_error, "Cannot find the annotated tag of a balance pair");
case STRING:
- throw_(value_error, "Cannot find the date of a string");
+ throw_(value_error, "Cannot find the annotated tag of a string");
case XML_NODE:
- return (*(xml::node_t **) data)->to_value().date();
+ return (*(xml::node_t **) data)->to_value().annotated_tag();
case POINTER:
- throw_(value_error, "Cannot find the date of a pointer");
+ throw_(value_error, "Cannot find the annotated tag of a pointer");
case SEQUENCE:
- throw_(value_error, "Cannot find the date of a sequence");
+ throw_(value_error, "Cannot find the annotated tag of a sequence");
default:
assert(0);