From 18aaf588ab55dfef5556e27ab69491f4c77ad303 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 30 Apr 2007 12:20:58 +0000 Subject: Added use of boost::optional<> to amount.h --- src/value.cc | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 12 deletions(-) (limited to 'src/value.cc') 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 temp = ((amount_t *) data)->price(); + if (! temp) + return false; + return *temp; + } + case BALANCE: { + optional temp = ((balance_t *) data)->price(); + if (! temp) + return false; + return *temp; + } + case BALANCE_PAIR: { + optional 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 temp = ((amount_t *) data)->date(); + if (! temp) + return false; + return *temp; + } + case BALANCE: { + optional temp = ((balance_t *) data)->date(); + if (! temp) + return false; + return *temp; + } + case BALANCE_PAIR: { + optional 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 temp = ((amount_t *) data)->tag(); + if (! temp) + return false; + return *temp; + } + case BALANCE: { + optional temp = ((balance_t *) data)->tag(); + if (! temp) + return false; + return *temp; + } + case BALANCE_PAIR: { + optional temp = ((balance_pair_t *) data)->tag(); + if (! temp) + return false; + return *temp; + } case STRING: throw_(value_error, "Cannot find the date of a string"); -- cgit v1.2.3