diff options
author | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:35:00 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:35:00 -0400 |
commit | 42f43b7686038e4cbca16d8d2118b139544e6de3 (patch) | |
tree | 52c5473401c57282242d66b8dd75f4c07bf41d07 /journal.h | |
parent | c7b4370ff9c8ab5c96f15b1e712e6db6bdab6324 (diff) | |
download | fork-ledger-42f43b7686038e4cbca16d8d2118b139544e6de3.tar.gz fork-ledger-42f43b7686038e4cbca16d8d2118b139544e6de3.tar.bz2 fork-ledger-42f43b7686038e4cbca16d8d2118b139544e6de3.zip |
Check in all changes made so far toward 3.0.
Diffstat (limited to 'journal.h')
-rw-r--r-- | journal.h | 98 |
1 files changed, 54 insertions, 44 deletions
@@ -1,17 +1,7 @@ #ifndef _JOURNAL_H #define _JOURNAL_H -#include <map> -#include <list> -#include <string> -#include <iostream> - -#include "amount.h" -#include "datetime.h" -#include "value.h" -#include "valexpr.h" -#include "error.h" -#include "debug.h" +#include "xpath.h" #include "util.h" namespace ledger { @@ -37,7 +27,7 @@ class transaction_t datetime_t _date_eff; account_t * account; amount_t amount; - value_expr amount_expr; + std::string amount_expr; amount_t * cost; std::string cost_expr; state_t state; @@ -47,15 +37,16 @@ class transaction_t unsigned long beg_line; istream_pos_type end_pos; unsigned long end_line; - mutable void * data; - static bool use_effective_date; + mutable void * data; + + static bool use_effective_date; transaction_t(account_t * _account = NULL) : entry(NULL), account(_account), cost(NULL), state(UNCLEARED), flags(TRANSACTION_NORMAL), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t"); + TRACE_CTOR("transaction_t(account_t *)"); } transaction_t(account_t * _account, const amount_t& _amount, @@ -65,14 +56,14 @@ class transaction_t state(UNCLEARED), flags(_flags), note(_note), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t"); + TRACE_CTOR("transaction_t(account_t *, const amount_t&, unsigned int, const std::string&)"); } transaction_t(const transaction_t& xact) : entry(xact.entry), account(xact.account), amount(xact.amount), cost(xact.cost ? new amount_t(*xact.cost) : NULL), state(xact.state), flags(xact.flags), note(xact.note), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_t"); + TRACE_CTOR("transaction_t(copy)"); } ~transaction_t(); @@ -120,21 +111,20 @@ class entry_base_t transactions_list transactions; entry_base_t() : journal(NULL), - beg_pos(0), beg_line(0), end_pos(0), end_line(0) - { - DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t"); + beg_pos(0), beg_line(0), end_pos(0), end_line(0) { + TRACE_CTOR("entry_base_t()"); } entry_base_t(const entry_base_t& e) : journal(NULL), beg_pos(0), beg_line(0), end_pos(0), end_line(0) { - DEBUG_PRINT("ledger.memory.ctors", "ctor entry_base_t"); + TRACE_CTOR("entry_base_t(copy)"); for (transactions_list::const_iterator i = e.transactions.begin(); i != e.transactions.end(); i++) transactions.push_back(new transaction_t(**i)); } virtual ~entry_base_t() { - DEBUG_PRINT("ledger.memory.dtors", "dtor entry_base_t"); + TRACE_DTOR("entry_base_t"); for (transactions_list::iterator i = transactions.begin(); i != transactions.end(); i++) @@ -166,13 +156,15 @@ class entry_t : public entry_base_t std::string code; std::string payee; - entry_t() { - DEBUG_PRINT("ledger.memory.ctors", "ctor entry_t"); + mutable void * data; + + entry_t() : data(NULL) { + TRACE_CTOR("entry_t()"); } entry_t(const entry_t& e); virtual ~entry_t() { - DEBUG_PRINT("ledger.memory.dtors", "dtor entry_t"); + TRACE_DTOR("entry_t"); } datetime_t actual_date() const { @@ -202,6 +194,9 @@ struct entry_finalizer_t { virtual bool operator()(entry_t& entry, bool post) = 0; }; +void print_entry(std::ostream& out, const entry_base_t& entry, + const std::string& prefix = ""); + class entry_context : public error_context { public: const entry_base_t& entry; @@ -222,21 +217,22 @@ class balance_error : public error { }; -template <typename T> -class item_predicate; - class auto_entry_t : public entry_base_t { public: - item_predicate<transaction_t> * predicate; - std::string predicate_string; + xml::xpath_t predicate; - auto_entry_t() : predicate(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor auto_entry_t"); + auto_entry_t() { + TRACE_CTOR("auto_entry_t()"); + } + auto_entry_t(const std::string& _predicate) + : predicate(_predicate) { + TRACE_CTOR("auto_entry_t(const std::string&)"); } - auto_entry_t(const std::string& _predicate); - virtual ~auto_entry_t(); + virtual ~auto_entry_t() { + TRACE_DTOR("auto_entry_t"); + } virtual void extend_entry(entry_base_t& entry, bool post); virtual bool valid() const { @@ -245,6 +241,7 @@ public: }; class journal_t; + struct auto_entry_finalizer_t : public entry_finalizer_t { journal_t * journal; auto_entry_finalizer_t(journal_t * _journal) : journal(_journal) {} @@ -259,19 +256,19 @@ class period_entry_t : public entry_base_t std::string period_string; period_entry_t() { - DEBUG_PRINT("ledger.memory.ctors", "ctor period_entry_t"); + TRACE_CTOR("period_entry_t()"); } period_entry_t(const std::string& _period) : period(_period), period_string(_period) { - DEBUG_PRINT("ledger.memory.ctors", "ctor period_entry_t"); + TRACE_CTOR("period_entry_t(const std::string&)"); } period_entry_t(const period_entry_t& e) : entry_base_t(e), period(e.period), period_string(e.period_string) { - DEBUG_PRINT("ledger.memory.ctors", "ctor period_entry_t"); + TRACE_CTOR("period_entry_t(copy)"); } virtual ~period_entry_t() { - DEBUG_PRINT("ledger.memory.dtors", "dtor period_entry_t"); + TRACE_DTOR("period_entry_t"); } virtual bool valid() const { @@ -295,8 +292,8 @@ class account_t unsigned short depth; accounts_map accounts; - mutable void * data; - mutable ident_t ident; + mutable void * data; + mutable ident_t ident; mutable std::string _fullname; account_t(account_t * _parent = NULL, @@ -304,7 +301,7 @@ class account_t const std::string& _note = "") : parent(_parent), name(_name), note(_note), depth(parent ? parent->depth + 1 : 0), data(NULL), ident(0) { - DEBUG_PRINT("ledger.memory.ctors", "ctor account_t " << this); + TRACE_CTOR("account_t(account_t *, const std::string&, const std::string&)"); } ~account_t(); @@ -380,9 +377,12 @@ typedef std::list<auto_entry_t *> auto_entries_list; typedef std::list<period_entry_t *> period_entries_list; typedef std::list<std::string> strings_list; +class session_t; + class journal_t { public: + session_t * session; account_t * master; account_t * basket; entries_list entries; @@ -391,17 +391,27 @@ class journal_t char * item_pool; char * item_pool_end; + // This is used for dynamically representing the journal data as an + // XML tree, to facilitate transformations without modifying any of + // the underlying structures (the transformers modify the XML tree + // -- perhaps even adding, changing or deleting nodes -- but they do + // not affect the basic data parsed from the journal file). + xml::document_t * document; + auto_entries_list auto_entries; period_entries_list period_entries; + mutable void * data; mutable accounts_map accounts_cache; std::list<entry_finalizer_t *> entry_finalize_hooks; - journal_t() : basket(NULL) { - DEBUG_PRINT("ledger.memory.ctors", "ctor journal_t"); + journal_t(session_t * _session) + : session(_session), basket(NULL), + item_pool(NULL), item_pool_end(NULL), + document(NULL), data(NULL) { + TRACE_CTOR("journal_t()"); master = new account_t(NULL, ""); master->journal = this; - item_pool = item_pool_end = NULL; } ~journal_t(); |