summaryrefslogtreecommitdiff
path: root/amount.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-10 05:07:50 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-10 05:07:50 -0400
commite414123ecb472d1f86a2f1cfdbd2732144c20f0d (patch)
treecafc81314d337786ea0d8461a96110ee5b1d6fe2 /amount.h
parent6261da4660a6602345c19d5a948124991bda86dc (diff)
downloadfork-ledger-e414123ecb472d1f86a2f1cfdbd2732144c20f0d.tar.gz
fork-ledger-e414123ecb472d1f86a2f1cfdbd2732144c20f0d.tar.bz2
fork-ledger-e414123ecb472d1f86a2f1cfdbd2732144c20f0d.zip
change commodity->symbol to const, and added set_symbol
Diffstat (limited to 'amount.h')
-rw-r--r--amount.h30
1 files changed, 16 insertions, 14 deletions
diff --git a/amount.h b/amount.h
index d58bd6e6..17fec339 100644
--- a/amount.h
+++ b/amount.h
@@ -271,16 +271,16 @@ class commodity_t
typedef unsigned long ident_t;
- std::string symbol;
- bool quote;
- std::string name;
- std::string note;
- unsigned short precision;
- unsigned short flags;
- history_map history;
- std::time_t last_lookup;
- amount_t conversion;
- ident_t ident;
+ const std::string symbol;
+ bool quote;
+ std::string name;
+ std::string note;
+ unsigned short precision;
+ unsigned short flags;
+ history_map history;
+ std::time_t last_lookup;
+ amount_t conversion;
+ ident_t ident;
// If set, this global function pointer is called to determine
// whether prices have been updated in the meanwhile.
@@ -315,9 +315,8 @@ class commodity_t
commodity_t(const std::string& _symbol = "",
unsigned int _precision = 0,
unsigned int _flags = COMMODITY_STYLE_DEFAULTS)
- : symbol(_symbol), quote(false), precision(_precision),
- flags(_flags), last_lookup(0) {
- check_symbol();
+ : precision(_precision), flags(_flags), last_lookup(0) {
+ set_symbol(_symbol);
}
operator bool() const {
@@ -330,12 +329,15 @@ class commodity_t
return this != &comm;
}
- void check_symbol() {
+ void set_symbol(const std::string& sym) {
+ *(const_cast<std::string *>(&symbol)) = sym;
+ quote = false;
for (const char * p = symbol.c_str(); *p; p++)
if (std::isspace(*p) || std::isdigit(*p) || *p == '-' || *p == '.') {
quote = true;
return;
}
+
}
void add_price(const std::time_t date, const amount_t& price);