From 0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 19 Apr 2007 20:31:46 +0000 Subject: Made the amount/balance/value interface a bit more rational; added back a useless version of the register command (just to prove the command sequence); and added smart XML semantics to the XPath implementation so that nodes can be coerced to values. --- xml.cc | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'xml.cc') diff --git a/xml.cc b/xml.cc index 33f98666..c56e9766 100644 --- a/xml.cc +++ b/xml.cc @@ -9,11 +9,18 @@ namespace ledger { namespace xml { -document_t::document_t(node_t *, const char ** _builtins, +document_t::document_t(node_t * _top, const char ** _builtins, const int _builtins_size) : builtins(_builtins), builtins_size(_builtins_size), top(new terminal_node_t(this)) {} +void document_t::set_top(node_t * _top) +{ + if (top) + delete top; + top = _top; +} + int document_t::register_name(const std::string& name) { int index = lookup_name_id(name); @@ -102,16 +109,9 @@ node_t::node_t(document_t * _document, parent_node_t * _parent, flags(_flags), info(NULL), attrs(NULL) { TRACE_CTOR("node_t(document_t *, node_t *)"); -#ifdef THREADSAFE document = _document; -#else - if (! document) - document = _document; -#if 0 - else - assert(document == _document); -#endif -#endif + if (! document->top) + document->set_top(this); if (parent) parent->add_child(this); } @@ -359,6 +359,18 @@ document_t * parser_t::parse(std::istream& in, const char ** builtins, return doc.release(); } +node_t * commodity_node_t::children() const +{ + // jww (2007-04-19): Need to report the commodity and its details + return NULL; +} + +node_t * amount_node_t::children() const +{ + // jww (2007-04-19): Need to report the quantity and commodity + return NULL; +} + node_t * transaction_node_t::children() const { if (! _children) { @@ -370,6 +382,20 @@ node_t * transaction_node_t::children() const return parent_node_t::children(); } +node_t * transaction_node_t::lookup_child(int _name_id) +{ + if (_name_id == payee_id) { + payee_virtual_node = new terminal_node_t(document); + payee_virtual_node->set_text(transaction->entry->payee); + return payee_virtual_node; + } +} + +value_t transaction_node_t::to_value() const +{ + return transaction->amount; +} + node_t * entry_node_t::children() const { if (! _children) { -- cgit v1.2.3