diff options
-rw-r--r-- | value.h | 2 | ||||
-rw-r--r-- | xml.cc | 62 | ||||
-rw-r--r-- | xml.h | 28 |
3 files changed, 56 insertions, 36 deletions
@@ -5,8 +5,6 @@ #include "balance.h" #include "error.h" -#include "linked_list.h" // code by Donovan Rebbechi - #include <vector> #include <exception> @@ -158,13 +158,13 @@ int node_t::set_name(const char * _name) return name_id; } -node_t * node_t::lookup_child(const char * _name) +node_t * node_t::lookup_child(const char * _name) const { int id = document->lookup_name_id(_name); return lookup_child(id); } -node_t * node_t::lookup_child(const string& _name) +node_t * node_t::lookup_child(const string& _name) const { int id = document->lookup_name_id(_name); return lookup_child(id); @@ -405,22 +405,20 @@ node_t * amount_node_t::children() const node_t * transaction_node_t::children() const { - if (! _children) { - terminal_node_t * account_node = - new terminal_node_t(document, const_cast<transaction_node_t *>(this)); - account_node->set_name("account"); - account_node->set_text(transaction->account->fullname()); - } return parent_node_t::children(); } -node_t * transaction_node_t::lookup_child(int _name_id) +node_t * transaction_node_t::lookup_child(int _name_id) const { - if (_name_id == payee_id) { + if (_name_id == entry_node_t::payee_id) { payee_virtual_node = new terminal_node_t(document); payee_virtual_node->set_text(transaction->entry->payee); return payee_virtual_node; } + else if (_name_id == journal_node_t::account_id) { + return new account_node_t(document, transaction->account, + const_cast<transaction_node_t *>(this)); + } return NULL; } @@ -429,31 +427,41 @@ value_t transaction_node_t::to_value() const return transaction->amount; } +int entry_node_t::code_id = -1; +int entry_node_t::payee_id = -1; + node_t * entry_node_t::children() const { - if (! _children) { - if (! entry->code.empty()) { - terminal_node_t * code_node = - new terminal_node_t(document, const_cast<entry_node_t *>(this)); - code_node->set_name("code"); - code_node->set_text(entry->code); - } - - if (! entry->payee.empty()) { - terminal_node_t * payee_node = - new terminal_node_t(document, const_cast<entry_node_t *>(this)); - payee_node->set_name("payee"); - payee_node->set_text(entry->payee); - } - + if (! _children) for (transactions_list::iterator i = entry->transactions.begin(); i != entry->transactions.end(); i++) new transaction_node_t(document, *i, const_cast<entry_node_t *>(this)); - } + return parent_node_t::children(); } +node_t * entry_node_t::lookup_child(int _name_id) const +{ + if (_name_id == entry_node_t::code_id) { + // jww (2007-04-20): I have to save this and then delete it later + terminal_node_t * code_node = + new terminal_node_t(document, const_cast<entry_node_t *>(this)); + code_node->set_name("code"); + code_node->set_text(entry->code); + return code_node; + } + else if (_name_id == entry_node_t::payee_id) { + // jww (2007-04-20): I have to save this and then delete it later + terminal_node_t * payee_node = + new terminal_node_t(document, const_cast<entry_node_t *>(this)); + payee_node->set_name("payee"); + payee_node->set_text(entry->payee); + return payee_node; + } + return NULL; +} + node_t * account_node_t::children() const { if (! _children) { @@ -479,6 +487,8 @@ node_t * account_node_t::children() const return parent_node_t::children(); } +int journal_node_t::account_id = -1; + node_t * journal_node_t::children() const { if (! _children) { @@ -93,9 +93,9 @@ public: return NULL; } - node_t * lookup_child(const char * _name); - node_t * lookup_child(const string& _name); - virtual node_t * lookup_child(int /* _name_id */) { + node_t * lookup_child(const char * _name) const; + node_t * lookup_child(const string& _name) const; + virtual node_t * lookup_child(int /* _name_id */) const { return NULL; } @@ -296,8 +296,7 @@ public: class transaction_node_t : public parent_node_t { - int payee_id; - terminal_node_t * payee_virtual_node; + mutable terminal_node_t * payee_virtual_node; public: transaction_t * transaction; @@ -309,7 +308,6 @@ public: transaction(_transaction) { TRACE_CTOR(transaction_node_t, "document_t *, transaction_t *, parent_node_t *"); set_name("transaction"); - payee_id = document->register_name("payee"); } virtual ~transaction_node_t() { TRACE_DTOR(transaction_node_t); @@ -318,13 +316,15 @@ public: } virtual node_t * children() const; - virtual node_t * lookup_child(int _name_id); + virtual node_t * lookup_child(int _name_id) const; virtual value_t to_value() const; }; class entry_node_t : public parent_node_t { - entry_t * entry; + static int code_id; + static int payee_id; + entry_t * entry; public: entry_node_t(document_t * _document, entry_t * _entry, @@ -332,12 +332,19 @@ public: : parent_node_t(_document, _parent), entry(_entry) { TRACE_CTOR(entry_node_t, "document_t *, entry_t *, parent_node_t *"); set_name("entry"); + if (code_id == -1) + payee_id = document->register_name("code"); + if (payee_id == -1) + payee_id = document->register_name("payee"); } virtual ~entry_node_t() { TRACE_DTOR(entry_node_t); } virtual node_t * children() const; + virtual node_t * lookup_child(int _name_id) const; + + friend class transaction_node_t; }; class account_node_t : public parent_node_t @@ -360,6 +367,7 @@ public: class journal_node_t : public parent_node_t { + static int account_id; journal_t * journal; public: @@ -368,12 +376,16 @@ public: : parent_node_t(_document, _parent), journal(_journal) { TRACE_CTOR(journal_node_t, "document_t *, journal_t *, parent_node_t *"); set_name("journal"); + if (account_id == -1) + account_id = document->register_name("account"); } virtual ~journal_node_t() { TRACE_DTOR(journal_node_t); } virtual node_t * children() const; + + friend class transaction_node_t; }; template <typename T> |