92 :
public ordered_field_operators<amount_t,
93 ordered_field_operators<amount_t, double,
94 ordered_field_operators<amount_t, unsigned long,
95 ordered_field_operators<amount_t, long> > > >
255 template <
typename T>
259 template <
typename T>
263 template <
typename T>
458 operator bool()
const {
684 std::istringstream stream(str);
685 bool result =
parse(stream, flags);
690 const string& smaller_str);
711#define AMOUNT_PRINT_NO_FLAGS 0x00
712#define AMOUNT_PRINT_RIGHT_JUSTIFY 0x01
713#define AMOUNT_PRINT_COLORIZE 0x02
714#define AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS 0x04
715#define AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES 0x08
737 void dump(std::ostream& out)
const {
755 std::ostringstream bufstream;
757 return bufstream.str();
761 std::ostringstream bufstream;
763 return bufstream.str();
767 std::ostringstream bufstream;
769 return bufstream.str();
785 bool commodity_details =
false);
General utility facilities used by Ledger.
#define TRACE_CTOR(cls, args)
datetime_t and date_t objects
#define AMOUNT_PRINT_NO_FLAGS
An amount may be output to a stream using the ‘print’ method.
#define DECLARE_EXCEPTION(name, kind)
flags::basic_t< parse_flags_enum_t, uint_least8_t > parse_flags_t
std::ostream & operator<<(std::ostream &out, const account_t &account)
void put_amount(property_tree::ptree &pt, const amount_t &amt, bool commodity_details=false)
boost::posix_time::ptime datetime_t
std::istream & operator>>(std::istream &in, amount_t &amt)
Encapsulate infinite-precision commoditized amounts.
double to_double() const
Conversion methods.
annotation_t & annotation()
amount_t & operator=(const char *str)
amount_t(const char *val)
Parse a pointer to a C string as an (optionally commoditized) amount.
bool fits_in_long() const
void set_commodity(commodity_t &comm)
bool operator==(const T &val) const
void dump(std::ostream &out) const
There are two methods defined to help with debugging:
bool has_annotation() const
amount_t unrounded() const
Yields an amount whose display precision is never truncated, even though its commodity normally displ...
void print(std::ostream &out, const uint_least8_t flags=0x00) const
static bool is_initialized
amount_t(const string &val)
Parse a string as an (optionally commoditized) amount.
string to_fullstring() const
void set_keep_precision(const bool keep=true) const
amount_t & operator*=(const amount_t &amt)
amount_t inverted() const
amount_t abs() const
Returns the absolute value of an amount.
amount_t(const unsigned long val)
Convert an unsigned long to an amount.
amount_t negated() const
Returns the negated value of an amount.
bool operator<(const T &amt) const
amount_t(const amount_t &amt)
Copy an amount object.
int sign() const
Truth tests.
amount_t & operator-=(const amount_t &amt)
static void initialize()
Ready the amount subsystem for use.
void annotate(const annotation_t &details)
An amount's commodity may be annotated with special details, such as the price it was purchased for,...
amount_t & operator/=(const amount_t &amt)
Divide two amounts while extending the precision to preserve the accuracy of the result.
bool operator==(const amount_t &amt) const
Test two amounts for equality.
optional< amount_t > price() const
amount_t(const long val)
Convert a long to an amount.
void _copy(const amount_t &amt)
amount_t operator-() const
optional< amount_t > value(const datetime_t &moment=datetime_t(), const commodity_t *in_terms_of=NULL) const
Returns the historical value for an amount – the default moment returns the most recently known price...
amount_t roundto(int places) const
amount_t floored() const
Yields an amount which has lost all of its extra precision, beyond what the display precision of the ...
amount_t & operator=(const unsigned long val)
amount_t & operator=(const double val)
bool parse(const string &str, const parse_flags_t &flags=PARSE_DEFAULT)
bool keep_precision() const
amount_t()
Creates a value for which is_null() is true, and which has no value or commodity.
amount_t truncated() const
Yields an amount which has lost all of its extra precision, beyond what the display precision of the ...
void in_place_roundto(int places)
amount_t reduced() const
reduces a value to its most basic commodity form, for amounts that utilize "scaling commodities".
string quantity_string() const
amount_t with_commodity(const commodity_t &comm) const
amount_t & multiply(const amount_t &amt, bool ignore_commodity=false)
static const std::size_t extend_by_digits
Number of places of precision by which values are extended to avoid losing precision during division ...
amount_t strip_annotations(const keep_details_t &what_to_keep) const
If the lot price is considered whenever working with commoditized values.
amount_t ceilinged() const
Yields an amount which has lost all of its extra precision, beyond what the display precision of the ...
precision_t display_precision() const
precision_t precision() const
Return an amount's internal precision.
amount_t & operator+=(const amount_t &amt)
amount_t & operator=(const string &str)
static void shutdown()
Shutdown the amount subsystem and free all resources.
static amount_t exact(const string &value)
Create an amount whose display precision is never truncated, even if the amount uses a commodity (whi...
commodity_t & commodity() const
amount_t unreduced() const
unreduce(), if used with a "scaling commodity", yields the most compact form greater than one.
amount_t rounded() const
Yields an amount whose display precision when output is truncated to the display precision of its com...
bool parse(std::istream &in, const parse_flags_t &flags=PARSE_DEFAULT)
The ‘flags’ argument of both parsing may be one or more of the following:
amount_t & operator=(const long val)
const annotation_t & annotation() const
amount_t & operator=(const amount_t &amt)
Assign an amount object.
static void parse_conversion(const string &larger_str, const string &smaller_str)
commodity_t * commodity_ptr() const
The following methods relate to an amount's commodity:
amount_t(const double val)
Convert a double to an amount.
bool has_commodity() const
amount_t(const amount_t &amt, const annotation_t &details)
Copy an amount object, applying the given commodity annotation details afterward.
~amount_t()
Release the reference count held for the underlying amount_t::bigint_t object.
uint_least16_t precision_t
The amount's decimal precision.
bool operator>(const T &amt) const
int compare(const amount_t &amt) const
Compare two amounts, returning a number less than zero if amt is greater, exactly zero if they are eq...
static bool stream_fullstrings
If amounts should be streamed using to_fullstring() rather than to_string(), so that complete precisi...