diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-21 20:45:13 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:39:06 -0400 |
commit | d23ed020abf494a046b499cdce1c0957cd5b4783 (patch) | |
tree | bd9035df62b9ef7cbf77045bb018de8e33270fca /src/numerics | |
parent | fdfc37adf948415b6caad55c08e8313abd4e1b1b (diff) | |
download | fork-ledger-d23ed020abf494a046b499cdce1c0957cd5b4783.tar.gz fork-ledger-d23ed020abf494a046b499cdce1c0957cd5b4783.tar.bz2 fork-ledger-d23ed020abf494a046b499cdce1c0957cd5b4783.zip |
Whitespace cleanup.
Diffstat (limited to 'src/numerics')
-rw-r--r-- | src/numerics/amount.cc | 31 | ||||
-rw-r--r-- | src/numerics/amount.h | 8 | ||||
-rw-r--r-- | src/numerics/balance.h | 30 | ||||
-rw-r--r-- | src/numerics/balpair.h | 87 | ||||
-rw-r--r-- | src/numerics/commodity.cc | 4 | ||||
-rw-r--r-- | src/numerics/commodity.h | 8 | ||||
-rw-r--r-- | src/numerics/value.h | 14 |
7 files changed, 91 insertions, 91 deletions
diff --git a/src/numerics/amount.cc b/src/numerics/amount.cc index 4c771cc7..79dd663c 100644 --- a/src/numerics/amount.cc +++ b/src/numerics/amount.cc @@ -33,9 +33,9 @@ * @file amount.cc * @author John Wiegley * @date Thu Apr 26 15:19:46 2007 - * + * * @brief Types for handling commoditized math. - * + * * This file defines member functions for amount_t, and also defines a * helper class, bigint_t, which is used as a refcounted wrapper * around libgmp's mpz_t type. @@ -43,6 +43,7 @@ #include "amount.h" #include "binary.h" +#include "parser.h" namespace ledger { @@ -330,7 +331,7 @@ int amount_t::compare(const amount_t& amt) const else throw_(amount_error, "Cannot compare two uninitialized amounts"); } - + if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) throw_(amount_error, @@ -363,7 +364,7 @@ amount_t& amount_t::operator+=(const amount_t& amt) else throw_(amount_error, "Cannot add two uninitialized amounts"); } - + if (commodity() != amt.commodity()) throw_(amount_error, "Adding amounts with different commodities: " << @@ -399,7 +400,7 @@ amount_t& amount_t::operator-=(const amount_t& amt) else throw_(amount_error, "Cannot subtract two uninitialized amounts"); } - + if (commodity() != amt.commodity()) throw_(amount_error, "Subtracting amounts with different commodities: " << @@ -483,7 +484,7 @@ amount_t& amount_t::operator*=(const amount_t& amt) else throw_(amount_error, "Cannot multiply two uninitialized amounts"); } - + if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) throw_(amount_error, @@ -521,7 +522,7 @@ amount_t& amount_t::operator/=(const amount_t& amt) else throw_(amount_error, "Cannot divide two uninitialized amounts"); } - + if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) throw_(amount_error, @@ -1218,10 +1219,10 @@ namespace { void amount_t::read(std::istream& in) { - using ledger::binary; + using namespace ledger::binary; // Read in the commodity for this amount - + commodity_t::ident_t ident; read_long(in, ident); if (ident == 0xffffffff) @@ -1266,10 +1267,10 @@ void amount_t::read(std::istream& in) void amount_t::read(const char *& data) { - using ledger::binary; - + using namespace ledger::binary; + // Read in the commodity for this amount - + commodity_t::ident_t ident; read_long(data, ident); if (ident == 0xffffffff) @@ -1323,10 +1324,10 @@ void amount_t::read(const char *& data) void amount_t::write(std::ostream& out, bool optimized) const { - using ledger::binary; - + using namespace ledger::binary; + // Write out the commodity for this amount - + if (! quantity) throw_(amount_error, "Cannot serialize an uninitialized amount"); diff --git a/src/numerics/amount.h b/src/numerics/amount.h index f4dbc9bd..1c8ef6d0 100644 --- a/src/numerics/amount.h +++ b/src/numerics/amount.h @@ -33,9 +33,9 @@ * @file amount.h * @author John Wiegley * @date Wed Apr 18 22:05:53 2007 - * + * * @brief Basic type for handling commoditized math: amount_t. - * + * * This file contains the most basic numerical type in Ledger: * amount_t, which relies upon commodity.h (commodity_t) for handling * commoditized amounts. This class allows Ledger to handle @@ -78,7 +78,7 @@ class amount_t // jww (2007-05-03): Make this private, and then make // ledger::initialize into a member function of session_t. public: - /** + /** * The initialize and shutdown methods ready the amount subsystem * for use. Normally they are called by `ledger::initialize' and * `ledger::shutdown'. @@ -347,7 +347,7 @@ public: return *this; } - amount_t round(const optional<precision_t>& prec) const; + amount_t round(const optional<precision_t>& prec = none) const; amount_t unround() const; amount_t reduce() const { diff --git a/src/numerics/balance.h b/src/numerics/balance.h index 1bab4b6b..b132115f 100644 --- a/src/numerics/balance.h +++ b/src/numerics/balance.h @@ -33,9 +33,9 @@ * @file balance.h * @author John Wiegley * @date Sun May 20 15:28:44 2007 - * + * * @brief Basic type for adding multiple commodities together. - * + * * Unlike the amount_t class, which throws an exception if amounts of * differing commodities are added or subtracted, the balance_t class * is designed to allow this, tracking the amounts of each component @@ -60,19 +60,19 @@ DECLARE_EXCEPTION(balance_error); */ class balance_t : public equality_comparable<balance_t, - equality_comparable<balance_t, amount_t, - equality_comparable<balance_t, double, - equality_comparable<balance_t, unsigned long, - equality_comparable<balance_t, long, - additive<balance_t, - additive<balance_t, amount_t, - additive<balance_t, double, - additive<balance_t, unsigned long, - additive<balance_t, long, - multiplicative<balance_t, amount_t, - multiplicative<balance_t, double, - multiplicative<balance_t, unsigned long, - multiplicative<balance_t, long> > > > > > > > > > > > > > + equality_comparable<balance_t, amount_t, + equality_comparable<balance_t, double, + equality_comparable<balance_t, unsigned long, + equality_comparable<balance_t, long, + additive<balance_t, + additive<balance_t, amount_t, + additive<balance_t, double, + additive<balance_t, unsigned long, + additive<balance_t, long, + multiplicative<balance_t, amount_t, + multiplicative<balance_t, double, + multiplicative<balance_t, unsigned long, + multiplicative<balance_t, long> > > > > > > > > > > > > > { public: typedef std::map<const commodity_t *, amount_t> amounts_map; diff --git a/src/numerics/balpair.h b/src/numerics/balpair.h index 13e4857b..af1a25ab 100644 --- a/src/numerics/balpair.h +++ b/src/numerics/balpair.h @@ -33,9 +33,9 @@ * @file balpair.h * @author John Wiegley * @date Sun May 20 19:11:58 2007 - * + * * @brief Provides an abstraction around balance_t for tracking costs. - * + * * When a transaction's amount is added to a balance, only the "value" * of the amount is added -- not the associated cost of the * transaction. To provide for this, the balance_pair_t type allows @@ -56,24 +56,24 @@ namespace ledger { class balance_pair_t - : public equality_comparable<balance_pair_t, - equality_comparable<balance_pair_t, balance_t, - equality_comparable<balance_pair_t, amount_t, - equality_comparable<balance_pair_t, double, - equality_comparable<balance_pair_t, unsigned long, - equality_comparable<balance_pair_t, long, - additive<balance_pair_t, - additive<balance_pair_t, balance_t, - additive<balance_pair_t, amount_t, - additive<balance_pair_t, double, - additive<balance_pair_t, unsigned long, - additive<balance_pair_t, long, - multiplicative<balance_pair_t, amount_t, - multiplicative<balance_pair_t, balance_t, - multiplicative<balance_pair_t, double, - multiplicative<balance_pair_t, unsigned long, - multiplicative2<balance_pair_t, long, balance_t - > > > > > > > > > > > > > > > > > + : public balance_t, + public equality_comparable<balance_pair_t, + equality_comparable<balance_pair_t, balance_t, + equality_comparable<balance_pair_t, amount_t, + equality_comparable<balance_pair_t, double, + equality_comparable<balance_pair_t, unsigned long, + equality_comparable<balance_pair_t, long, + additive<balance_pair_t, + additive<balance_pair_t, balance_t, + additive<balance_pair_t, amount_t, + additive<balance_pair_t, double, + additive<balance_pair_t, unsigned long, + additive<balance_pair_t, long, + multiplicative<balance_pair_t, amount_t, + multiplicative<balance_pair_t, balance_t, + multiplicative<balance_pair_t, double, + multiplicative<balance_pair_t, unsigned long, + multiplicative<balance_pair_t, long> > > > > > > > > > > > > > > > > { /** * The `cost' member of a balance pair tracks the cost associated @@ -216,33 +216,22 @@ public: // comparison bool operator==(const balance_pair_t& bal_pair) const { - return quantity == bal_pair.quantity; + return quantity() == bal_pair.quantity(); } bool operator==(const balance_t& bal) const { - return quantity == bal; + return quantity() == bal; } bool operator==(const amount_t& amt) const { - return quantity == amt; - } - - balance_pair_t& operator*=(const amount_t& amt) { - quantity *= amt; - if (cost) - *cost *= amt; - return *this; - } - balance_pair_t& operator/=(const amount_t& amt) { - quantity /= amt; - if (cost) - *cost /= amt; - return *this; + return quantity() == amt; } // unary negation void in_place_negate() { +#if 0 quantity.in_place_negate(); if (cost) cost->in_place_negate(); +#endif } balance_pair_t negate() const { balance_pair_t temp = *this; @@ -255,57 +244,67 @@ public: // test for non-zero (use ! for zero) operator bool() const { - return quantity; + return quantity(); } bool is_realzero() const { +#if 0 return ((! cost || cost->is_realzero()) && quantity.is_realzero()); +#else + return false; +#endif } balance_pair_t abs() const { +#if 0 balance_pair_t temp = *this; temp.quantity = temp.quantity.abs(); if (temp.cost) temp.cost = temp.cost->abs(); return temp; +#else + return balance_pair_t(); +#endif } optional<amount_t> commodity_amount(const optional<const commodity_t&>& commodity = none) const { - return quantity.commodity_amount(commodity); + return quantity().commodity_amount(commodity); } optional<balance_t> value(const optional<moment_t>& moment = none) const { - return quantity.value(moment); + return quantity().value(moment); } balance_t strip_annotations(const bool keep_price = amount_t::keep_price, const bool keep_date = amount_t::keep_date, const bool keep_tag = amount_t::keep_tag) const { - return quantity.strip_annotations(keep_price, keep_date, keep_tag); + return quantity().strip_annotations(keep_price, keep_date, keep_tag); } void print(std::ostream& out, const int first_width, const int latter_width = -1) const { - quantity.print(out, first_width, latter_width); + quantity().print(out, first_width, latter_width); } balance_pair_t& add(const amount_t& amt, const optional<amount_t>& a_cost = none) { +#if 0 if (a_cost && ! cost) cost = quantity; quantity += amt; if (cost) *cost += a_cost ? *a_cost : amt; +#endif return *this; } bool valid() { - return quantity.valid() && (! cost || cost->valid()); + return quantity().valid() && (! cost || cost->valid()); } void in_place_reduce() { - quantity.in_place_reduce(); + quantity().in_place_reduce(); if (cost) cost->in_place_reduce(); } balance_pair_t reduce() const { @@ -320,7 +319,7 @@ public: inline std::ostream& operator<<(std::ostream& out, const balance_pair_t& bal_pair) { - bal_pair.quantity.print(out, 12); + bal_pair.quantity().print(out, 12); return out; } diff --git a/src/numerics/commodity.cc b/src/numerics/commodity.cc index 8ab518ee..589ddd05 100644 --- a/src/numerics/commodity.cc +++ b/src/numerics/commodity.cc @@ -33,9 +33,9 @@ * @file commodity.cc * @author John Wiegley * @date Thu Apr 26 15:19:46 2007 - * + * * @brief Types for dealing with commodities. - * + * * This file defines member functions for flavors of commodity_t. */ diff --git a/src/numerics/commodity.h b/src/numerics/commodity.h index 6212e743..5389ed46 100644 --- a/src/numerics/commodity.h +++ b/src/numerics/commodity.h @@ -33,9 +33,9 @@ * @file commodity.h * @author John Wiegley * @date Wed Apr 18 22:05:53 2007 - * + * * @brief Types for handling commodities. - * + * * This file contains one of the most basic types in Ledger: * commodity_t, and its annotated cousin, annotated_commodity_t. */ @@ -240,7 +240,7 @@ struct annotation_t : public equality_comparable<annotation_t> out << "price " << (price ? price->to_string() : "NONE") << " " << "date " << (date ? *date : moment_t()) << " " << "tag " << (tag ? *tag : "NONE"); - } + } bool valid() const { assert(*this); @@ -256,7 +256,7 @@ inline std::ostream& operator<<(std::ostream& out, const annotation_t& details) class annotated_commodity_t : public commodity_t, public equality_comparable<annotated_commodity_t, - equality_comparable2<annotated_commodity_t, commodity_t, + equality_comparable2<annotated_commodity_t, commodity_t, noncopyable> > { public: diff --git a/src/numerics/value.h b/src/numerics/value.h index 28024767..a70bf33e 100644 --- a/src/numerics/value.h +++ b/src/numerics/value.h @@ -51,12 +51,12 @@ namespace xml { class value_t : public ordered_field_operators<value_t, - ordered_field_operators<value_t, balance_pair_t, - ordered_field_operators<value_t, balance_t, - ordered_field_operators<value_t, amount_t, - ordered_field_operators<value_t, double, - ordered_field_operators<value_t, unsigned long, - ordered_field_operators<value_t, long> > > > > > > + ordered_field_operators<value_t, balance_pair_t, + ordered_field_operators<value_t, balance_t, + ordered_field_operators<value_t, amount_t, + ordered_field_operators<value_t, double, + ordered_field_operators<value_t, unsigned long, + ordered_field_operators<value_t, long> > > > > > > { public: typedef std::vector<value_t> sequence_t; @@ -625,7 +625,7 @@ public: assert(false); return "<invalid>"; } - + value_t operator-() const { return negate(); } |