summaryrefslogtreecommitdiff
path: root/balance.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-02-28 10:24:21 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 05:48:43 -0400
commit6d529efa63f5f2020b126c8476fe0ea03516869d (patch)
treec8699424992378dbd5e787f5ffc9ea5942edaa17 /balance.h
parent72e8a366a49451bd46a10d0b04c16b9ff5aba354 (diff)
downloadfork-ledger-6d529efa63f5f2020b126c8476fe0ea03516869d.tar.gz
fork-ledger-6d529efa63f5f2020b126c8476fe0ea03516869d.tar.bz2
fork-ledger-6d529efa63f5f2020b126c8476fe0ea03516869d.zip
*** no comment ***
Diffstat (limited to 'balance.h')
-rw-r--r--balance.h29
1 files changed, 6 insertions, 23 deletions
diff --git a/balance.h b/balance.h
index 8a6e4a35..4c2c8b00 100644
--- a/balance.h
+++ b/balance.h
@@ -143,11 +143,7 @@ class balance_t
}
// multiplication and divide
- balance_t& operator*=(const balance_t& bal) {
- if (amounts.size() == 1 && bal.amounts.size() == 1)
- return *this *= (*bal.amounts.begin()).second;
- throw amount_error("It makes no sense to multiply two balances");
- }
+ balance_t& operator*=(const balance_t& bal);
balance_t& operator*=(const amount_t& amt) {
// Multiplying by the null commodity causes all amounts to be
// increased by the same factor.
@@ -172,11 +168,7 @@ class balance_t
return *this *= amount_t(val);
}
- balance_t& operator/=(const balance_t& bal) {
- if (amounts.size() == 1 && bal.amounts.size() == 1)
- return *this /= (*bal.amounts.begin()).second;
- throw amount_error("It makes no sense to divide two balances");
- }
+ balance_t& operator/=(const balance_t& bal);
balance_t& operator/=(const amount_t& amt) {
// Dividing by the null commodity causes all amounts to be
// increased by the same factor.
@@ -406,15 +398,7 @@ class balance_t
}
// conversion operators
- operator amount_t() const {
- if (amounts.size() == 1)
- return (*amounts.begin()).second;
- else if (amounts.size() == 0)
- return amount_t();
- else
- throw amount_error("Cannot convert a balance with "
- "multiple commodities to an amount");
- }
+ operator amount_t() const;
operator bool() const {
for (amounts_map::const_iterator i = amounts.begin();
i != amounts.end();
@@ -427,9 +411,8 @@ class balance_t
amount_t amount(const commodity_t& commodity) const;
balance_t value(const std::time_t moment) const;
- void write(std::ostream& out,
- const int first_width,
- const int latter_width = -1) const;
+ void write(std::ostream& out, const int first_width,
+ const int latter_width = -1) const;
void abs() {
for (amounts_map::iterator i = amounts.begin();
@@ -462,7 +445,7 @@ inline std::ostream& operator<<(std::ostream& out, const balance_t& bal) {
class balance_pair_t
{
public:
- balance_t quantity;
+ balance_t quantity;
balance_t * cost;
// constructors