Dynamic type representing various numeric types. More...
#include <value.h>
Inherits ordered_field_operators< value_t, equality_comparable< value_t, balance_t, additive< value_t, balance_t, multiplicative< 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 > > > > > > > >.
Classes | |
class | storage_t |
Public Types | |
typedef sequence_t::const_iterator | const_iterator |
typedef sequence_t::difference_type | difference_type |
typedef sequence_t::iterator | iterator |
typedef ptr_deque< value_t > | sequence_t |
The sequence_t member type abstracts the type used to represent a resizable "array" of value_t objects. | |
enum | type_t { VOID , BOOLEAN , DATETIME , DATE , INTEGER , AMOUNT , BALANCE , STRING , MASK , SEQUENCE , SCOPE , ANY } |
type_t gives the type of the data contained or referenced by a value_t object. More... | |
Static Public Member Functions | |
static void | initialize () |
static void | shutdown () |
Dynamic type representing various numeric types.
The following type is a polymorphous value type used solely for performance reasons. The alternative is to compute value expressions (valexpr.cc) in terms of the largest data type, balance_t. This was found to be prohibitively expensive, especially when large logic chains were involved, since many temporary allocations would occur for every operator. With value_t, and the fact that logic chains only need boolean values to continue, no memory allocations need to take place at all.
typedef sequence_t::const_iterator ledger::value_t::const_iterator |
typedef sequence_t::difference_type ledger::value_t::difference_type |
typedef sequence_t::iterator ledger::value_t::iterator |
|
inline |
Constructors.
value_t objects may be constructed from almost any value type that they can contain, including variations on those types (such as long, unsigned long, etc). The ordering of the methods here reflects the ordering of the constants in type_t above.
One constructor of special note is that taking a string or character pointer as an argument. Because value_t("$100") is interpreted as a commoditized amount, the form value_t("$100", true) is required to represent the literal string "$100", and not the amount "one hundred dollars".
Definition at line 273 of file value.h.
References TRACE_CTOR.
Referenced by push_back(), and push_front().
Definition at line 277 of file value.h.
References ledger::downcast(), set_boolean(), and TRACE_CTOR.
|
inline |
Definition at line 282 of file value.h.
References ledger::downcast(), set_datetime(), and TRACE_CTOR.
Definition at line 286 of file value.h.
References ledger::downcast(), set_date(), and TRACE_CTOR.
Definition at line 291 of file value.h.
References ledger::downcast(), set_long(), and TRACE_CTOR.
Definition at line 295 of file value.h.
References ledger::downcast(), set_amount(), and TRACE_CTOR.
Definition at line 299 of file value.h.
References ledger::downcast(), set_amount(), and TRACE_CTOR.
Definition at line 303 of file value.h.
References ledger::downcast(), set_amount(), and TRACE_CTOR.
Definition at line 307 of file value.h.
References ledger::downcast(), set_balance(), and TRACE_CTOR.
Definition at line 311 of file value.h.
References ledger::downcast(), set_mask(), and TRACE_CTOR.
Definition at line 316 of file value.h.
References ledger::downcast(), set_amount(), set_string(), and TRACE_CTOR.
Definition at line 324 of file value.h.
References ledger::downcast(), set_amount(), set_string(), and TRACE_CTOR.
|
inline |
Definition at line 333 of file value.h.
References ledger::downcast(), set_sequence(), and TRACE_CTOR.
|
inlineexplicit |
Definition at line 338 of file value.h.
References ledger::downcast(), set_scope(), and TRACE_CTOR.
|
inline |
Destructor.
This does not do anything, because the intrusive_ptr that refers to our storage object will decrease its reference count itself upon destruction.
Definition at line 355 of file value.h.
References TRACE_DTOR.
Assignment and copy operators.
Values are cheaply copied by simply creating another reference to the other value's storage object. A true copy is only ever made prior to modification.
Definition at line 364 of file value.h.
References ledger::downcast(), and TRACE_CTOR.
value_t ledger::value_t::abs | ( | ) | const |
void ledger::value_t::annotate | ( | const annotation_t & | details | ) |
Annotated commodity methods.
annotation_t & ledger::value_t::annotation | ( | ) |
|
inline |
Definition at line 828 of file value.h.
References annotation().
Definition at line 625 of file value.h.
References is_amount(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 620 of file value.h.
References is_amount(), and VERIFY.
|
inline |
Definition at line 759 of file value.h.
References as_any(), and ledger::downcast().
|
inline |
Definition at line 745 of file value.h.
References is_any(), and VERIFY.
Referenced by as_any_lval().
|
inline |
Definition at line 751 of file value.h.
References as_any_lval(), and ledger::downcast().
Definition at line 643 of file value.h.
References is_balance(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 638 of file value.h.
References is_balance(), and VERIFY.
Definition at line 557 of file value.h.
References is_boolean(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 552 of file value.h.
References is_boolean(), and VERIFY.
Definition at line 591 of file value.h.
References is_date(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
|
inline |
Definition at line 574 of file value.h.
References is_datetime(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 569 of file value.h.
References is_datetime(), and VERIFY.
Definition at line 608 of file value.h.
References is_long(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 685 of file value.h.
References is_mask(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
|
inline |
Definition at line 722 of file value.h.
References is_scope(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 707 of file value.h.
References is_sequence(), and VERIFY.
Referenced by begin(), end(), operator[](), pop_back(), and size().
|
inline |
Definition at line 702 of file value.h.
References is_sequence(), and VERIFY.
Referenced by begin(), end(), operator[](), pop_back(), push_back(), and push_front().
Definition at line 661 of file value.h.
References is_string(), and VERIFY.
Referenced by ledger::call_scope_t::get().
|
inline |
Definition at line 656 of file value.h.
References is_string(), and VERIFY.
|
inline |
Definition at line 895 of file value.h.
References as_sequence_lval(), is_sequence(), and VERIFY.
Referenced by ledger::call_scope_t::begin(), and ledger::call_scope_t::begin().
|
inline |
Definition at line 904 of file value.h.
References as_sequence(), is_sequence(), and VERIFY.
Dynamic typing conversion methods.
‘cast(type_t)’ returns a new value whose type has been cast to the given type, but whose value is based on the original value. For example, the uncommoditized AMOUNT "100.00" could be cast to an INTEGER value. If a cast would lose information or is not meaningful, an exception is thrown.
‘simplify()’ is an automatic cast to the simplest type that can still represent the original value.
There are also "in-place" versions of these two methods: in_place_cast in_place_simplify
Definition at line 805 of file value.h.
References ledger::downcast().
|
inline |
Definition at line 452 of file value.h.
References ledger::downcast().
|
inline |
Definition at line 922 of file value.h.
References size().
Referenced by ledger::draft_t::draft_t(), and ledger::query_t::query_t().
|
inline |
Definition at line 899 of file value.h.
References as_sequence_lval(), is_sequence(), and VERIFY.
Referenced by ledger::call_scope_t::end(), and ledger::call_scope_t::end().
|
inline |
Definition at line 908 of file value.h.
References as_sequence(), is_sequence(), and VERIFY.
value_t ledger::value_t::exchange_commodities | ( | const std::string & | commodities, |
const bool | add_prices = false, | ||
const datetime_t & | moment = datetime_t() ) |
|
inline |
Definition at line 445 of file value.h.
References ledger::downcast().
bool ledger::value_t::has_annotation | ( | ) | const |
void ledger::value_t::in_place_ceiling | ( | ) |
void ledger::value_t::in_place_floor | ( | ) |
void ledger::value_t::in_place_negate | ( | ) |
void ledger::value_t::in_place_not | ( | ) |
void ledger::value_t::in_place_reduce | ( | ) |
void ledger::value_t::in_place_round | ( | ) |
void ledger::value_t::in_place_simplify | ( | ) |
void ledger::value_t::in_place_truncate | ( | ) |
void ledger::value_t::in_place_unreduce | ( | ) |
void ledger::value_t::in_place_unround | ( | ) |
|
inline |
Definition at line 617 of file value.h.
References AMOUNT, and is_type().
Referenced by as_amount(), and as_amount_lval().
|
inline |
Dealing with any type at all is bit involved because we actually deal with typed object.
For example, if you call as_any it returns a boost::any object, but if you use as_any<type_t>, then it returns a type_t by value.
Definition at line 737 of file value.h.
References ANY, and is_type().
Referenced by as_any(), and as_any_lval().
|
inline |
Definition at line 635 of file value.h.
References BALANCE, and is_type().
Referenced by as_balance(), and as_balance_lval().
|
inline |
Data manipulation methods.
A value object may be truth tested for the existence of every type it can contain:
is_boolean() is_long() is_datetime() is_date() is_amount() is_balance() is_string() is_mask() is_sequence() is_any()
There are corresponding as_*() methods that represent a value as a reference to its underlying type. For example, as_long() returns a reference to a "const long".
There are also as_*_lval() methods, which represent the underlying data as a reference to a non-const type. The difference here is that an _lval() call causes the underlying data to be fully copied before the resulting reference is returned.
Lastly, there are corresponding set_*(data) methods for directly assigning data of a particular type, rather than using the regular assignment operator (whose implementation simply calls the various set_ methods).
Definition at line 549 of file value.h.
References BOOLEAN, and is_type().
Referenced by as_boolean(), and as_boolean_lval().
|
inline |
|
inline |
Definition at line 566 of file value.h.
References DATETIME, and is_type().
Referenced by as_datetime(), and as_datetime_lval().
Comparison operators.
Values can be compared to other values
Referenced by operator==().
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 499 of file value.h.
References is_type(), VERIFY, and VOID.
Referenced by ledger::call_scope_t::has(), operator[](), operator[](), pop_back(), push_back(), push_front(), and size().
bool ledger::value_t::is_realzero | ( | ) | const |
|
inline |
Dealing with scope pointers.
Definition at line 719 of file value.h.
References is_type(), and SCOPE.
Referenced by as_scope().
|
inline |
Definition at line 699 of file value.h.
References is_type(), and SEQUENCE.
Referenced by as_sequence(), as_sequence_lval(), begin(), begin(), end(), end(), operator[](), operator[](), pop_back(), push_back(), push_front(), and size().
|
inline |
Definition at line 653 of file value.h.
References is_type(), and STRING.
Referenced by as_string(), and as_string_lval().
Definition at line 512 of file value.h.
References ledger::downcast(), and type().
Referenced by is_amount(), is_any(), is_balance(), is_boolean(), is_date(), is_datetime(), is_long(), is_mask(), is_null(), is_scope(), is_sequence(), and is_string().
bool ledger::value_t::is_zero | ( | ) | const |
|
inline |
Unary arithmetic operators.
Definition at line 410 of file value.h.
References ledger::downcast(), and in_place_negate().
Referenced by operator-().
value_t ledger::value_t::number | ( | ) | const |
ledger::value_t::operator bool | ( | ) | const |
Truth tests.
Binary arithmetic operators.
add(amount_t, optional<amount_t>) allows for the possibility of adding both an amount and its cost in a single operation. Otherwise, there is no way to separately represent the "cost" part of an amount addition statement.
|
inline |
Definition at line 386 of file value.h.
References ledger::downcast(), and is_less_than().
Definition at line 368 of file value.h.
References ledger::downcast().
Definition at line 382 of file value.h.
References ledger::downcast(), and is_equal_to().
Definition at line 390 of file value.h.
References ledger::downcast(), and is_greater_than().
Collection-style access methods for SEQUENCE values.
Definition at line 837 of file value.h.
References as_sequence_lval(), assert, ledger::downcast(), is_null(), is_sequence(), and VERIFY.
Definition at line 848 of file value.h.
References as_sequence(), assert, ledger::downcast(), is_null(), is_sequence(), and VERIFY.
|
inline |
Definition at line 876 of file value.h.
References as_sequence(), as_sequence_lval(), ledger::downcast(), is_null(), is_sequence(), and VERIFY.
Referenced by ledger::call_scope_t::pop_back().
void ledger::value_t::print | ( | std::ostream & | out, |
const int | first_width = -1, | ||
const int | latter_width = -1, | ||
const uint_least8_t | flags = 0x00 ) const |
Printing methods.
Definition at line 868 of file value.h.
References as_sequence_lval(), ledger::downcast(), in_place_cast(), is_null(), is_sequence(), SEQUENCE, and value_t().
Referenced by ledger::call_scope_t::push_back().
Definition at line 860 of file value.h.
References as_sequence_lval(), ledger::downcast(), in_place_cast(), is_null(), is_sequence(), SEQUENCE, and value_t().
Referenced by ledger::call_scope_t::push_front().
|
inline |
Definition at line 466 of file value.h.
References ledger::downcast().
|
inline |
Definition at line 424 of file value.h.
References ledger::downcast().
Definition at line 431 of file value.h.
References ledger::downcast().
Definition at line 762 of file value.h.
References ANY, and ledger::downcast().
Definition at line 767 of file value.h.
References ANY, and ledger::downcast().
Definition at line 561 of file value.h.
References BOOLEAN, and ledger::downcast().
Referenced by value_t().
Definition at line 595 of file value.h.
References DATE, and ledger::downcast().
Referenced by value_t().
|
inline |
Definition at line 578 of file value.h.
References DATETIME, and ledger::downcast().
Referenced by value_t().
Definition at line 612 of file value.h.
References ledger::downcast(), and INTEGER.
Referenced by value_t().
Definition at line 694 of file value.h.
References ledger::downcast(), and MASK.
Definition at line 690 of file value.h.
References ledger::downcast(), and MASK.
Referenced by value_t().
Definition at line 726 of file value.h.
References ledger::downcast(), and SCOPE.
Referenced by value_t().
|
inline |
Definition at line 711 of file value.h.
References ledger::downcast(), and SEQUENCE.
Referenced by value_t().
Definition at line 670 of file value.h.
References ledger::downcast(), STRING, and VERIFY.
|
inline |
Definition at line 812 of file value.h.
References ledger::downcast(), and in_place_simplify().
|
inline |
Definition at line 913 of file value.h.
References as_sequence(), is_null(), and is_sequence().
Referenced by ledger::call_scope_t::empty(), empty(), ledger::call_scope_t::has(), ledger::call_scope_t::size(), and ledger::call_scope_t::value().
value_t ledger::value_t::strip_annotations | ( | const keep_details_t & | what_to_keep | ) | const |
amount_t ledger::value_t::to_amount | ( | ) | const |
balance_t ledger::value_t::to_balance | ( | ) | const |
bool ledger::value_t::to_boolean | ( | ) | const |
Data conversion methods.
These methods convert a value object to its underlying type, where possible. If not possible, an exception is thrown.
Referenced by ledger::call_scope_t::get().
date_t ledger::value_t::to_date | ( | ) | const |
datetime_t ledger::value_t::to_datetime | ( | ) | const |
int ledger::value_t::to_int | ( | ) | const |
long ledger::value_t::to_long | ( | ) | const |
Referenced by ledger::call_scope_t::get(), and to_size_t().
mask_t ledger::value_t::to_mask | ( | ) | const |
sequence_t ledger::value_t::to_sequence | ( | ) | const |
|
inline |
string ledger::value_t::to_string | ( | ) | const |
|
inline |
Definition at line 438 of file value.h.
References ledger::downcast().
|
inline |
|
inline |
Definition at line 473 of file value.h.
References ledger::downcast().
|
inline |
Definition at line 459 of file value.h.
References ledger::downcast().
bool ledger::value_t::valid | ( | ) | const |
Debugging methods.
value_t ledger::value_t::value | ( | const datetime_t & | moment = datetime_t(), |
const commodity_t * | in_terms_of = NULL ) const |