From 7ce12f8cfe0beaecea3de7e073aa3c9751742a5d Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 1 Oct 2003 21:55:40 +0000 Subject: *** empty log message *** --- amount.cc | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'amount.cc') diff --git a/amount.cc b/amount.cc index 41837767..695c4226 100644 --- a/amount.cc +++ b/amount.cc @@ -59,13 +59,10 @@ class gmp_amount : public amount virtual operator bool() const; - virtual void credit(const amount * other) { - *this += *other; - } virtual void negate() { mpz_ui_sub(quantity, 0, quantity); } - virtual void operator+=(const amount& other); + virtual void credit(const amount * other); virtual void parse(const char * num) { *this = num; @@ -211,30 +208,32 @@ amount * gmp_amount::street() const extern bool get_quotes; for (int cycles = 0; cycles < 10; cycles++) { - totals::iterator pi = main_ledger.prices.amounts.find(amt->comm_symbol()); + totals::iterator pi = + main_ledger.prices.amounts.find(amt->comm_symbol()); if (pi == main_ledger.prices.amounts.end()) { - if (get_quotes && amt->comm_symbol() != DEFAULT_COMMODITY) { - using namespace std; - - char buf[256]; - buf[0] = '\0'; - - if (FILE * fp = popen((std::string("getquote ") + - amt->comm_symbol()).c_str(), "r")) { - if (feof(fp) || ! fgets(buf , 255, fp)) { - fclose(fp); - break; - } + using namespace std; + + if (! get_quotes) + break; + + char buf[256]; + buf[0] = '\0'; + + if (FILE * fp = popen((std::string("getquote ") + + amt->comm_symbol()).c_str(), "r")) { + if (feof(fp) || ! fgets(buf , 255, fp)) { fclose(fp); + break; } + fclose(fp); + } - if (buf[0]) { - char * p = strchr(buf, '\n'); - if (p) *p = '\0'; + if (buf[0]) { + char * p = strchr(buf, '\n'); + if (p) *p = '\0'; - main_ledger.record_price((amt->comm_symbol() + "=" + buf).c_str()); - continue; - } + main_ledger.record_price((amt->comm_symbol() + "=" + buf).c_str()); + continue; } break; } else { @@ -598,11 +597,11 @@ amount& gmp_amount::operator=(const char * num) return *this; } -void gmp_amount::operator+=(const amount& _other) +void gmp_amount::credit(const amount * value) { - const gmp_amount& other = dynamic_cast(_other); - assert(quantity_comm == other.quantity_comm); - mpz_add(quantity, quantity, other.quantity); + const gmp_amount * val = dynamic_cast(value); + assert(quantity_comm == val->quantity_comm); + mpz_add(quantity, quantity, val->quantity); } } // namespace ledger -- cgit v1.2.3