From 8ca91c1196181954e0b3da36110bfe069d2831fe Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 21 Feb 2009 22:00:00 -0400 Subject: Allow balance values to be compared < or > 0 --- src/value.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/value.cc b/src/value.cc index 90067bba..ad4047cd 100644 --- a/src/value.cc +++ b/src/value.cc @@ -769,6 +769,27 @@ bool value_t::is_less_than(const value_t& val) const } break; + case BALANCE: + switch (val.type()) { + case INTEGER: + if (val.as_long() != 0) + break; + // fall through... + case AMOUNT: + if (val.is_nonzero()) + break; + + foreach (const balance_t::amounts_map::value_type& pair, + as_balance().amounts) { + if (pair.second > 0L) + return false; + } + return true; + default: + break; + } + break; + case STRING: if (val.is_string()) return as_string() < val.as_string(); @@ -818,6 +839,27 @@ bool value_t::is_greater_than(const value_t& val) const } break; + case BALANCE: + switch (val.type()) { + case INTEGER: + if (val.as_long() != 0) + break; + // fall through... + case AMOUNT: + if (val.is_nonzero()) + break; + + foreach (const balance_t::amounts_map::value_type& pair, + as_balance().amounts) { + if (pair.second < 0L) + return false; + } + return true; + default: + break; + } + break; + case STRING: if (val.is_string()) return as_string() > val.as_string(); -- cgit v1.2.3