diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-09 10:02:56 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:42 -0400 |
commit | 8e20c378d6ee6eb36f8c6866f8c9ec52f8600c58 (patch) | |
tree | f610a289a997487d89f6b24dc48f5e1ffce35628 /src/amount.h | |
parent | 623e6e024cf43fc855c889314b8da8802c2f0449 (diff) | |
download | fork-ledger-8e20c378d6ee6eb36f8c6866f8c9ec52f8600c58.tar.gz fork-ledger-8e20c378d6ee6eb36f8c6866f8c9ec52f8600c58.tar.bz2 fork-ledger-8e20c378d6ee6eb36f8c6866f8c9ec52f8600c58.zip |
The unit tests for amount.cc now cover every part of the code except
for two: those concerning annotated commodities (which will be covered
in the t_commodity.cc tests) and reading of optimized amounts in the
binary journal reader.
Diffstat (limited to 'src/amount.h')
-rw-r--r-- | src/amount.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/amount.h b/src/amount.h index 2f360f72..10659f1f 100644 --- a/src/amount.h +++ b/src/amount.h @@ -141,7 +141,6 @@ public: static bool stream_fullstrings; protected: - void _init(); void _copy(const amount_t& amt); void _dup(); void _resize(precision_t prec); @@ -326,7 +325,7 @@ public: precision_t precision() const; amount_t negate() const { - amount_t temp = *this; + amount_t temp(*this); temp.in_place_negate(); return temp; } @@ -575,6 +574,7 @@ public: void parse(const string& str, flags_t flags = 0) { std::istringstream stream(str); parse(stream, flags); + assert(stream.eof()); } static void parse_conversion(const string& larger_str, @@ -616,12 +616,17 @@ public: * an input stream into a buffer. It advances the pointer passed in * to the end of the deserialized amount. * - * write(ostream) writes an amount to an output stream in a compact - * binary format. + * write(ostream, [bool]) writes an amount to an output stream in a + * compact binary format. If the second parameter is true, + * quantities with multiple reference counts will be written in an + * optimized fashion. NOTE: This form of usage is valid only for + * the binary journal writer, it should not be used otherwise, as it + * has strict requirements for reading that only the binary reader + * knows about. */ void read(std::istream& in); - void read(char *& data); - void write(std::ostream& out) const; + void read(const char *& data); + void write(std::ostream& out, bool optimize = false) const; /** * Debugging methods. There are two methods defined to help with @@ -691,6 +696,8 @@ inline bool amount_t::operator==(const amount_t& amt) const { } inline amount_t amount_t::round() const { + if (! quantity) + throw_(amount_error, "Cannot round an uninitialized amount"); if (! has_commodity()) return *this; return round(commodity().precision()); |