From 8276b51f5692796bfdf75dd64f709e0de1c7caaf Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 31 Jul 2008 04:28:58 -0400 Subject: 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. --- value.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'value.cc') diff --git a/value.cc b/value.cc index 6c257c00..272fe8d6 100644 --- a/value.cc +++ b/value.cc @@ -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(binary::read_long(data))) { + case BOOLEAN: + set_boolean(binary::read_bool(data)); + break; + case INTEGER: + set_long(binary::read_long(data)); + break; + case DATETIME: + // jww (2008-04-22): I need to record and read a datetime_t directly + //set_datetime(read_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(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()) { -- cgit v1.2.3