summaryrefslogtreecommitdiff
path: root/gnucash.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-03 09:45:44 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:28 -0400
commit96d6d62ad94082ca777c2c88b88e0346a5d00e65 (patch)
treeb50a26a9c4c0cc0ab90b1772cc75368739501fa5 /gnucash.cc
parent7d3e45958e805f8acaf399ef14d53757979240ab (diff)
downloadfork-ledger-96d6d62ad94082ca777c2c88b88e0346a5d00e65.tar.gz
fork-ledger-96d6d62ad94082ca777c2c88b88e0346a5d00e65.tar.bz2
fork-ledger-96d6d62ad94082ca777c2c88b88e0346a5d00e65.zip
Began support for improved commodity handling.
Diffstat (limited to 'gnucash.cc')
-rw-r--r--gnucash.cc33
1 files changed, 23 insertions, 10 deletions
diff --git a/gnucash.cc b/gnucash.cc
index 03ea4fc3..cf858ba3 100644
--- a/gnucash.cc
+++ b/gnucash.cc
@@ -84,7 +84,10 @@ static void startElement(void *userData, const char *name, const char **atts)
action = ACCOUNT_PARENT;
else if (std::strcmp(name, "gnc:commodity") == 0) {
assert(! curr_comm);
+#if 0
+ // jww (2006-03-02): !!!
curr_comm = new commodity_t("");
+#endif
}
else if (std::strcmp(name, "cmdty:id") == 0)
action = COMM_SYM;
@@ -133,7 +136,10 @@ static void endElement(void *userData, const char *name)
}
else if (std::strcmp(name, "gnc:commodity") == 0) {
assert(curr_comm);
+#if 0
+ // jww (2006-03-02): !!!
commodity_t::add_commodity(curr_comm);
+#endif
curr_comm = NULL;
}
else if (std::strcmp(name, "gnc:transaction") == 0) {
@@ -252,20 +258,25 @@ static void dataHandler(void *userData, const char *s, int len)
case COMM_SYM:
if (curr_comm) {
+#if 0
+ // jww (2006-03-02): !!!
curr_comm->set_symbol(std::string(s, len));
+#endif
}
else if (curr_account) {
std::string symbol(s, len);
- commodity_t * comm = commodity_t::find_commodity(symbol, true);
+ commodity_t * comm = commodity_t::find_or_create(symbol);
+ assert(comm);
if (symbol != "$" && symbol != "USD")
- comm->flags() |= COMMODITY_STYLE_SEPARATED;
+ comm->add_flags(COMMODITY_STYLE_SEPARATED);
account_comms.insert(account_comm_pair(curr_account, comm));
}
else if (curr_entry) {
std::string symbol(s, len);
- entry_comm = commodity_t::find_commodity(symbol, true);
+ entry_comm = commodity_t::find_or_create(symbol);
+ assert(entry_comm);
if (symbol != "$" && symbol != "USD")
- entry_comm->flags() |= COMMODITY_STYLE_SEPARATED;
+ entry_comm->add_flags(COMMODITY_STYLE_SEPARATED);
}
break;
@@ -274,7 +285,7 @@ static void dataHandler(void *userData, const char *s, int len)
break;
case COMM_PREC:
- curr_comm->precision() = len - 1;
+ curr_comm->set_precision(len - 1);
break;
case ENTRY_NUM:
@@ -308,7 +319,7 @@ static void dataHandler(void *userData, const char *s, int len)
curr_value.set_commodity(*entry_comm);
if (precision > entry_comm->precision())
- entry_comm->precision() = precision;
+ entry_comm->set_precision(precision);
break;
}
@@ -380,11 +391,13 @@ unsigned int gnucash_parser_t::parse(std::istream& in,
// GnuCash uses the USD commodity without defining it, which really
// means $.
- commodity_t * usd;
- usd = new commodity_t("$", 2, COMMODITY_STYLE_THOUSANDS);
- commodity_t::add_commodity(usd, "$");
- usd = new commodity_t("$", 2, COMMODITY_STYLE_THOUSANDS);
+ commodity_t * usd = commodity_t::find_or_create("$");
+ usd->set_precision(2);
+ usd->add_flags(COMMODITY_STYLE_THOUSANDS);
+#if 0
+ //jww (2006-03-02): !!! make an alias here
commodity_t::add_commodity(usd, "USD");
+#endif
offset = 2;
parser = current_parser = XML_ParserCreate(NULL);