From 2c80227339538154ad0869e746f52db805325589 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 25 Oct 2009 05:13:21 -0400 Subject: Added basic foundation for XML reporting --- src/value.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/value.cc') diff --git a/src/value.cc b/src/value.cc index e2c9dc8b..2029b9c5 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1746,4 +1746,58 @@ bool sort_value_is_less_than(const std::list& left_values, return false; } +void to_xml(std::ostream& out, const value_t& value) +{ + push_xml x(out, "value"); + + switch (value.type()) { + case value_t::VOID: + out << ""; + break; + case value_t::BOOLEAN: { + push_xml y(out, "boolean"); + out << (value.as_boolean() ? "true" : "false"); + break; + } + case value_t::INTEGER: { + push_xml y(out, "integer"); + out << value.as_long(); + break; + } + case value_t::DATETIME: + to_xml(out, value.as_datetime()); + break; + case value_t::DATE: + to_xml(out, value.as_date()); + break; + case value_t::STRING: { + push_xml y(out, "string"); + out << y.guard(value.as_string()); + break; + } + case value_t::MASK: + to_xml(out, value.as_mask()); + break; + + case value_t::SEQUENCE: { + push_xml y(out, "sequence"); + foreach (const value_t& member, value.as_sequence()) + to_xml(out, member); + break; + } + + case value_t::AMOUNT: + to_xml(out, value.as_amount()); + break; + case value_t::BALANCE: + to_xml(out, value.as_balance()); + break; + + case value_t::SCOPE: + default: + assert(false); + break; + } +} + } // namespace ledger -- cgit v1.2.3