diff options
author | John Wiegley <johnw@newartisans.com> | 2007-04-30 12:20:58 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:34 -0400 |
commit | 18aaf588ab55dfef5556e27ab69491f4c77ad303 (patch) | |
tree | 2a0d2d3afb537d93f23085f0b9cbe6b9cf8562a4 /src/balance.cc | |
parent | 21af83013f3b1bae511a61b9e27224ab3de235c1 (diff) | |
download | fork-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/balance.cc')
-rw-r--r-- | src/balance.cc | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/balance.cc b/src/balance.cc index 73fd668c..462a7074 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -39,30 +39,51 @@ balance_t balance_t::value(const moment_t& moment) const return temp; } -balance_t balance_t::price() const +optional<balance_t> balance_t::price() const { - balance_t temp; + optional<balance_t> temp; for (amounts_map::const_iterator i = amounts.begin(); i != amounts.end(); - i++) - temp += (*i).second.price(); + i++) { + optional<amount_t> i_price = (*i).second.price(); + if (i_price) { + if (! temp) + temp = balance_t(); + *temp += *i_price; + } + } + return temp; +} +optional<moment_t> balance_t::date() const +{ + optional<moment_t> temp; + + for (amounts_map::const_iterator i = amounts.begin(); + i != amounts.end(); + i++) { + optional<moment_t> tdate = (*i).second.date(); + if (! temp && tdate) + temp = *tdate; + else if (temp && tdate && temp != tdate) + return optional<moment_t>(); + } return temp; } -moment_t balance_t::date() const +optional<string> balance_t::tag() const { - moment_t temp; + optional<string> temp; for (amounts_map::const_iterator i = amounts.begin(); i != amounts.end(); i++) { - moment_t tdate = (*i).second.date(); - if (! is_valid_moment(temp) && is_valid_moment(tdate)) - temp = tdate; - else if (temp != tdate) - return moment_t(); + optional<string> ttag = (*i).second.tag(); + if (! temp && ttag) + temp = *ttag; + else if (temp && ttag && temp != ttag) + return optional<string>(); } return temp; } |