diff options
author | John Wiegley <johnw@newartisans.com> | 2007-04-16 04:27:26 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:35:35 -0400 |
commit | e7f9486f6e524947a29b8e7d20bc834a240a3b23 (patch) | |
tree | 9720b3b7750bffc3cab66a707cac8719371ad857 /amount.h | |
parent | 8a63ad1c8d0f03b9be57331f911c0ccd998ece68 (diff) | |
download | fork-ledger-e7f9486f6e524947a29b8e7d20bc834a240a3b23.tar.gz fork-ledger-e7f9486f6e524947a29b8e7d20bc834a240a3b23.tar.bz2 fork-ledger-e7f9486f6e524947a29b8e7d20bc834a240a3b23.zip |
Finished uncommoditized amount unit tests.
Diffstat (limited to 'amount.h')
-rw-r--r-- | amount.h | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -128,9 +128,6 @@ class amount_t return ! quantity && ! has_commodity(); } - std::string to_string() const; - std::string quantity_string() const {} - // assignment operator amount_t& operator=(const amount_t& amt); amount_t& operator=(const std::string& val); @@ -226,12 +223,21 @@ class amount_t return negated(); } - // test for non-zero (use ! for zero) - operator bool() const; + // test for zero and non-zero + int sign() const; + bool zero() const; + bool realzero() const { + return sign() == 0; + } + operator bool() const { + return ! zero(); + } + operator long() const; operator double() const; - bool realzero() const; + std::string to_string() const; + std::string quantity_string() const; // comparisons between amounts int compare(const amount_t& amt) const; @@ -259,8 +265,6 @@ class amount_t parse(in); } - int sign() const; - // POD comparisons #define AMOUNT_CMP_INT(OP) \ template <typename T> \ @@ -322,7 +326,7 @@ class amount_t #define AMOUNT_PARSE_NO_MIGRATE 0x01 #define AMOUNT_PARSE_NO_REDUCE 0x02 - void print(std::ostream& out) const; + void print(std::ostream& out, bool omit_commodity = false) const; void parse(std::istream& in, unsigned char flags = 0); void parse(const std::string& str, unsigned char flags = 0) { std::istringstream stream(str); @@ -346,6 +350,12 @@ inline std::string amount_t::to_string() const { return bufstream.str(); } +inline std::string amount_t::quantity_string() const { + std::ostringstream bufstream; + print(bufstream, true); + return bufstream.str(); +} + inline amount_t abs(const amount_t& amt) { return amt < 0 ? amt.negated() : amt; } |