summaryrefslogtreecommitdiff
path: root/ledger.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-07-30 21:57:02 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-07-30 21:57:02 -0400
commit94e76ae87e883291d13320738fe165c7a2a2415b (patch)
treeb90eff2ee3737ecdfea96dbee52ecd239fcb2578 /ledger.h
parent5087a60deef7c618a07562511e9a1fbf2414776c (diff)
downloadledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.gz
ledger-94e76ae87e883291d13320738fe165c7a2a2415b.tar.bz2
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.h')
-rw-r--r--ledger.h57
1 files changed, 33 insertions, 24 deletions
diff --git a/ledger.h b/ledger.h
index 5aa47c9f..840d879d 100644
--- a/ledger.h
+++ b/ledger.h
@@ -50,8 +50,6 @@ class amount_t
base_type quantity; // amount, to MAX_PRECISION
commodity_t * commodity;
- static commodity_t * null_commodity;
-
bool valid() const {
if (quantity)
return commodity != NULL;
@@ -185,10 +183,10 @@ class amount_t
operator std::string() const;
- void parse(std::istream& in, ledger_t * ledger = NULL);
- void parse(const std::string& str, ledger_t * ledger = NULL) {
+ void parse(std::istream& in);
+ void parse(const std::string& str) {
std::istringstream stream(str);
- parse(stream, ledger);
+ parse(stream);
}
void write_quantity(std::ostream& out) const;
@@ -223,6 +221,9 @@ std::ostream& operator<<(std::ostream& out, const amount_t& amt);
typedef std::map<const std::time_t, amount_t> history_map;
typedef std::pair<const std::time_t, amount_t> history_pair;
+typedef std::map<const std::string, commodity_t *> commodities_map;
+typedef std::pair<const std::string, commodity_t *> commodities_pair;
+
class commodity_t
{
public:
@@ -235,11 +236,34 @@ class commodity_t
amount_t conversion;
unsigned long ident;
+ // If set, this global function pointer is called to determine
+ // whether prices have been updated in the meanwhile.
+
static void (*updater)(commodity_t * commodity,
const std::time_t date,
const amount_t& price,
const std::time_t moment);
+ // This map remembers all commodities that have been
+ // defined thus far.
+
+ static commodities_map commodities;
+
+ static void add_commodity(commodity_t * commodity,
+ const std::string symbol = "") {
+ commodities.insert(commodities_pair((symbol.empty() ?
+ commodity->symbol : symbol),
+ commodity));
+ }
+ static bool remove_commodity(commodity_t * commodity) {
+ commodities_map::size_type n = commodities.erase(commodity->symbol);
+ return n > 0;
+ }
+ static commodity_t * find_commodity(const std::string& symbol,
+ bool auto_create = false);
+
+ // Now the per-object constructor and methods
+
commodity_t(const std::string& _symbol = "",
unsigned int _precision = 2,
unsigned int _flags = COMMODITY_STYLE_DEFAULTS)
@@ -377,17 +401,14 @@ inline std::ostream& operator<<(std::ostream& out, const account_t& acct) {
}
-typedef std::map<const std::string, commodity_t *> commodities_map;
-typedef std::pair<const std::string, commodity_t *> commodities_pair;
-
typedef std::list<entry_t *> entries_list;
class ledger_t
{
public:
- account_t * master;
- commodities_map commodities;
- entries_list entries;
+ account_t * master;
+ entries_list entries;
+
std::list<std::string> sources;
ledger_t() {
@@ -409,23 +430,11 @@ class ledger_t
return master->find_account(name, auto_create);
}
- void add_commodity(commodity_t * commodity, const std::string symbol = "") {
- commodities.insert(commodities_pair(symbol.empty() ?
- commodity->symbol : symbol, commodity));
- }
- bool remove_commodity(commodity_t * commodity) {
- commodities_map::size_type n = commodities.erase(commodity->symbol);
- return n > 0;
- }
-
- commodity_t * find_commodity(const std::string& symbol,
- bool auto_create = false);
-
bool add_entry(entry_t * entry);
bool remove_entry(entry_t * entry);
};
-int parse_ledger_file(char * p, ledger_t * book);
+int parse_ledger_file(char * p, ledger_t * journal);
} // namespace ledger