summaryrefslogtreecommitdiff
path: root/src/balance.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-02 04:40:51 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-02 04:40:51 -0500
commitf9b833b685251e0787a8282a256588328bd68ad7 (patch)
tree51f72a0f369201009e9c2aa11fec7b2552ee5906 /src/balance.h
parent60d016a21cabf35d6f1a97f713d217398f303f2b (diff)
downloadfork-ledger-f9b833b685251e0787a8282a256588328bd68ad7.tar.gz
fork-ledger-f9b833b685251e0787a8282a256588328bd68ad7.tar.bz2
fork-ledger-f9b833b685251e0787a8282a256588328bd68ad7.zip
Corrected balance_t's arithmetic interface
Diffstat (limited to 'src/balance.h')
-rw-r--r--src/balance.h35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/balance.h b/src/balance.h
index 5452510b..ad340aa5 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -207,7 +207,7 @@ public:
template <typename T>
bool operator==(const T& val) const {
- return *this == balance_t(val);
+ return *this == amount_t(val);
}
/**
@@ -217,11 +217,29 @@ public:
*/
balance_t& operator+=(const balance_t& bal);
balance_t& operator+=(const amount_t& amt);
+ balance_t& operator+=(const double val) {
+ return *this += amount_t(val);
+ }
+ balance_t& operator+=(const unsigned long val) {
+ return *this += amount_t(val);
+ }
+ balance_t& operator+=(const long val) {
+ return *this += amount_t(val);
+ }
+
balance_t& operator-=(const balance_t& bal);
balance_t& operator-=(const amount_t& amt);
+ balance_t& operator-=(const double val) {
+ return *this -= amount_t(val);
+ }
+ balance_t& operator-=(const unsigned long val) {
+ return *this -= amount_t(val);
+ }
+ balance_t& operator-=(const long val) {
+ return *this -= amount_t(val);
+ }
balance_t& operator*=(const amount_t& amt);
-
balance_t& operator*=(const double val) {
return *this *= amount_t(val);
}
@@ -233,7 +251,6 @@ public:
}
balance_t& operator/=(const amount_t& amt);
-
balance_t& operator/=(const double val) {
return *this /= amount_t(val);
}
@@ -278,7 +295,7 @@ public:
* in_place_reduce()
* in_place_unreduce()
*/
- balance_t negate() const {
+ balance_t negated() const {
balance_t temp(*this);
temp.in_place_negate();
return temp;
@@ -288,7 +305,7 @@ public:
pair.second.in_place_negate();
}
balance_t operator-() const {
- return negate();
+ return negated();
}
balance_t abs() const {
@@ -388,6 +405,13 @@ public:
* it.
*/
operator bool() const {
+ return is_nonzero();
+ }
+
+ bool is_nonzero() const {
+ if (is_empty())
+ return false;
+
foreach (const amounts_map::value_type& pair, amounts)
if (pair.second.is_nonzero())
return true;
@@ -433,6 +457,7 @@ public:
else
throw_(balance_error,
_("Cannot convert a balance with multiple commodities to an amount"));
+ return amount_t();
}
/**