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, totally_ordered< value_t, commodity_t, addable< value_t, commodity_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 > > > > > > > > > >.
|
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
, COMMODITY
,
STRING
, MASK
, SEQUENCE
, SCOPE
,
ANY
} |
| type_t gives the type of the data contained or referenced by a value_t object. More...
|
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.
Definition at line 75 of file value.h.
◆ const_iterator
◆ difference_type
◆ iterator
◆ sequence_t
The sequence_t member type abstracts the type used to represent a resizable "array" of value_t objects.
Definition at line 92 of file value.h.
◆ type_t
type_t gives the type of the data contained or referenced by a value_t object.
Use the type() method to get a value of type type_t.
Enumerator |
---|
VOID | |
BOOLEAN | |
DATETIME | |
DATE | |
INTEGER | |
AMOUNT | |
BALANCE | |
COMMODITY | |
STRING | |
MASK | |
SEQUENCE | |
SCOPE | |
ANY | |
Definition at line 102 of file value.h.
◆ value_t() [1/16]
ledger::value_t::value_t |
( |
| ) |
|
|
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 278 of file value.h.
References TRACE_CTOR, and value_t().
Referenced by abs(), annotation(), casted(), ceilinged(), exchange_commodities(), floored(), is_equal_to(), is_greater_than(), is_less_than(), negated(), number(), operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), operator[](), operator[](), push_back(), push_front(), reduced(), rounded(), roundto(), simplified(), strip_annotations(), truncated(), unreduced(), unrounded(), value(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), value_t(), and ~value_t().
◆ value_t() [2/16]
ledger::value_t::value_t |
( |
const bool | val | ) |
|
|
inline |
◆ value_t() [3/16]
ledger::value_t::value_t |
( |
const datetime_t & | val | ) |
|
|
inline |
◆ value_t() [4/16]
ledger::value_t::value_t |
( |
const date_t & | val | ) |
|
|
inline |
◆ value_t() [5/16]
ledger::value_t::value_t |
( |
const long | val | ) |
|
|
inline |
◆ value_t() [6/16]
ledger::value_t::value_t |
( |
const unsigned long | val | ) |
|
|
inline |
◆ value_t() [7/16]
ledger::value_t::value_t |
( |
const double | val | ) |
|
|
inline |
◆ value_t() [8/16]
ledger::value_t::value_t |
( |
const amount_t & | val | ) |
|
|
inline |
◆ value_t() [9/16]
ledger::value_t::value_t |
( |
const balance_t & | val | ) |
|
|
inline |
◆ value_t() [10/16]
◆ value_t() [11/16]
ledger::value_t::value_t |
( |
const mask_t & | val | ) |
|
|
inline |
◆ value_t() [12/16]
ledger::value_t::value_t |
( |
const string & | val, |
|
|
bool | literal = false ) |
|
inlineexplicit |
◆ value_t() [13/16]
ledger::value_t::value_t |
( |
const char * | val, |
|
|
bool | literal = false ) |
|
inlineexplicit |
◆ value_t() [14/16]
ledger::value_t::value_t |
( |
const sequence_t & | val | ) |
|
|
inline |
◆ value_t() [15/16]
ledger::value_t::value_t |
( |
scope_t * | item | ) |
|
|
inlineexplicit |
◆ ~value_t()
ledger::value_t::~value_t |
( |
| ) |
|
|
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 364 of file value.h.
References TRACE_DTOR, and value_t().
◆ value_t() [16/16]
ledger::value_t::value_t |
( |
const value_t & | val | ) |
|
|
inline |
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 373 of file value.h.
References TRACE_CTOR, and value_t().
◆ abs()
value_t ledger::value_t::abs |
( |
| ) |
const |
◆ annotate()
void ledger::value_t::annotate |
( |
const annotation_t & | details | ) |
|
Annotated commodity methods.
◆ annotation() [1/2]
◆ annotation() [2/2]
◆ as_amount()
const amount_t & ledger::value_t::as_amount |
( |
| ) |
const |
|
inline |
◆ as_amount_lval()
amount_t & ledger::value_t::as_amount_lval |
( |
| ) |
|
|
inline |
◆ as_any() [1/2]
const boost::any & ledger::value_t::as_any |
( |
| ) |
const |
|
inline |
◆ as_any() [2/2]
template<typename T>
const T & ledger::value_t::as_any |
( |
| ) |
const |
|
inline |
◆ as_any_lval() [1/2]
boost::any & ledger::value_t::as_any_lval |
( |
| ) |
|
|
inline |
◆ as_any_lval() [2/2]
template<typename T>
T & ledger::value_t::as_any_lval |
( |
| ) |
|
|
inline |
◆ as_balance()
const balance_t & ledger::value_t::as_balance |
( |
| ) |
const |
|
inline |
◆ as_balance_lval()
balance_t & ledger::value_t::as_balance_lval |
( |
| ) |
|
|
inline |
◆ as_boolean()
const bool & ledger::value_t::as_boolean |
( |
| ) |
const |
|
inline |
◆ as_boolean_lval()
bool & ledger::value_t::as_boolean_lval |
( |
| ) |
|
|
inline |
◆ as_commodity()
const commodity_t & ledger::value_t::as_commodity |
( |
| ) |
const |
|
inline |
◆ as_date()
const date_t & ledger::value_t::as_date |
( |
| ) |
const |
|
inline |
◆ as_date_lval()
date_t & ledger::value_t::as_date_lval |
( |
| ) |
|
|
inline |
◆ as_datetime()
const datetime_t & ledger::value_t::as_datetime |
( |
| ) |
const |
|
inline |
◆ as_datetime_lval()
datetime_t & ledger::value_t::as_datetime_lval |
( |
| ) |
|
|
inline |
◆ as_long()
const long & ledger::value_t::as_long |
( |
| ) |
const |
|
inline |
◆ as_long_lval()
long & ledger::value_t::as_long_lval |
( |
| ) |
|
|
inline |
◆ as_mask()
const mask_t & ledger::value_t::as_mask |
( |
| ) |
const |
|
inline |
◆ as_mask_lval()
mask_t & ledger::value_t::as_mask_lval |
( |
| ) |
|
|
inline |
◆ as_scope()
scope_t * ledger::value_t::as_scope |
( |
| ) |
const |
|
inline |
◆ as_sequence()
const sequence_t & ledger::value_t::as_sequence |
( |
| ) |
const |
|
inline |
◆ as_sequence_lval()
sequence_t & ledger::value_t::as_sequence_lval |
( |
| ) |
|
|
inline |
◆ as_string()
const string & ledger::value_t::as_string |
( |
| ) |
const |
|
inline |
◆ as_string_lval()
string & ledger::value_t::as_string_lval |
( |
| ) |
|
|
inline |
◆ begin() [1/2]
sequence_t::iterator ledger::value_t::begin |
( |
| ) |
|
|
inline |
◆ begin() [2/2]
sequence_t::const_iterator ledger::value_t::begin |
( |
| ) |
const |
|
inline |
◆ casted()
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 824 of file value.h.
References in_place_cast(), and value_t().
◆ ceilinged()
value_t ledger::value_t::ceilinged |
( |
| ) |
const |
|
inline |
◆ dump()
void ledger::value_t::dump |
( |
std::ostream & | out, |
|
|
const bool | relaxed = true ) const |
◆ empty()
bool ledger::value_t::empty |
( |
| ) |
const |
|
inline |
◆ end() [1/2]
sequence_t::iterator ledger::value_t::end |
( |
| ) |
|
|
inline |
◆ end() [2/2]
sequence_t::const_iterator ledger::value_t::end |
( |
| ) |
const |
|
inline |
◆ exchange_commodities()
value_t ledger::value_t::exchange_commodities |
( |
const std::string & | commodities, |
|
|
const bool | add_prices = false, |
|
|
const datetime_t & | moment = datetime_t() ) |
◆ floored()
value_t ledger::value_t::floored |
( |
| ) |
const |
|
inline |
◆ has_annotation()
bool ledger::value_t::has_annotation |
( |
| ) |
const |
◆ in_place_cast()
void ledger::value_t::in_place_cast |
( |
type_t | cast_type | ) |
|
◆ in_place_ceiling()
void ledger::value_t::in_place_ceiling |
( |
| ) |
|
◆ in_place_floor()
void ledger::value_t::in_place_floor |
( |
| ) |
|
◆ in_place_negate()
void ledger::value_t::in_place_negate |
( |
| ) |
|
◆ in_place_not()
void ledger::value_t::in_place_not |
( |
| ) |
|
◆ in_place_reduce()
void ledger::value_t::in_place_reduce |
( |
| ) |
|
◆ in_place_round()
void ledger::value_t::in_place_round |
( |
| ) |
|
◆ in_place_roundto()
void ledger::value_t::in_place_roundto |
( |
int | places | ) |
|
◆ in_place_simplify()
void ledger::value_t::in_place_simplify |
( |
| ) |
|
◆ in_place_truncate()
void ledger::value_t::in_place_truncate |
( |
| ) |
|
◆ in_place_unreduce()
void ledger::value_t::in_place_unreduce |
( |
| ) |
|
◆ in_place_unround()
void ledger::value_t::in_place_unround |
( |
| ) |
|
◆ initialize()
void ledger::value_t::initialize |
( |
| ) |
|
|
static |
◆ is_amount()
bool ledger::value_t::is_amount |
( |
| ) |
const |
|
inline |
◆ is_any() [1/2]
bool ledger::value_t::is_any |
( |
| ) |
const |
|
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 755 of file value.h.
References ANY, and is_type().
Referenced by as_any(), as_any_lval(), and ledger::is_expr().
◆ is_any() [2/2]
template<typename T>
bool ledger::value_t::is_any |
( |
| ) |
const |
|
inline |
◆ is_balance()
bool ledger::value_t::is_balance |
( |
| ) |
const |
|
inline |
◆ is_boolean()
bool ledger::value_t::is_boolean |
( |
| ) |
const |
|
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 558 of file value.h.
References BOOLEAN, and is_type().
Referenced by as_boolean(), and as_boolean_lval().
◆ is_commodity()
bool ledger::value_t::is_commodity |
( |
| ) |
const |
|
inline |
◆ is_date()
bool ledger::value_t::is_date |
( |
| ) |
const |
|
inline |
◆ is_datetime()
bool ledger::value_t::is_datetime |
( |
| ) |
const |
|
inline |
◆ is_equal_to()
bool ledger::value_t::is_equal_to |
( |
const value_t & | val | ) |
const |
Comparison operators.
Values can be compared to other values
References value_t().
Referenced by operator==().
◆ is_greater_than()
bool ledger::value_t::is_greater_than |
( |
const value_t & | val | ) |
const |
◆ is_less_than()
bool ledger::value_t::is_less_than |
( |
const value_t & | val | ) |
const |
◆ is_long()
bool ledger::value_t::is_long |
( |
| ) |
const |
|
inline |
◆ is_mask()
bool ledger::value_t::is_mask |
( |
| ) |
const |
|
inline |
◆ is_nonzero()
bool ledger::value_t::is_nonzero |
( |
| ) |
const |
|
inline |
◆ is_null()
bool ledger::value_t::is_null |
( |
| ) |
const |
|
inline |
◆ is_realzero()
bool ledger::value_t::is_realzero |
( |
| ) |
const |
◆ is_scope()
bool ledger::value_t::is_scope |
( |
| ) |
const |
|
inline |
◆ is_sequence()
bool ledger::value_t::is_sequence |
( |
| ) |
const |
|
inline |
Definition at line 717 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().
◆ is_string()
bool ledger::value_t::is_string |
( |
| ) |
const |
|
inline |
◆ is_type()
bool ledger::value_t::is_type |
( |
type_t | _type | ) |
const |
|
inline |
Definition at line 521 of file value.h.
References type().
Referenced by is_amount(), is_any(), is_balance(), is_boolean(), is_commodity(), is_date(), is_datetime(), is_long(), is_mask(), is_null(), is_scope(), is_sequence(), and is_string().
◆ is_zero()
bool ledger::value_t::is_zero |
( |
| ) |
const |
◆ label()
string ledger::value_t::label |
( |
optional< type_t > | the_type = none | ) |
const |
◆ negated()
value_t ledger::value_t::negated |
( |
| ) |
const |
|
inline |
◆ number()
value_t ledger::value_t::number |
( |
| ) |
const |
◆ operator bool()
ledger::value_t::operator bool |
( |
| ) |
const |
◆ operator*=()
◆ operator+=()
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.
References value_t().
◆ operator-()
value_t ledger::value_t::operator- |
( |
| ) |
const |
|
inline |
◆ operator-=()
◆ operator/=()
◆ operator<()
template<typename T>
bool ledger::value_t::operator< |
( |
const T & | amt | ) |
const |
|
inline |
◆ operator=()
◆ operator==()
template<typename T>
bool ledger::value_t::operator== |
( |
const T & | amt | ) |
const |
|
inline |
◆ operator>()
template<typename T>
bool ledger::value_t::operator> |
( |
const T & | amt | ) |
const |
|
inline |
◆ operator[]() [1/2]
value_t & ledger::value_t::operator[] |
( |
const std::size_t | index | ) |
|
|
inline |
◆ operator[]() [2/2]
const value_t & ledger::value_t::operator[] |
( |
const std::size_t | index | ) |
const |
|
inline |
◆ pop_back()
void ledger::value_t::pop_back |
( |
| ) |
|
|
inline |
◆ print()
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 |
◆ push_back()
void ledger::value_t::push_back |
( |
const value_t & | val | ) |
|
|
inline |
◆ push_front()
void ledger::value_t::push_front |
( |
const value_t & | val | ) |
|
|
inline |
◆ reduced()
value_t ledger::value_t::reduced |
( |
| ) |
const |
|
inline |
◆ rounded()
value_t ledger::value_t::rounded |
( |
| ) |
const |
|
inline |
◆ roundto()
value_t ledger::value_t::roundto |
( |
int | places | ) |
const |
|
inline |
◆ set_amount()
void ledger::value_t::set_amount |
( |
const amount_t & | val | ) |
|
|
inline |
◆ set_any() [1/2]
void ledger::value_t::set_any |
( |
const boost::any & | val | ) |
|
|
inline |
◆ set_any() [2/2]
template<typename T>
void ledger::value_t::set_any |
( |
T & | val | ) |
|
|
inline |
◆ set_balance()
void ledger::value_t::set_balance |
( |
const balance_t & | val | ) |
|
|
inline |
◆ set_boolean()
void ledger::value_t::set_boolean |
( |
const bool | val | ) |
|
|
inline |
◆ set_commodity()
void ledger::value_t::set_commodity |
( |
const commodity_t & | val | ) |
|
◆ set_date()
void ledger::value_t::set_date |
( |
const date_t & | val | ) |
|
|
inline |
◆ set_datetime()
void ledger::value_t::set_datetime |
( |
const datetime_t & | val | ) |
|
|
inline |
◆ set_long()
void ledger::value_t::set_long |
( |
const long | val | ) |
|
|
inline |
◆ set_mask() [1/2]
void ledger::value_t::set_mask |
( |
const mask_t & | val | ) |
|
|
inline |
◆ set_mask() [2/2]
void ledger::value_t::set_mask |
( |
const string & | val | ) |
|
|
inline |
◆ set_scope()
void ledger::value_t::set_scope |
( |
scope_t * | val | ) |
|
|
inline |
◆ set_sequence()
void ledger::value_t::set_sequence |
( |
const sequence_t & | val | ) |
|
|
inline |
◆ set_string() [1/2]
void ledger::value_t::set_string |
( |
const char * | val = "" | ) |
|
|
inline |
◆ set_string() [2/2]
void ledger::value_t::set_string |
( |
const string & | val = "" | ) |
|
|
inline |
◆ shutdown()
void ledger::value_t::shutdown |
( |
| ) |
|
|
static |
◆ simplified()
value_t ledger::value_t::simplified |
( |
| ) |
const |
|
inline |
◆ size()
std::size_t ledger::value_t::size |
( |
| ) |
const |
|
inline |
◆ strip_annotations()
◆ to_amount()
amount_t ledger::value_t::to_amount |
( |
| ) |
const |
◆ to_balance()
balance_t ledger::value_t::to_balance |
( |
| ) |
const |
◆ to_boolean()
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().
◆ to_commodity()
const commodity_t & ledger::value_t::to_commodity |
( |
| ) |
const |
◆ to_date()
date_t ledger::value_t::to_date |
( |
| ) |
const |
◆ to_datetime()
◆ to_int()
int ledger::value_t::to_int |
( |
| ) |
const |
◆ to_long()
long ledger::value_t::to_long |
( |
| ) |
const |
◆ to_mask()
mask_t ledger::value_t::to_mask |
( |
| ) |
const |
◆ to_sequence()
◆ to_size_t()
std::size_t ledger::value_t::to_size_t |
( |
| ) |
const |
|
inline |
◆ to_string()
string ledger::value_t::to_string |
( |
| ) |
const |
◆ truncated()
value_t ledger::value_t::truncated |
( |
| ) |
const |
|
inline |
◆ type()
type_t ledger::value_t::type |
( |
| ) |
const |
|
inline |
◆ unreduced()
value_t ledger::value_t::unreduced |
( |
| ) |
const |
|
inline |
◆ unrounded()
value_t ledger::value_t::unrounded |
( |
| ) |
const |
|
inline |
◆ valid()
bool ledger::value_t::valid |
( |
| ) |
const |
◆ value()
The documentation for this class was generated from the following file: