diff options
author | John Wiegley <johnw@newartisans.com> | 2004-07-30 21:57:02 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-07-30 21:57:02 -0400 |
commit | 94e76ae87e883291d13320738fe165c7a2a2415b (patch) | |
tree | b90eff2ee3737ecdfea96dbee52ecd239fcb2578 /ledger.cc | |
parent | 5087a60deef7c618a07562511e9a1fbf2414776c (diff) | |
download | fork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.gz fork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.bz2 fork-ledger-94e76ae87e883291d13320738fe165c7a2a2415b.zip |
two major changes
Complete changed the way format strings are handled. They are now
compiled first, which is far more efficient than what was being done
before.
Also, there is now a global ledger::commodity_t::commodities map,
which saves me from having to pass the current journal around to a
zillion different functions, for the sole purpose of making sure that
all commodity symbols that are parsed refer to the same commodity
object.
Diffstat (limited to 'ledger.cc')
-rw-r--r-- | ledger.cc | 33 |
1 files changed, 6 insertions, 27 deletions
@@ -12,11 +12,6 @@ ledger_t::~ledger_t() { delete master; - for (commodities_map::iterator i = commodities.begin(); - i != commodities.end(); - i++) - delete (*i).second; - // Don't bother unhooking each entry's transactions from the // accounts they refer to, because all accounts are about to // be deleted. @@ -26,22 +21,6 @@ ledger_t::~ledger_t() delete *i; } -commodity_t * ledger_t::find_commodity(const std::string& symbol, - bool auto_create) -{ - commodities_map::const_iterator i = commodities.find(symbol); - if (i != commodities.end()) - return (*i).second; - - if (auto_create) { - commodity_t * commodity = new commodity_t(symbol); - add_commodity(commodity); - return commodity; - } - - return NULL; -} - bool ledger_t::add_entry(entry_t * entry) { entries.push_back(entry); @@ -73,7 +52,7 @@ bool ledger_t::remove_entry(entry_t * entry) return true; } -int parse_ledger_file(char * p, ledger_t * book) +int parse_ledger_file(char * p, ledger_t * journal) { char * sep = std::strrchr(p, '='); if (sep) *sep++ = '\0'; @@ -82,11 +61,11 @@ int parse_ledger_file(char * p, ledger_t * book) account_t * master; if (sep) - master = book->find_account(sep); + master = journal->find_account(sep); else - master = book->master; + master = journal->master; - book->sources.push_back(p); + journal->sources.push_back(p); unsigned long magic; std::istream::pos_type start = stream.tellg(); @@ -94,9 +73,9 @@ int parse_ledger_file(char * p, ledger_t * book) stream.seekg(start); if (magic == magic_number) - return read_binary_ledger(stream, "", book, master); + return read_binary_ledger(stream, "", journal, master); else - return parse_textual_ledger(stream, book, master); + return parse_textual_ledger(stream, journal, master); } } // namespace ledger |