66 :
public equality_comparable<balance_t,
67 equality_comparable<balance_t, amount_t,
68 equality_comparable<balance_t, double,
69 equality_comparable<balance_t, unsigned long,
70 equality_comparable<balance_t, long,
72 additive<balance_t, amount_t,
73 additive<balance_t, double,
74 additive<balance_t, unsigned long,
75 additive<balance_t, long,
76 multiplicative<balance_t, amount_t,
77 multiplicative<balance_t, double,
78 multiplicative<balance_t, unsigned long,
79 multiplicative<balance_t, long> > > > > > > > > > > > > >
82 typedef std::unordered_map<commodity_t *, amount_t>
amounts_map;
113 _(
"Cannot initialize a balance from an uninitialized amount"));
114 if (!
amt.is_realzero())
115 amounts.insert(amounts_map::value_type(&
amt.commodity(),
amt));
156 _(
"Cannot assign an uninitialized amount to a balance"));
159 if (!
amt.is_realzero())
160 amounts.insert(amounts_map::value_type(&
amt.commodity(),
amt));
193 _(
"Cannot compare a balance to an uninitialized amount"));
195 if (
amt.is_realzero())
201 template <
typename T>
293 temp.in_place_negate();
297 foreach (amounts_map::value_type& pair,
amounts)
298 pair.second.in_place_negate();
306 foreach (
const amounts_map::value_type& pair,
amounts)
313 temp.in_place_round();
317 foreach (amounts_map::value_type& pair,
amounts)
318 pair.second.in_place_round();
328 foreach (amounts_map::value_type& pair,
amounts)
329 pair.second.in_place_roundto(
places);
334 temp.in_place_truncate();
338 foreach (amounts_map::value_type& pair,
amounts)
339 pair.second.in_place_truncate();
344 temp.in_place_floor();
348 foreach (amounts_map::value_type& pair,
amounts)
349 pair.second.in_place_floor();
354 temp.in_place_ceiling();
358 foreach (amounts_map::value_type& pair,
amounts)
359 pair.second.in_place_ceiling();
365 temp.in_place_unround();
369 foreach (amounts_map::value_type& pair,
amounts)
370 pair.second.in_place_unround();
375 temp.in_place_reduce();
382 foreach (
const amounts_map::value_type& pair,
amounts)
389 temp.in_place_unreduce();
396 foreach (
const amounts_map::value_type& pair,
amounts)
431 foreach (
const amounts_map::value_type& pair,
amounts)
432 if (pair.second.is_nonzero())
441 foreach (
const amounts_map::value_type& pair,
amounts)
442 if (! pair.second.is_zero())
451 foreach (
const amounts_map::value_type& pair,
amounts)
452 if (! pair.second.is_realzero())
472 std::ostringstream buf;
481 return amounts.begin()->second;
484 _(
"Cannot convert a balance with multiple commodities to an amount"));
513 foreach (
const amounts_map::value_type& pair,
amounts)
578 void dump(std::ostream& out)
const {
581 foreach (
const amounts_map::value_type& pair,
amounts) {
586 pair.second.print(out);
592 foreach (
const amounts_map::value_type& pair,
amounts)
593 if (! pair.second.valid()) {
594 DEBUG(
"ledger.validate",
"balance_t: ! pair.second.valid()");
#define TRACE_CTOR(cls, args)
Basic type for handling commoditized math: amount_t.
#define AMOUNT_PRINT_NO_FLAGS
An amount may be output to a stream using the ‘print’ method.
#define DECLARE_EXCEPTION(name, kind)
balance_t average_lot_prices(const balance_t &bal)
void put_balance(property_tree::ptree &pt, const balance_t &bal)
std::ostream & operator<<(std::ostream &out, const account_t &account)
boost::posix_time::ptime datetime_t
Encapsulate infinite-precision commoditized amounts.
A wrapper around amount_t allowing addition of multiple commodities.
balance_t & operator+=(const balance_t &bal)
Binary arithmetic operators.
balance_t & operator*=(const unsigned long val)
void in_place_roundto(int places)
balance_t & operator=(const string &str)
balance_t & operator/=(const long val)
bool single_amount() const
balance_t unreduced() const
balance_t truncated() const
balance_t floored() const
balance_t & operator-=(const double val)
balance_t & operator=(const char *str)
optional< balance_t > value(const datetime_t &moment=datetime_t(), const commodity_t *in_terms_of=NULL) const
bool operator==(const balance_t &bal) const
Comparison operators.
balance_t & operator*=(const amount_t &amt)
balance_t reduced() const
void map_sorted_amounts(function< void(const amount_t &)> fn) const
Iteration primitives.
balance_t(const string &val)
balance_t & operator-=(const amount_t &amt)
balance_t & operator-=(const balance_t &bal)
balance_t(const amount_t &amt)
balance_t(const long val)
balance_t & operator+=(const amount_t &amt)
bool operator==(const amount_t &amt) const
balance_t & operator=(const amount_t &amt)
std::unordered_map< commodity_t *, amount_t > amounts_map
amount_t to_amount() const
balance_t(const balance_t &bal)
Assignment and copy operators.
balance_t(const char *val)
balance_t(const double val)
balance_t operator-() const
balance_t unrounded() const
balance_t rounded() const
balance_t & operator*=(const long val)
balance_t & operator=(const balance_t &bal)
balance_t & operator*=(const double val)
balance_t roundto(int places) const
balance_t & operator/=(const double val)
balance_t & operator+=(const long val)
balance_t & operator-=(const long val)
void sorted_amounts(amounts_array &sorted) const
Given a balance, insert a commodity-wise sort of the amounts into the given amounts_array.
balance_t & operator+=(const unsigned long val)
balance_t negated() const
Unary arithmetic operators.
std::vector< const amount_t * > amounts_array
std::size_t commodity_count() const
Commodity-related methods.
bool operator==(const T &val) const
balance_t & operator-=(const unsigned long val)
amounts_map::const_iterator find_by_name(const commodity_t &comm) const
void print(std::ostream &out, const int first_width=-1, const int latter_width=-1, const uint_least8_t flags=0x00) const
Printing methods.
balance_t strip_annotations(const keep_details_t &what_to_keep) const
Annotated commodity methods.
balance_t & operator/=(const amount_t &amt)
balance_t(const unsigned long val)
balance_t & operator+=(const double val)
optional< amount_t > commodity_amount(const optional< const commodity_t & > &commodity=none) const
amounts_map::iterator find_by_name(const commodity_t &comm)
balance_t ceilinged() const
balance_t & operator/=(const unsigned long val)
void dump(std::ostream &out) const
Debugging methods.