diff options
author | John Wiegley <johnw@newartisans.com> | 2008-07-31 04:28:58 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-07-31 04:28:58 -0400 |
commit | 8276b51f5692796bfdf75dd64f709e0de1c7caaf (patch) | |
tree | 8f2a964080d2ee7e90400e158d3f89e9ffdbfa75 /value.cc | |
parent | 208c414ab9600eca4852034a923418948629ced0 (diff) | |
download | fork-ledger-8276b51f5692796bfdf75dd64f709e0de1c7caaf.tar.gz fork-ledger-8276b51f5692796bfdf75dd64f709e0de1c7caaf.tar.bz2 fork-ledger-8276b51f5692796bfdf75dd64f709e0de1c7caaf.zip |
A new binary_cache_t object has been creating to manage saving and restoring a
Ledger session from a cache file. It doesn't work at all yet, though at least
the major structures are in place now.
Diffstat (limited to 'value.cc')
-rw-r--r-- | value.cc | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -30,6 +30,7 @@ */ #include "value.h" +#include "binary.h" namespace ledger { @@ -1601,6 +1602,61 @@ void value_t::print(std::ostream& out, const bool relaxed) const } } +void value_t::read(const char *& data) +{ + switch (static_cast<value_t::type_t>(binary::read_long<int>(data))) { + case BOOLEAN: + set_boolean(binary::read_bool(data)); + break; + case INTEGER: + set_long(binary::read_long<unsigned long>(data)); + break; + case DATETIME: + // jww (2008-04-22): I need to record and read a datetime_t directly + //set_datetime(read_long<unsigned long>(data)); + break; + case AMOUNT: { + amount_t temp; + temp.read(data); + set_amount(temp); + break; + } + + //case BALANCE: + //case BALANCE_PAIR: + default: + assert(false); + break; + } +} + +void value_t::write(std::ostream& out) const +{ + binary::write_long(out, static_cast<int>(type())); + + switch (type()) { + case BOOLEAN: + binary::write_bool(out, as_boolean()); + break; + case INTEGER: + binary::write_long(out, as_long()); + break; + case DATETIME: +#if 0 + binary::write_number(out, as_datetime()); +#endif + break; + case AMOUNT: + as_amount().write(out); + break; + + //case BALANCE: + //case BALANCE_PAIR: + default: + throw new error("Cannot write a balance to the binary cache"); + } +} + bool value_t::valid() const { switch (type()) { |