diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-07 10:27:21 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:39 -0400 |
commit | d8498372037a4d0c272547ae48046b2182bcd4b1 (patch) | |
tree | ea3f228c5b6b20d71456e47a418e383669925d5f /src/xml.h | |
parent | a71d48881e538630aa1d147d58365da84e6db91f (diff) | |
download | fork-ledger-d8498372037a4d0c272547ae48046b2182bcd4b1.tar.gz fork-ledger-d8498372037a4d0c272547ae48046b2182bcd4b1.tar.bz2 fork-ledger-d8498372037a4d0c272547ae48046b2182bcd4b1.zip |
Major restructuring of the value_t class.
Diffstat (limited to 'src/xml.h')
-rw-r--r-- | src/xml.h | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -52,27 +52,25 @@ DECLARE_EXCEPTION(conversion_error); class parent_node_t; class document_t; -class node_t +class node_t : public supports_flags<> { public: - unsigned int name_id; + unsigned int name_id; #ifdef THREADSAFE - document_t * document; + document_t * document; #else static document_t * document; #endif - parent_node_t * parent; - node_t * next; - node_t * prev; - unsigned int flags; + parent_node_t * parent; + node_t * next; + node_t * prev; - typedef std::map<string, string> attrs_map; - typedef std::pair<string, string> attrs_pair; + typedef std::map<string, string> attrs_map; attrs_map * attrs; node_t(document_t * _document, parent_node_t * _parent = NULL, - unsigned int _flags = 0); + flags_t _flags = 0); virtual ~node_t() { TRACE_DTOR(node_t); @@ -80,10 +78,21 @@ public: if (attrs) checked_delete(attrs); } + parent_node_t * as_parent_node() { + if (! has_flags(XML_NODE_IS_PARENT)) + throw_(std::logic_error, "Request to cast leaf node to a parent node"); + return polymorphic_downcast<parent_node_t *>(this); + } + const parent_node_t * as_parent_node() const { + if (! has_flags(XML_NODE_IS_PARENT)) + throw_(std::logic_error, "Request to cast leaf node to a parent node"); + return polymorphic_downcast<const parent_node_t *>(this); + } + void extract(); // extract this node from its parent's child list virtual const char * text() const { - assert(0); + assert(false); return NULL; } @@ -98,7 +107,7 @@ public: if (! attrs) attrs = new attrs_map; std::pair<attrs_map::iterator, bool> result = - attrs->insert(attrs_pair(n, v)); + attrs->insert(attrs_map::value_type(n, v)); assert(result.second); } const char * get_attr(const char * n) { @@ -223,8 +232,7 @@ private: names_array names; - typedef std::map<string, int> names_map; - typedef std::pair<string, int> names_pair; + typedef std::map<string, int> names_map; names_map names_index; |