summaryrefslogtreecommitdiff
path: root/xml.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-19 20:31:46 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:28 -0400
commit0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c (patch)
tree0a2c2aca7100d045f491b03f0a5bda92378d3ef9 /xml.h
parent176b3044e355398a0c31e0c42a3cd7b8a2e3f3e5 (diff)
downloadfork-ledger-0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c.tar.gz
fork-ledger-0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c.tar.bz2
fork-ledger-0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c.zip
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.
Diffstat (limited to 'xml.h')
-rw-r--r--xml.h85
1 files changed, 83 insertions, 2 deletions
diff --git a/xml.h b/xml.h
index b3481d5a..09b3180e 100644
--- a/xml.h
+++ b/xml.h
@@ -49,6 +49,8 @@ class document_t
document_t(node_t * _top = NULL, const char ** _builtins = NULL,
const int _builtins_size = 0);
+ void set_top(node_t * _top);
+
int register_name(const std::string& name);
int lookup_name_id(const std::string& name) const;
const char * lookup_name(int id) const;
@@ -58,6 +60,14 @@ class document_t
#define XML_NODE_IS_PARENT 0x1
+class conversion_error : public error {
+ public:
+ conversion_error(const std::string& _reason,
+ error_context * _ctxt = NULL) throw()
+ : error(_reason, _ctxt) {}
+ virtual ~conversion_error() throw() {}
+};
+
class parent_node_t;
class node_t
@@ -124,6 +134,22 @@ public:
return NULL;
}
+ node_t * lookup_child(const char * _name) {
+ int id = document->lookup_name_id(_name);
+ return lookup_child(id);
+ }
+ node_t * lookup_child(const std::string& _name) {
+ int id = document->lookup_name_id(_name);
+ return lookup_child(id);
+ }
+ virtual node_t * lookup_child(int _name_id) {
+ return NULL;
+ }
+
+ virtual value_t to_value() const {
+ throw new conversion_error("Cannot convert node to a value");
+ }
+
virtual void write(std::ostream& out, int depth = 0) const = 0;
private:
@@ -187,6 +213,10 @@ public:
data = _data;
}
+ virtual value_t to_value() const {
+ return text();
+ }
+
void write(std::ostream& out, int depth = 0) const;
private:
@@ -228,23 +258,74 @@ class parse_error : public error {
#endif
+class commodity_node_t : public parent_node_t
+{
+public:
+ commodity_t * commodity;
+
+ commodity_node_t(document_t * _document,
+ commodity_t * _commodity,
+ parent_node_t * _parent = NULL)
+ : parent_node_t(_document, _parent), commodity(_commodity) {
+ TRACE_CTOR("commodity_node_t(document_t *, commodity_t *, parent_node_t *)");
+ set_name("commodity");
+ }
+ virtual ~commodity_node_t() {
+ TRACE_DTOR("commodity_node_t");
+ }
+
+ virtual node_t * children() const;
+};
+
+class amount_node_t : public parent_node_t
+{
+public:
+ amount_t * amount;
+
+ amount_node_t(document_t * _document,
+ amount_t * _amount,
+ parent_node_t * _parent = NULL)
+ : parent_node_t(_document, _parent), amount(_amount) {
+ TRACE_CTOR("amount_node_t(document_t *, amount_t *, parent_node_t *)");
+ set_name("amount");
+ }
+ virtual ~amount_node_t() {
+ TRACE_DTOR("amount_node_t");
+ }
+
+ virtual node_t * children() const;
+
+ virtual value_t to_value() const {
+ return *amount;
+ }
+};
+
class transaction_node_t : public parent_node_t
{
- transaction_t * transaction;
+ int payee_id;
+ terminal_node_t * payee_virtual_node;
public:
+ transaction_t * transaction;
+
transaction_node_t(document_t * _document,
transaction_t * _transaction,
parent_node_t * _parent = NULL)
- : parent_node_t(_document, _parent), transaction(_transaction) {
+ : parent_node_t(_document, _parent), transaction(_transaction),
+ payee_virtual_node(NULL) {
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");
+ if (payee_virtual_node)
+ delete payee_virtual_node;
}
virtual node_t * children() const;
+ virtual node_t * lookup_child(int _name_id);
+ virtual value_t to_value() const;
};
class entry_node_t : public parent_node_t