Loading...
Searching...
No Matches
value.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2023, John Wiegley. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of New Artisans LLC nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
49#pragma once
50
51#include "balance.h" // includes amount.h
52#include "mask.h"
53
54namespace ledger {
55
56DECLARE_EXCEPTION(value_error, std::runtime_error);
57
58class scope_t;
59
75 : public ordered_field_operators<value_t,
76 equality_comparable<value_t, balance_t,
77 additive<value_t, balance_t,
78 multiplicative<value_t, balance_t,
79 ordered_field_operators<value_t, amount_t,
80 ordered_field_operators<value_t, double,
81 ordered_field_operators<value_t, unsigned long,
82 ordered_field_operators<value_t, long> > > > > > > >
83{
84public:
90 typedef sequence_t::iterator iterator;
91 typedef sequence_t::const_iterator const_iterator;
92 typedef sequence_t::difference_type difference_type;
93
99 enum type_t {
100 VOID, // a null value (i.e., uninitialized)
101 BOOLEAN, // a boolean
102 DATETIME, // a date and time (Boost posix_time)
103 DATE, // a date (Boost gregorian::date)
104 INTEGER, // a signed integer value
105 AMOUNT, // a ledger::amount_t
106 BALANCE, // a ledger::balance_t
107 STRING, // a string object
108 MASK, // a regular expression mask
109 SEQUENCE, // a vector of value_t objects
110 SCOPE, // a pointer to a scope
111 ANY // a pointer to an arbitrary object
112 };
113
115 {
116 friend class value_t;
117
128 variant<bool, // BOOLEAN
129 datetime_t, // DATETIME
130 date_t, // DATE
131 long, // INTEGER
132 amount_t, // AMOUNT
133 balance_t *, // BALANCE
134 string, // STRING
135 mask_t, // MASK
136 sequence_t *, // SEQUENCE
137 scope_t *, // SCOPE
138 boost::any // ANY
139 > data;
140
141 type_t type;
142
147 mutable int refc;
148
156 explicit storage_t() : type(VOID), refc(0) {
158 }
159
160 public: // so `checked_delete' can access it
170 VERIFY(refc == 0);
171 destroy();
172 }
173
174 private:
179 explicit storage_t(const storage_t& rhs)
180 : type(rhs.type), refc(0) {
181 *this = rhs;
183 }
184 storage_t& operator=(const storage_t& rhs);
185
191 void acquire() const {
192 DEBUG("value.storage.refcount",
193 "Acquiring " << this << ", refc now " << refc + 1);
194 VERIFY(refc >= 0);
195 refc++;
196 }
197 void release() const {
198 DEBUG("value.storage.refcount",
199 "Releasing " << this << ", refc now " << refc - 1);
200 VERIFY(refc > 0);
201 if (--refc == 0)
202 checked_delete(this);
203 }
204
206 storage_ptr->acquire();
207 }
209 storage_ptr->release();
210 }
211
212 void destroy() {
213 DEBUG("value.storage.refcount", "Destroying " << this);
214 switch (type) {
215 case VOID:
216 return;
217 case BALANCE:
218 checked_delete(boost::get<balance_t *>(data));
219 break;
220 case SEQUENCE:
221 checked_delete(boost::get<sequence_t *>(data));
222 break;
223 default:
224 break;
225 }
226 data = false;
227 type = VOID;
228 }
229 };
230
231private:
237
242 void _dup() {
243 if (storage && storage->refc > 1)
244 storage = new storage_t(*storage.get());
245 }
246
252 static intrusive_ptr<storage_t> true_value;
253 static intrusive_ptr<storage_t> false_value;
254
255public:
256 static void initialize();
257 static void shutdown();
258
259public:
274 TRACE_CTOR(value_t, "");
275 }
276
277 value_t(const bool val) {
279 TRACE_CTOR(value_t, "const bool");
280 }
281
284 TRACE_CTOR(value_t, "const datetime_t&");
285 }
287 set_date(val);
288 TRACE_CTOR(value_t, "const date_t&");
289 }
290
291 value_t(const long val) {
292 set_long(val);
293 TRACE_CTOR(value_t, "const long");
294 }
295 value_t(const unsigned long val) {
297 TRACE_CTOR(value_t, "const unsigned long");
298 }
299 value_t(const double val) {
301 TRACE_CTOR(value_t, "const double");
302 }
305 TRACE_CTOR(value_t, "const amount_t&");
306 }
309 TRACE_CTOR(value_t, "const balance_t&");
310 }
312 set_mask(val);
313 TRACE_CTOR(value_t, "const mask_t&");
314 }
315
316 explicit value_t(const string& val, bool literal = false) {
317 if (literal)
319 else
321
322 TRACE_CTOR(value_t, "const string&, bool");
323 }
324 explicit value_t(const char * val, bool literal = false) {
325 if (literal)
327 else
329
330 TRACE_CTOR(value_t, "const char *");
331 }
332
335 TRACE_CTOR(value_t, "const sequence_t&");
336 }
337
338 explicit value_t(scope_t * item) {
340 TRACE_CTOR(value_t, "scope_t *");
341 }
342#if 0
343 template <typename T>
344 explicit value_t(T& item) {
345 set_any(item);
346 TRACE_CTOR(value_t, "T&");
347 }
348#endif
349
357 }
358
365 *this = val;
366 TRACE_CTOR(value_t, "copy");
367 }
369 if (! (this == &val || storage == val.storage))
370 storage = val.storage;
371 return *this;
372 }
373
377 bool is_equal_to(const value_t& val) const;
378 bool is_less_than(const value_t& val) const;
379 bool is_greater_than(const value_t& val) const;
380
381 template <typename T>
382 bool operator==(const T& amt) const {
383 return is_equal_to(amt);
384 }
385 template <typename T>
386 bool operator<(const T& amt) const {
387 return is_less_than(amt);
388 }
389 template <typename T>
390 bool operator>(const T& amt) const {
391 return is_greater_than(amt);
392 }
393
406
410 value_t negated() const {
411 value_t temp = *this;
413 return temp;
414 }
415 void in_place_negate(); // exists for efficiency's sake
416 void in_place_not(); // exists for efficiency's sake
417
419 return negated();
420 }
421
422 value_t abs() const;
423
424 value_t rounded() const {
425 value_t temp(*this);
426 temp.in_place_round();
427 return temp;
428 }
430
431 value_t roundto(int places) const {
432 value_t temp(*this);
433 temp.in_place_roundto(places);
434 return temp;
435 }
437
439 value_t temp(*this);
440 temp.in_place_truncate();
441 return temp;
442 }
444
445 value_t floored() const {
446 value_t temp(*this);
447 temp.in_place_floor();
448 return temp;
449 }
451
453 value_t temp(*this);
454 temp.in_place_ceiling();
455 return temp;
456 }
458
460 value_t temp(*this);
461 temp.in_place_unround();
462 return temp;
463 }
465
466 value_t reduced() const {
467 value_t temp(*this);
468 temp.in_place_reduce();
469 return temp;
470 }
471 void in_place_reduce(); // exists for efficiency's sake
472
474 value_t temp(*this);
475 temp.in_place_unreduce();
476 return temp;
477 }
478 void in_place_unreduce(); // exists for efficiency's sake
479
480 // Return the "market value" of a given value at a specific time.
482 const commodity_t * in_terms_of = NULL) const;
483
484 value_t exchange_commodities(const std::string& commodities,
485 const bool add_prices = false,
486 const datetime_t& moment = datetime_t());
487
491 operator bool() const;
492
493 bool is_nonzero() const {
494 return ! is_zero();
495 }
496
497 bool is_realzero() const;
498 bool is_zero() const;
499 bool is_null() const {
500 if (! storage) {
502 return true;
503 } else {
504 VERIFY(! is_type(VOID));
505 return false;
506 }
507 }
508
509 type_t type() const {
510 return storage ? storage->type : VOID;
511 }
512 bool is_type(type_t _type) const {
513 return type() == _type;
514 }
515
516private:
517 void set_type(type_t new_type);
518
519public:
549 bool is_boolean() const {
550 return is_type(BOOLEAN);
551 }
554 _dup();
555 return boost::get<bool>(storage->data);
556 }
557 const bool& as_boolean() const {
559 return boost::get<bool>(storage->data);
560 }
561 void set_boolean(const bool val) {
562 set_type(BOOLEAN);
563 storage = val ? true_value : false_value;
564 }
565
566 bool is_datetime() const {
567 return is_type(DATETIME);
568 }
571 _dup();
572 return boost::get<datetime_t>(storage->data);
573 }
574 const datetime_t& as_datetime() const {
576 return boost::get<datetime_t>(storage->data);
577 }
579 set_type(DATETIME);
580 storage->data = val;
581 }
582
583 bool is_date() const {
584 return is_type(DATE);
585 }
587 VERIFY(is_date());
588 _dup();
589 return boost::get<date_t>(storage->data);
590 }
591 const date_t& as_date() const {
592 VERIFY(is_date());
593 return boost::get<date_t>(storage->data);
594 }
595 void set_date(const date_t& val) {
596 set_type(DATE);
597 storage->data = val;
598 }
599
600 bool is_long() const {
601 return is_type(INTEGER);
602 }
603 long& as_long_lval() {
604 VERIFY(is_long());
605 _dup();
606 return boost::get<long>(storage->data);
607 }
608 const long& as_long() const {
609 VERIFY(is_long());
610 return boost::get<long>(storage->data);
611 }
612 void set_long(const long val) {
613 set_type(INTEGER);
614 storage->data = val;
615 }
616
617 bool is_amount() const {
618 return is_type(AMOUNT);
619 }
621 VERIFY(is_amount());
622 _dup();
623 return boost::get<amount_t>(storage->data);
624 }
625 const amount_t& as_amount() const {
626 VERIFY(is_amount());
627 return boost::get<amount_t>(storage->data);
628 }
629 void set_amount(const amount_t& val) {
630 VERIFY(val.valid());
631 set_type(AMOUNT);
632 storage->data = val;
633 }
634
635 bool is_balance() const {
636 return is_type(BALANCE);
637 }
640 _dup();
641 return *boost::get<balance_t *>(storage->data);
642 }
643 const balance_t& as_balance() const {
645 return *boost::get<balance_t *>(storage->data);
646 }
647 void set_balance(const balance_t& val) {
648 VERIFY(val.valid());
649 set_type(BALANCE);
650 storage->data = new balance_t(val);
651 }
652
653 bool is_string() const {
654 return is_type(STRING);
655 }
656 string& as_string_lval() {
657 VERIFY(is_string());
658 _dup();
659 return boost::get<string>(storage->data);
660 }
661 const string& as_string() const {
662 VERIFY(is_string());
663 return boost::get<string>(storage->data);
664 }
665 void set_string(const string& val = "") {
666 set_type(STRING);
667 storage->data = val;
668 VERIFY(boost::get<string>(storage->data) == val);
669 }
670 void set_string(const char * val = "") {
671 set_type(STRING);
672 storage->data = string(val);
673 VERIFY(boost::get<string>(storage->data) == val);
674 }
675
676 bool is_mask() const {
677 return is_type(MASK);
678 }
680 VERIFY(is_mask());
681 _dup();
682 VERIFY(boost::get<mask_t>(storage->data).valid());
683 return boost::get<mask_t>(storage->data);
684 }
685 const mask_t& as_mask() const {
686 VERIFY(is_mask());
687 VERIFY(boost::get<mask_t>(storage->data).valid());
688 return boost::get<mask_t>(storage->data);
689 }
690 void set_mask(const string& val) {
691 set_type(MASK);
692 storage->data = mask_t(val);
693 }
694 void set_mask(const mask_t& val) {
695 set_type(MASK);
696 storage->data = val;
697 }
698
699 bool is_sequence() const {
700 return is_type(SEQUENCE);
701 }
704 _dup();
705 return *boost::get<sequence_t *>(storage->data);
706 }
707 const sequence_t& as_sequence() const {
709 return *boost::get<sequence_t *>(storage->data);
710 }
712 set_type(SEQUENCE);
713 storage->data = new sequence_t(val);
714 }
715
719 bool is_scope() const {
720 return is_type(SCOPE);
721 }
722 scope_t * as_scope() const {
723 VERIFY(is_scope());
724 return boost::get<scope_t *>(storage->data);
725 }
727 set_type(SCOPE);
728 storage->data = val;
729 }
730
737 bool is_any() const {
738 return is_type(ANY);
739 }
740 template <typename T>
741 bool is_any() const {
742 return (is_type(ANY) &&
743 boost::get<boost::any>(storage->data).type() == typeid(T));
744 }
745 boost::any& as_any_lval() {
746 VERIFY(is_any());
747 _dup();
748 return boost::get<boost::any>(storage->data);
749 }
750 template <typename T>
752 return any_cast<T&>(as_any_lval());
753 }
754 const boost::any& as_any() const {
755 VERIFY(is_any());
756 return boost::get<boost::any>(storage->data);
757 }
758 template <typename T>
759 const T& as_any() const {
760 return any_cast<const T&>(as_any());
761 }
762 void set_any(const boost::any& val) {
763 set_type(ANY);
764 storage->data = val;
765 }
766 template <typename T>
767 void set_any(T& val) {
768 set_type(ANY);
769 storage->data = boost::any(val);
770 }
771
777 bool to_boolean() const;
778 int to_int() const;
779 long to_long() const;
780 std::size_t to_size_t() const { return static_cast<std::size_t>(to_long()); }
785 string to_string() const;
788
806 value_t temp(*this);
807 temp.in_place_cast(cast_type);
808 return temp;
809 }
811
813 value_t temp = *this;
815 return temp;
816 }
818
820
824 void annotate(const annotation_t& details);
825 bool has_annotation() const;
826
828 const annotation_t& annotation() const {
829 return const_cast<value_t&>(*this).annotation();
830 }
831
832 value_t strip_annotations(const keep_details_t& what_to_keep) const;
833
837 value_t& operator[](const std::size_t index) {
838 VERIFY(! is_null());
839 if (is_sequence())
840 return as_sequence_lval()[index];
841 else if (index == 0)
842 return *this;
843
844 assert(false);
845 static value_t null;
846 return null;
847 }
848 const value_t& operator[](const std::size_t index) const {
849 VERIFY(! is_null());
850 if (is_sequence())
851 return as_sequence()[index];
852 else if (index == 0)
853 return *this;
854
855 assert(false);
856 static value_t null;
857 return null;
858 }
859
860 void push_front(const value_t& val) {
861 if (is_null())
862 *this = sequence_t();
863 if (! is_sequence())
865 as_sequence_lval().push_front(new value_t(val));
866 }
867
868 void push_back(const value_t& val) {
869 if (is_null())
870 *this = sequence_t();
871 if (! is_sequence())
873 as_sequence_lval().push_back(new value_t(val));
874 }
875
876 void pop_back() {
877 VERIFY(! is_null());
878
879 if (! is_sequence()) {
880 storage.reset();
881 } else {
882 as_sequence_lval().pop_back();
883
884 const sequence_t& seq(as_sequence());
885 std::size_t new_size = seq.size();
886 if (new_size == 0) {
887 storage.reset();
888 }
889 else if (new_size == 1) {
890 *this = seq.front();
891 }
892 }
893 }
894
895 sequence_t::iterator begin() {
897 return as_sequence_lval().begin();
898 }
899 sequence_t::iterator end() {
901 return as_sequence_lval().end();
902 }
903
904 sequence_t::const_iterator begin() const {
906 return as_sequence().begin();
907 }
908 sequence_t::const_iterator end() const {
910 return as_sequence().end();
911 }
912
913 std::size_t size() const {
914 if (is_null())
915 return 0;
916 else if (is_sequence())
917 return as_sequence().size();
918 else
919 return 1;
920 }
921
922 bool empty() const {
923 return size() == 0;
924 }
925
930
934 void print(std::ostream& out,
935 const int first_width = -1,
936 const int latter_width = -1,
937 const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
938
939 void dump(std::ostream& out, const bool relaxed = true) const;
940
944 bool valid() const;
945};
946
947#define NULL_VALUE (value_t())
948
949inline value_t string_value(const string& str = "") {
950 return value_t(str, true);
951}
952
953#define VALUE_OR_ZERO(val) ((val).is_null() ? value_t(0L) : (val))
954#define SIMPLIFIED_VALUE_OR_ZERO(val) \
955 ((val).is_null() ? value_t(0L) : (val).simplified())
956
957inline value_t mask_value(const string& str) {
958 return value_t(mask_t(str));
959}
960
961inline std::ostream& operator<<(std::ostream& out, const value_t& val) {
962 val.print(out);
963 return out;
964}
965
966inline string value_context(const value_t& val) {
967 std::ostringstream buf;
968 val.print(buf, 20, 20, true);
969 return buf.str();
970}
971
973 return value_t(val);
974}
975
976template <typename T>
978 if (lhs.is_null())
979 lhs = rhs;
980 else
981 lhs += rhs;
982 return lhs;
983}
984
992
993bool sort_value_is_less_than(const std::list<sort_value_t>& left_values,
994 const std::list<sort_value_t>& right_values);
995
996void put_value(property_tree::ptree& pt, const value_t& value);
997
998} // namespace ledger
#define VERIFY(x)
Definition utils.h:141
#define TRACE_DTOR(cls)
Definition utils.h:144
#define TRACE_CTOR(cls, args)
Definition utils.h:143
#define DEBUG(cat, msg)
Definition utils.h:327
#define assert(x)
Definition utils.h:92
Regular expression masking.
#define AMOUNT_PRINT_NO_FLAGS
An amount may be output to a stream using the ‘print’ method.
Definition amount.h:711
#define DECLARE_EXCEPTION(name, kind)
Definition error.h:88
Basic type for adding multiple commodities together.
void put_value(property_tree::ptree &pt, const value_t &value)
value_t mask_value(const string &str)
Definition value.h:957
boost::gregorian::date date_t
Definition times.h:60
value_t string_value(const string &str="")
Definition value.h:949
std::string string
Definition utils.h:59
std::ostream & operator<<(std::ostream &out, const account_t &account)
T & downcast(U &object)
Definition utils.h:468
value_t scope_value(scope_t *val)
Definition value.h:972
boost::posix_time::ptime datetime_t
Definition times.h:53
value_t & add_or_set_value(value_t &lhs, const T &rhs)
Definition value.h:977
bool sort_value_is_less_than(const std::list< sort_value_t > &left_values, const std::list< sort_value_t > &right_values)
string value_context(const value_t &val)
Definition value.h:966
Encapsulate infinite-precision commoditized amounts.
Definition amount.h:96
A wrapper around amount_t allowing addition of multiple commodities.
Definition balance.h:80
Dynamic type representing various numeric types.
Definition value.h:83
value_t()
Constructors.
Definition value.h:273
bool is_amount() const
Definition value.h:617
const value_t & operator[](const std::size_t index) const
Definition value.h:848
void set_boolean(const bool val)
Definition value.h:561
value_t(const bool val)
Definition value.h:277
value_t & operator-=(const value_t &val)
value_t floored() const
Definition value.h:445
value_t(const long val)
Definition value.h:291
void print(std::ostream &out, const int first_width=-1, const int latter_width=-1, const uint_least8_t flags=0x00) const
Printing methods.
bool is_mask() const
Definition value.h:676
value_t strip_annotations(const keep_details_t &what_to_keep) const
value_t(const string &val, bool literal=false)
Definition value.h:316
const boost::any & as_any() const
Definition value.h:754
value_t(const double val)
Definition value.h:299
string label(optional< type_t > the_type=none) const
Informational methods.
bool & as_boolean_lval()
Definition value.h:552
void in_place_truncate()
const datetime_t & as_datetime() const
Definition value.h:574
string & as_string_lval()
Definition value.h:656
value_t casted(type_t cast_type) const
Dynamic typing conversion methods.
Definition value.h:805
type_t type() const
Definition value.h:509
void in_place_simplify()
void in_place_floor()
amount_t & as_amount_lval()
Definition value.h:620
void in_place_unreduce()
const date_t & as_date() const
Definition value.h:591
sequence_t to_sequence() const
void pop_back()
Definition value.h:876
value_t number() const
value_t(const date_t &val)
Definition value.h:286
const annotation_t & annotation() const
Definition value.h:828
datetime_t & as_datetime_lval()
Definition value.h:569
void set_mask(const string &val)
Definition value.h:690
annotation_t & annotation()
bool is_null() const
Definition value.h:499
bool is_string() const
Definition value.h:653
void in_place_negate()
sequence_t::iterator end()
Definition value.h:899
bool is_less_than(const value_t &val) const
mask_t to_mask() const
void set_long(const long val)
Definition value.h:612
bool is_scope() const
Dealing with scope pointers.
Definition value.h:719
void set_any(T &val)
Definition value.h:767
mask_t & as_mask_lval()
Definition value.h:679
scope_t * as_scope() const
Definition value.h:722
const long & as_long() const
Definition value.h:608
const balance_t & as_balance() const
Definition value.h:643
const mask_t & as_mask() const
Definition value.h:685
int to_int() const
sequence_t::iterator iterator
Definition value.h:90
bool is_realzero() const
sequence_t::const_iterator begin() const
Definition value.h:904
void set_datetime(const datetime_t &val)
Definition value.h:578
void set_string(const char *val="")
Definition value.h:670
bool operator==(const T &amt) const
Definition value.h:382
std::size_t to_size_t() const
Definition value.h:780
bool is_long() const
Definition value.h:600
bool empty() const
Definition value.h:922
value_t & operator+=(const value_t &val)
Binary arithmetic operators.
void push_back(const value_t &val)
Definition value.h:868
value_t operator-() const
Definition value.h:418
value_t ceilinged() const
Definition value.h:452
bool is_any() const
Definition value.h:741
const string & as_string() const
Definition value.h:661
bool is_balance() const
Definition value.h:635
void in_place_ceiling()
sequence_t & as_sequence_lval()
Definition value.h:702
void set_scope(scope_t *val)
Definition value.h:726
std::size_t size() const
Definition value.h:913
void set_date(const date_t &val)
Definition value.h:595
date_t to_date() const
void set_balance(const balance_t &val)
Definition value.h:647
long & as_long_lval()
Definition value.h:603
sequence_t::const_iterator end() const
Definition value.h:908
~value_t()
Destructor.
Definition value.h:355
bool operator<(const T &amt) const
Definition value.h:386
value_t rounded() const
Definition value.h:424
boost::any & as_any_lval()
Definition value.h:745
long to_long() const
void in_place_unround()
bool is_boolean() const
Data manipulation methods.
Definition value.h:549
type_t
type_t gives the type of the data contained or referenced by a value_t object.
Definition value.h:99
datetime_t to_datetime() const
bool is_type(type_t _type) const
Definition value.h:512
value_t & operator[](const std::size_t index)
Collection-style access methods for SEQUENCE values.
Definition value.h:837
value_t(const datetime_t &val)
Definition value.h:282
bool is_equal_to(const value_t &val) const
Comparison operators.
const amount_t & as_amount() const
Definition value.h:625
bool is_sequence() const
Definition value.h:699
void set_any(const boost::any &val)
Definition value.h:762
value_t value(const datetime_t &moment=datetime_t(), const commodity_t *in_terms_of=NULL) const
const sequence_t & as_sequence() const
Definition value.h:707
sequence_t::iterator begin()
Definition value.h:895
void set_sequence(const sequence_t &val)
Definition value.h:711
bool is_any() const
Dealing with any type at all is bit involved because we actually deal with typed object.
Definition value.h:737
value_t simplified() const
Definition value.h:812
bool is_nonzero() const
Definition value.h:493
value_t & operator/=(const value_t &val)
void in_place_roundto(int places)
balance_t & as_balance_lval()
Definition value.h:638
value_t(scope_t *item)
Definition value.h:338
void annotate(const annotation_t &details)
Annotated commodity methods.
balance_t to_balance() const
value_t negated() const
Unary arithmetic operators.
Definition value.h:410
value_t & operator=(const value_t &val)
Definition value.h:368
date_t & as_date_lval()
Definition value.h:586
amount_t to_amount() const
T & as_any_lval()
Definition value.h:751
void push_front(const value_t &val)
Definition value.h:860
bool has_annotation() const
bool is_greater_than(const value_t &val) const
bool valid() const
Debugging methods.
void set_amount(const amount_t &val)
Definition value.h:629
bool is_datetime() const
Definition value.h:566
const bool & as_boolean() const
Definition value.h:557
value_t(const char *val, bool literal=false)
Definition value.h:324
value_t(const mask_t &val)
Definition value.h:311
void set_mask(const mask_t &val)
Definition value.h:694
static void initialize()
bool operator>(const T &amt) const
Definition value.h:390
bool is_zero() const
value_t(const amount_t &val)
Definition value.h:303
bool is_date() const
Definition value.h:583
static void shutdown()
value_t(const unsigned long val)
Definition value.h:295
sequence_t::difference_type difference_type
Definition value.h:92
void in_place_cast(type_t cast_type)
value_t(const sequence_t &val)
Definition value.h:333
const T & as_any() const
Definition value.h:759
value_t exchange_commodities(const std::string &commodities, const bool add_prices=false, const datetime_t &moment=datetime_t())
string to_string() const
value_t reduced() const
Definition value.h:466
void dump(std::ostream &out, const bool relaxed=true) const
value_t(const balance_t &val)
Definition value.h:307
sequence_t::const_iterator const_iterator
Definition value.h:91
ptr_deque< value_t > sequence_t
The sequence_t member type abstracts the type used to represent a resizable "array" of value_t object...
Definition value.h:89
value_t(const value_t &val)
Assignment and copy operators.
Definition value.h:364
value_t truncated() const
Definition value.h:438
void set_string(const string &val="")
Definition value.h:665
bool to_boolean() const
Data conversion methods.
value_t unrounded() const
Definition value.h:459
value_t roundto(int places) const
Definition value.h:431
value_t unreduced() const
Definition value.h:473
void in_place_reduce()
value_t & operator*=(const value_t &val)
value_t abs() const
void in_place_round()
friend void intrusive_ptr_add_ref(value_t::storage_t *storage_ptr)
Definition value.h:205
~storage_t()
Destructor.
Definition value.h:168
friend void intrusive_ptr_release(value_t::storage_t *storage_ptr)
Definition value.h:208