diff options
Diffstat (limited to 'ledger.h')
-rw-r--r-- | ledger.h | 71 |
1 files changed, 34 insertions, 37 deletions
@@ -1,5 +1,5 @@ #ifndef _LEDGER_H -#define _LEDGER_H "$Revision: 1.18 $" +#define _LEDGER_H "$Revision: 1.19 $" ////////////////////////////////////////////////////////////////////// // @@ -44,9 +44,9 @@ struct commodity bool thou = true, bool euro = false, int prec = 2); }; -typedef std::map<const std::string, commodity *> commodities_t; -typedef commodities_t::iterator commodities_iterator; -typedef std::pair<const std::string, commodity *> commodities_entry; +typedef std::map<const std::string, commodity *> commodities_map; +typedef commodities_map::iterator commodities_map_iterator; +typedef std::pair<const std::string, commodity *> commodities_map_pair; class amount @@ -90,11 +90,11 @@ struct mask mask(const std::string& pattern); }; -typedef std::list<mask> regexps_t; +typedef std::list<mask> regexps_map; -void record_regexp(const std::string& pattern, regexps_t& regexps); -void read_regexps(const std::string& path, regexps_t& regexps); -bool matches(const regexps_t& regexps, const std::string& str, +void record_regexp(const std::string& pattern, regexps_map& regexps); +void read_regexps(const std::string& path, regexps_map& regexps); +bool matches(const regexps_map& regexps, const std::string& str, bool * by_exclusion = NULL); @@ -114,12 +114,10 @@ struct transaction : acct(_acct), cost(_cost), is_virtual(false), must_balance(true), specified(false) {} -#ifdef DO_CLEANUP ~transaction() { if (cost) delete cost; } -#endif const std::string acct_as_str() const; @@ -140,7 +138,6 @@ struct entry entry() : cleared(false) {} -#ifdef DO_CLEANUP // If we're running as a command-line tool, it's cheaper to just // throw away the heap on exit, than spend time freeing things up // like a good citizen. @@ -152,7 +149,6 @@ struct entry delete *i; } } -#endif bool matches(const std::list<mask>& regexps) const; bool validate(bool show_unaccounted = false) const; @@ -166,22 +162,21 @@ struct cmp_entry_date { } }; -typedef std::vector<entry *> entries_t; -typedef entries_t::iterator entries_iterator; +typedef std::vector<entry *> entries_list; +typedef entries_list::iterator entries_list_iterator; +typedef entries_list::const_iterator entries_list_const_iterator; struct totals { - typedef std::map<const std::string, amount *> map; - typedef map::iterator iterator; - typedef map::const_iterator const_iterator; + typedef std::map<const std::string, amount *> map; + typedef map::iterator iterator; + typedef map::const_iterator const_iterator; typedef std::pair<const std::string, amount *> pair; map amounts; -#ifdef DO_CLEANUP ~totals(); -#endif void credit(const amount * val) { std::pair<iterator, bool> result = @@ -202,9 +197,9 @@ struct totals }; -typedef std::map<const std::string, account *> accounts_t; -typedef accounts_t::iterator accounts_iterator; -typedef std::pair<const std::string, account *> accounts_entry; +typedef std::map<const std::string, account *> accounts_map; +typedef accounts_map::iterator accounts_map_iterator; +typedef std::pair<const std::string, account *> accounts_map_pair; struct account { @@ -216,7 +211,7 @@ struct account #endif totals balance; // optional, parse-time computed balance int checked; // 'balance' uses this for speed's sake - accounts_t children; + accounts_map children; mutable std::string full_name; @@ -238,11 +233,12 @@ struct account struct state { - commodities_t commodities; - accounts_t accounts; - accounts_t accounts_cache; // maps full names to accounts - entries_t entries; + commodities_map commodities; + accounts_map accounts; + accounts_map accounts_cache; // maps full names to accounts + entries_list entries; totals prices; + int current_year; typedef std::map<std::list<mask> *, std::list<transaction *> *> virtual_map; @@ -252,30 +248,31 @@ struct state typedef virtual_map::const_iterator virtual_map_iterator; - std::string mapping_file; + bool compute_balances; virtual_map virtual_mapping; - bool compute_virtual; - - state() : mapping_file(".mapping"), compute_virtual(true) {} -#ifdef DO_CLEANUP ~state(); -#endif void record_price(const std::string& setting); + template<typename Compare> + void sort(Compare comp) { + std::sort(entries.begin(), entries.end(), comp); + } + void print(std::ostream& out, regexps_map& regexps, bool shortcut) const; + account * find_account(const std::string& name, bool create = true); }; -extern state main_ledger; -extern bool use_warnings; +extern state * main_ledger; +extern bool use_warnings; inline commodity::commodity(const std::string& sym, bool pre, bool sep, bool thou, bool euro, int prec) : symbol(sym), prefix(pre), separate(sep), thousands(thou), european(euro), precision(prec) { - std::pair<commodities_iterator, bool> result = - main_ledger.commodities.insert(commodities_entry(sym, this)); + std::pair<commodities_map_iterator, bool> result = + main_ledger->commodities.insert(commodities_map_pair(sym, this)); assert(result.second); } |