summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-26 20:50:54 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-26 20:50:54 -0400
commit71e7157a650c5296e792e5a88cce14d7bfcbaec4 (patch)
tree30d5801a3a896d5b26eac805c0523eac24b44d68
parent21707033108fccbd24e03c98677131b7dd74a5f7 (diff)
downloadfork-ledger-71e7157a650c5296e792e5a88cce14d7bfcbaec4.tar.gz
fork-ledger-71e7157a650c5296e792e5a88cce14d7bfcbaec4.tar.bz2
fork-ledger-71e7157a650c5296e792e5a88cce14d7bfcbaec4.zip
Added is_nonzero and a stream-based read() method to value_t.
-rw-r--r--src/value.cc28
-rw-r--r--src/value.h5
2 files changed, 33 insertions, 0 deletions
diff --git a/src/value.cc b/src/value.cc
index 1ebc3110..2d6d42d1 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1747,6 +1747,34 @@ void value_t::print(std::ostream& out, const bool relaxed) const
}
}
+void value_t::read(std::istream& in)
+{
+ switch (static_cast<value_t::type_t>(binary::read_long<int>(in))) {
+ case BOOLEAN:
+ set_boolean(binary::read_bool(in));
+ break;
+ case INTEGER:
+ set_long(binary::read_long<long>(in));
+ break;
+ case DATETIME:
+ set_datetime(parse_datetime(binary::read_string(in)));
+ break;
+ case DATE:
+ set_date(parse_date(binary::read_string(in)));
+ break;
+ case AMOUNT: {
+ amount_t temp;
+ temp.read(in);
+ set_amount(temp);
+ break;
+ }
+ default:
+ break;
+ }
+
+ throw_(value_error, "Cannot read " << label() << " from a stream");
+}
+
void value_t::read(const char *& data)
{
switch (static_cast<value_t::type_t>(binary::read_long<int>(data))) {
diff --git a/src/value.h b/src/value.h
index 5c55a117..3c6c1d41 100644
--- a/src/value.h
+++ b/src/value.h
@@ -429,6 +429,10 @@ public:
*/
operator bool() const;
+ bool is_nonzero() const {
+ return ! is_zero();
+ }
+
bool is_realzero() const;
bool is_zero() const;
bool is_null() const {
@@ -892,6 +896,7 @@ public:
* stream or a character pointer, and it may be serialized to an
* output stream. The methods used are:
*/
+ void read(std::istream& in);
void read(const char *& data);
void write(std::ostream& out) const;