Loading...
Searching...
No Matches
value.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2025, 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
35
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 commodity_t;
59class scope_t;
60
76 : public ordered_field_operators<value_t,
77 equality_comparable<value_t, balance_t,
78 additive<value_t, balance_t,
79 multiplicative<value_t, balance_t,
80 totally_ordered<value_t, commodity_t,
81 addable<value_t, commodity_t,
82 ordered_field_operators<value_t, amount_t,
83 ordered_field_operators<value_t, double,
84 ordered_field_operators<value_t, unsigned long,
85 ordered_field_operators<value_t, long> > > > > > > > > >
86{
87public:
92 typedef ptr_deque<value_t> sequence_t;
93 typedef sequence_t::iterator iterator;
94 typedef sequence_t::const_iterator const_iterator;
95 typedef sequence_t::difference_type difference_type;
96
102 enum type_t {
103 VOID, // a null value (i.e., uninitialized)
104 BOOLEAN, // a boolean
105 DATETIME, // a date and time (Boost posix_time)
106 DATE, // a date (Boost gregorian::date)
107 INTEGER, // a signed integer value
108 AMOUNT, // a ledger::amount_t
109 BALANCE, // a ledger::balance_t
110 COMMODITY, // a ledger::commodity_t
111 STRING, // a string object
112 MASK, // a regular expression mask
113 SEQUENCE, // a vector of value_t objects
114 SCOPE, // a pointer to a scope
115 ANY // a pointer to an arbitrary object
116 };
117
118 class storage_t
119 {
120 friend class value_t;
121
132 variant<bool, // BOOLEAN
133 datetime_t, // DATETIME
134 date_t, // DATE
135 long, // INTEGER
136 amount_t, // AMOUNT
137 balance_t *, // BALANCE
138 commodity_t const *, // COMMODITY
139 string, // STRING
140 mask_t, // MASK
141 sequence_t *, // SEQUENCE
142 scope_t *, // SCOPE
143 boost::any // ANY
144 > data;
145
146 type_t type;
147
152 mutable int refc;
153
161 explicit storage_t() : type(VOID), refc(0) {
163 }
164
165 public: // so `checked_delete' can access it
175 VERIFY(refc == 0);
176 destroy();
177 }
178
179 private:
184 explicit storage_t(const storage_t& rhs)
185 : type(rhs.type), refc(0) {
186 *this = rhs;
188 }
189 storage_t& operator=(const storage_t& rhs);
190
196 void acquire() const {
197 DEBUG("value.storage.refcount",
198 "Acquiring " << this << ", refc now " << refc + 1);
199 VERIFY(refc >= 0);
200 refc++;
201 }
202 void release() const {
203 DEBUG("value.storage.refcount",
204 "Releasing " << this << ", refc now " << refc - 1);
205 VERIFY(refc > 0);
206 if (--refc == 0)
207 checked_delete(this);
208 }
209
210 friend inline void intrusive_ptr_add_ref(value_t::storage_t * storage_ptr) {
211 storage_ptr->acquire();
212 }
213 friend inline void intrusive_ptr_release(value_t::storage_t * storage_ptr) {
214 storage_ptr->release();
215 }
216
217 void destroy() {
218 DEBUG("value.storage.refcount", "Destroying " << this);
219 switch (type) {
220 case VOID:
221 return;
222 case BALANCE:
223 checked_delete(boost::get<balance_t *>(data));
224 break;
225 case SEQUENCE:
226 checked_delete(boost::get<sequence_t *>(data));
227 break;
228 default:
229 break;
230 }
231 data = false;
232 type = VOID;
233 }
234 };
235
236private:
241 intrusive_ptr<storage_t> storage;
242
247 void _dup() {
248 if (storage && storage->refc > 1)
249 storage = new storage_t(*storage.get());
250 }
251
257 static intrusive_ptr<storage_t> true_value;
258 static intrusive_ptr<storage_t> false_value;
259
260public:
261 static void initialize();
262 static void shutdown();
263
264public:
279 TRACE_CTOR(value_t, "");
280 }
281
282 value_t(const bool val) {
283 set_boolean(val);
284 TRACE_CTOR(value_t, "const bool");
285 }
286
287 value_t(const datetime_t& val) {
288 set_datetime(val);
289 TRACE_CTOR(value_t, "const datetime_t&");
290 }
291 value_t(const date_t& val) {
292 set_date(val);
293 TRACE_CTOR(value_t, "const date_t&");
294 }
295
296 value_t(const long val) {
297 set_long(val);
298 TRACE_CTOR(value_t, "const long");
299 }
300 value_t(const unsigned long val) {
301 set_amount(val);
302 TRACE_CTOR(value_t, "const unsigned long");
303 }
304 value_t(const double val) {
305 set_amount(val);
306 TRACE_CTOR(value_t, "const double");
307 }
308 value_t(const amount_t& val) {
309 set_amount(val);
310 TRACE_CTOR(value_t, "const amount_t&");
311 }
312 value_t(const balance_t& val) {
313 set_balance(val);
314 TRACE_CTOR(value_t, "const balance_t&");
315 }
316 value_t(const commodity_t& val) {
317 set_commodity(val);
318 TRACE_CTOR(value_t, "const commodity_t&");
319 }
320 value_t(const mask_t& val) {
321 set_mask(val);
322 TRACE_CTOR(value_t, "const mask_t&");
323 }
324
325 explicit value_t(const string& val, bool literal = false) {
326 if (literal)
327 set_string(val);
328 else
329 set_amount(amount_t(val));
330
331 TRACE_CTOR(value_t, "const string&, bool");
332 }
333 explicit value_t(const char * val, bool literal = false) {
334 if (literal)
335 set_string(val);
336 else
337 set_amount(amount_t(val));
338
339 TRACE_CTOR(value_t, "const char *");
340 }
341
342 value_t(const sequence_t& val) {
343 set_sequence(val);
344 TRACE_CTOR(value_t, "const sequence_t&");
345 }
346
347 explicit value_t(scope_t * item) {
348 set_scope(item);
349 TRACE_CTOR(value_t, "scope_t *");
350 }
351#if 0
352 template <typename T>
353 explicit value_t(T& item) {
354 set_any(item);
355 TRACE_CTOR(value_t, "T&");
356 }
357#endif
358
366 }
367
373 value_t(const value_t& val) {
374 *this = val;
375 TRACE_CTOR(value_t, "copy");
376 }
377 value_t& operator=(const value_t& val) {
378 if (! (this == &val || storage == val.storage))
379 storage = val.storage;
380 return *this;
381 }
382
386 bool is_equal_to(const value_t& val) const;
387 bool is_less_than(const value_t& val) const;
388 bool is_greater_than(const value_t& val) const;
389
390 template <typename T>
391 bool operator==(const T& amt) const {
392 return is_equal_to(amt);
393 }
394 template <typename T>
395 bool operator<(const T& amt) const {
396 return is_less_than(amt);
397 }
398 template <typename T>
399 bool operator>(const T& amt) const {
400 return is_greater_than(amt);
401 }
402
415
419 value_t negated() const {
420 value_t temp = *this;
421 temp.in_place_negate();
422 return temp;
423 }
424 void in_place_negate(); // exists for efficiency's sake
425 void in_place_not(); // exists for efficiency's sake
426
428 return negated();
429 }
430
431 value_t abs() const;
432
433 value_t rounded() const {
434 value_t temp(*this);
435 temp.in_place_round();
436 return temp;
437 }
439
440 value_t roundto(int places) const {
441 value_t temp(*this);
442 temp.in_place_roundto(places);
443 return temp;
444 }
445 void in_place_roundto(int places);
446
448 value_t temp(*this);
449 temp.in_place_truncate();
450 return temp;
451 }
453
454 value_t floored() const {
455 value_t temp(*this);
456 temp.in_place_floor();
457 return temp;
458 }
460
462 value_t temp(*this);
463 temp.in_place_ceiling();
464 return temp;
465 }
467
469 value_t temp(*this);
470 temp.in_place_unround();
471 return temp;
472 }
474
475 value_t reduced() const {
476 value_t temp(*this);
477 temp.in_place_reduce();
478 return temp;
479 }
480 void in_place_reduce(); // exists for efficiency's sake
481
483 value_t temp(*this);
484 temp.in_place_unreduce();
485 return temp;
486 }
487 void in_place_unreduce(); // exists for efficiency's sake
488
489 // Return the "market value" of a given value at a specific time.
491 const commodity_t * in_terms_of = NULL) const;
492
493 value_t exchange_commodities(const std::string& commodities,
494 const bool add_prices = false,
495 const datetime_t& moment = datetime_t());
496
500 operator bool() const;
501
502 bool is_nonzero() const {
503 return ! is_zero();
504 }
505
506 bool is_realzero() const;
507 bool is_zero() const;
508 bool is_null() const {
509 if (! storage) {
511 return true;
512 } else {
513 VERIFY(! is_type(VOID));
514 return false;
515 }
516 }
517
518 type_t type() const {
519 return storage ? storage->type : VOID;
520 }
521 bool is_type(type_t _type) const {
522 return type() == _type;
523 }
524
525private:
526 void set_type(type_t new_type);
527
528public:
558 bool is_boolean() const {
559 return is_type(BOOLEAN);
560 }
563 _dup();
564 return boost::get<bool>(storage->data);
565 }
566 const bool& as_boolean() const {
568 return boost::get<bool>(storage->data);
569 }
570 void set_boolean(const bool val) {
571 set_type(BOOLEAN);
572 storage = val ? true_value : false_value;
573 }
574
575 bool is_datetime() const {
576 return is_type(DATETIME);
577 }
580 _dup();
581 return boost::get<datetime_t>(storage->data);
582 }
583 const datetime_t& as_datetime() const {
585 return boost::get<datetime_t>(storage->data);
586 }
587 void set_datetime(const datetime_t& val) {
588 set_type(DATETIME);
589 storage->data = val;
590 }
591
592 bool is_date() const {
593 return is_type(DATE);
594 }
596 VERIFY(is_date());
597 _dup();
598 return boost::get<date_t>(storage->data);
599 }
600 const date_t& as_date() const {
601 VERIFY(is_date());
602 return boost::get<date_t>(storage->data);
603 }
604 void set_date(const date_t& val) {
605 set_type(DATE);
606 storage->data = val;
607 }
608
609 bool is_long() const {
610 return is_type(INTEGER);
611 }
612 long& as_long_lval() {
613 VERIFY(is_long());
614 _dup();
615 return boost::get<long>(storage->data);
616 }
617 const long& as_long() const {
618 VERIFY(is_long());
619 return boost::get<long>(storage->data);
620 }
621 void set_long(const long val) {
622 set_type(INTEGER);
623 storage->data = val;
624 }
625
626 bool is_amount() const {
627 return is_type(AMOUNT);
628 }
630 VERIFY(is_amount());
631 _dup();
632 return boost::get<amount_t>(storage->data);
633 }
634 const amount_t& as_amount() const {
635 VERIFY(is_amount());
636 return boost::get<amount_t>(storage->data);
637 }
638 void set_amount(const amount_t& val) {
639 VERIFY(val.valid());
640 set_type(AMOUNT);
641 storage->data = val;
642 }
643
644 bool is_balance() const {
645 return is_type(BALANCE);
646 }
649 _dup();
650 return *boost::get<balance_t *>(storage->data);
651 }
652 const balance_t& as_balance() const {
654 return *boost::get<balance_t *>(storage->data);
655 }
656 void set_balance(const balance_t& val) {
657 VERIFY(val.valid());
658 set_type(BALANCE);
659 storage->data = new balance_t(val);
660 }
661
662 bool is_commodity() const {
663 return is_type(COMMODITY);
664 }
665 const commodity_t& as_commodity() const {
667 return *boost::get<commodity_t const *>(storage->data);
668 }
669 void set_commodity(const commodity_t& val);
670
671 bool is_string() const {
672 return is_type(STRING);
673 }
674 string& as_string_lval() {
675 VERIFY(is_string());
676 _dup();
677 return boost::get<string>(storage->data);
678 }
679 const string& as_string() const {
680 VERIFY(is_string());
681 return boost::get<string>(storage->data);
682 }
683 void set_string(const string& val = "") {
684 set_type(STRING);
685 storage->data = val;
686 VERIFY(boost::get<string>(storage->data) == val);
687 }
688 void set_string(const char * val = "") {
689 set_type(STRING);
690 storage->data = string(val);
691 VERIFY(boost::get<string>(storage->data) == val);
692 }
693
694 bool is_mask() const {
695 return is_type(MASK);
696 }
698 VERIFY(is_mask());
699 _dup();
700 VERIFY(boost::get<mask_t>(storage->data).valid());
701 return boost::get<mask_t>(storage->data);
702 }
703 const mask_t& as_mask() const {
704 VERIFY(is_mask());
705 VERIFY(boost::get<mask_t>(storage->data).valid());
706 return boost::get<mask_t>(storage->data);
707 }
708 void set_mask(const string& val) {
709 set_type(MASK);
710 storage->data = mask_t(val);
711 }
712 void set_mask(const mask_t& val) {
713 set_type(MASK);
714 storage->data = val;
715 }
716
717 bool is_sequence() const {
718 return is_type(SEQUENCE);
719 }
722 _dup();
723 return *boost::get<sequence_t *>(storage->data);
724 }
725 const sequence_t& as_sequence() const {
727 return *boost::get<sequence_t *>(storage->data);
728 }
729 void set_sequence(const sequence_t& val) {
730 set_type(SEQUENCE);
731 storage->data = new sequence_t(val);
732 }
733
737 bool is_scope() const {
738 return is_type(SCOPE);
739 }
740 scope_t * as_scope() const {
741 VERIFY(is_scope());
742 return boost::get<scope_t *>(storage->data);
743 }
744 void set_scope(scope_t * val) {
745 set_type(SCOPE);
746 storage->data = val;
747 }
748
755 bool is_any() const {
756 return is_type(ANY);
757 }
758 template <typename T>
759 bool is_any() const {
760 return (is_type(ANY) &&
761 boost::get<boost::any>(storage->data).type() == typeid(T));
762 }
763 boost::any& as_any_lval() {
764 VERIFY(is_any());
765 _dup();
766 return boost::get<boost::any>(storage->data);
767 }
768 template <typename T>
770 return any_cast<T&>(as_any_lval());
771 }
772 const boost::any& as_any() const {
773 VERIFY(is_any());
774 return boost::get<boost::any>(storage->data);
775 }
776 template <typename T>
777 const T& as_any() const {
778 return any_cast<const T&>(as_any());
779 }
780 void set_any(const boost::any& val) {
781 set_type(ANY);
782 storage->data = val;
783 }
784 template <typename T>
785 void set_any(T& val) {
786 set_type(ANY);
787 storage->data = boost::any(val);
788 }
789
795 bool to_boolean() const;
796 int to_int() const;
797 long to_long() const;
798 std::size_t to_size_t() const { return static_cast<std::size_t>(to_long()); }
803 const commodity_t& to_commodity() const;
804 string to_string() const;
807
824 value_t casted(type_t cast_type) const {
825 value_t temp(*this);
826 temp.in_place_cast(cast_type);
827 return temp;
828 }
829 void in_place_cast(type_t cast_type);
830
832 value_t temp = *this;
833 temp.in_place_simplify();
834 return temp;
835 }
837
839
843 void annotate(const annotation_t& details);
844 bool has_annotation() const;
845
847 const annotation_t& annotation() const {
848 return const_cast<value_t&>(*this).annotation();
849 }
850
851 value_t strip_annotations(const keep_details_t& what_to_keep) const;
852
856 value_t& operator[](const std::size_t index) {
857 VERIFY(! is_null());
858 if (is_sequence())
859 return as_sequence_lval()[index];
860 else if (index == 0)
861 return *this;
862
863 assert(false);
864 static value_t null;
865 return null;
866 }
867 const value_t& operator[](const std::size_t index) const {
868 VERIFY(! is_null());
869 if (is_sequence())
870 return as_sequence()[index];
871 else if (index == 0)
872 return *this;
873
874 assert(false);
875 static value_t null;
876 return null;
877 }
878
879 void push_front(const value_t& val) {
880 if (is_null())
881 *this = sequence_t();
882 if (! is_sequence())
884 as_sequence_lval().push_front(new value_t(val));
885 }
886
887 void push_back(const value_t& val) {
888 if (is_null())
889 *this = sequence_t();
890 if (! is_sequence())
892 as_sequence_lval().push_back(new value_t(val));
893 }
894
895 void pop_back() {
896 VERIFY(! is_null());
897
898 if (! is_sequence()) {
899 storage.reset();
900 } else {
901 as_sequence_lval().pop_back();
902
903 const sequence_t& seq(as_sequence());
904 std::size_t new_size = seq.size();
905 if (new_size == 0) {
906 storage.reset();
907 }
908 else if (new_size == 1) {
909 *this = seq.front();
910 }
911 }
912 }
913
914 sequence_t::iterator begin() {
916 return as_sequence_lval().begin();
917 }
918 sequence_t::iterator end() {
920 return as_sequence_lval().end();
921 }
922
923 sequence_t::const_iterator begin() const {
925 return as_sequence().begin();
926 }
927 sequence_t::const_iterator end() const {
929 return as_sequence().end();
930 }
931
932 std::size_t size() const {
933 if (is_null())
934 return 0;
935 else if (is_sequence())
936 return as_sequence().size();
937 else
938 return 1;
939 }
940
941 bool empty() const {
942 return size() == 0;
943 }
944
948 string label(optional<type_t> the_type = none) const;
949
953 void print(std::ostream& out,
954 const int first_width = -1,
955 const int latter_width = -1,
956 const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
957
958 void dump(std::ostream& out, const bool relaxed = true) const;
959
963 bool valid() const;
964};
965
966#define NULL_VALUE (value_t())
967
968inline value_t string_value(const string& str = "") {
969 return value_t(str, true);
970}
971
972#define VALUE_OR_ZERO(val) ((val).is_null() ? value_t(0L) : (val))
973#define SIMPLIFIED_VALUE_OR_ZERO(val) \
974 ((val).is_null() ? value_t(0L) : (val).simplified())
975
976inline value_t mask_value(const string& str) {
977 return value_t(mask_t(str));
978}
979
980inline std::ostream& operator<<(std::ostream& out, const value_t& val) {
981 val.print(out);
982 return out;
983}
984
985inline string value_context(const value_t& val) {
986 std::ostringstream buf;
987 val.print(buf, 20, 20, true);
988 return buf.str();
989}
990
992 return value_t(val);
993}
994
995template <typename T>
996inline value_t& add_or_set_value(value_t& lhs, const T& rhs) {
997 if (lhs.is_null())
998 lhs = rhs;
999 else
1000 lhs += rhs;
1001 return lhs;
1002}
1003
1005{
1008
1010};
1011
1012bool sort_value_is_less_than(const std::list<sort_value_t>& left_values,
1013 const std::list<sort_value_t>& right_values);
1014
1015void put_value(property_tree::ptree& pt, const value_t& value);
1016
1017} // namespace ledger
#define DECLARE_EXCEPTION(name, kind)
Definition error.h:88
Basic type for adding multiple commodities together.
#define AMOUNT_PRINT_NO_FLAGS
An amount may be output to a stream using the ‘print’ method.
Definition amount.h:711
Regular expression masking.
#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:287
#define assert(x)
Definition utils.h:92
void put_value(property_tree::ptree &pt, const value_t &value)
value_t mask_value(const string &str)
Definition value.h:976
boost::gregorian::date date_t
Definition times.h:60
value_t string_value(const string &str="")
Definition value.h:968
std::string string
Definition utils.h:59
std::ostream & operator<<(std::ostream &out, const account_t &account)
value_t scope_value(scope_t *val)
Definition value.h:991
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:996
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:985
Encapsulate infinite-precision commoditized amounts.
Definition amount.h:96
bool valid() const
A wrapper around amount_t allowing addition of multiple commodities.
Definition balance.h:80
bool valid() const
Definition balance.h:591
value_error(const string &why)
Definition value.h:56
Dynamic type representing various numeric types.
Definition value.h:86
value_t()
Constructors.
Definition value.h:278
bool is_amount() const
Definition value.h:626
const value_t & operator[](const std::size_t index) const
Definition value.h:867
void set_boolean(const bool val)
Definition value.h:570
value_t(const bool val)
Definition value.h:282
value_t & operator-=(const value_t &val)
value_t floored() const
Definition value.h:454
value_t(const long val)
Definition value.h:296
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:694
value_t strip_annotations(const keep_details_t &what_to_keep) const
value_t(const string &val, bool literal=false)
Definition value.h:325
const boost::any & as_any() const
Definition value.h:772
value_t(const double val)
Definition value.h:304
string label(optional< type_t > the_type=none) const
Informational methods.
bool & as_boolean_lval()
Definition value.h:561
void in_place_truncate()
const datetime_t & as_datetime() const
Definition value.h:583
string & as_string_lval()
Definition value.h:674
value_t casted(type_t cast_type) const
Dynamic typing conversion methods.
Definition value.h:824
type_t type() const
Definition value.h:518
void in_place_simplify()
void in_place_floor()
amount_t & as_amount_lval()
Definition value.h:629
void in_place_unreduce()
const date_t & as_date() const
Definition value.h:600
value_t(const commodity_t &val)
Definition value.h:316
sequence_t to_sequence() const
void pop_back()
Definition value.h:895
value_t number() const
value_t(const date_t &val)
Definition value.h:291
const annotation_t & annotation() const
Definition value.h:847
bool is_commodity() const
Definition value.h:662
datetime_t & as_datetime_lval()
Definition value.h:578
void set_mask(const string &val)
Definition value.h:708
annotation_t & annotation()
bool is_null() const
Definition value.h:508
bool is_string() const
Definition value.h:671
void in_place_negate()
sequence_t::iterator end()
Definition value.h:918
bool is_less_than(const value_t &val) const
mask_t to_mask() const
void set_long(const long val)
Definition value.h:621
bool is_scope() const
Dealing with scope pointers.
Definition value.h:737
void set_any(T &val)
Definition value.h:785
mask_t & as_mask_lval()
Definition value.h:697
scope_t * as_scope() const
Definition value.h:740
const long & as_long() const
Definition value.h:617
const balance_t & as_balance() const
Definition value.h:652
const mask_t & as_mask() const
Definition value.h:703
int to_int() const
sequence_t::iterator iterator
Definition value.h:93
bool is_realzero() const
sequence_t::const_iterator begin() const
Definition value.h:923
void set_datetime(const datetime_t &val)
Definition value.h:587
void set_string(const char *val="")
Definition value.h:688
bool operator==(const T &amt) const
Definition value.h:391
std::size_t to_size_t() const
Definition value.h:798
const commodity_t & to_commodity() const
bool is_long() const
Definition value.h:609
bool empty() const
Definition value.h:941
value_t & operator+=(const value_t &val)
Binary arithmetic operators.
void push_back(const value_t &val)
Definition value.h:887
value_t operator-() const
Definition value.h:427
value_t ceilinged() const
Definition value.h:461
bool is_any() const
Definition value.h:759
const string & as_string() const
Definition value.h:679
bool is_balance() const
Definition value.h:644
void in_place_ceiling()
sequence_t & as_sequence_lval()
Definition value.h:720
void set_scope(scope_t *val)
Definition value.h:744
std::size_t size() const
Definition value.h:932
void set_date(const date_t &val)
Definition value.h:604
date_t to_date() const
void set_balance(const balance_t &val)
Definition value.h:656
long & as_long_lval()
Definition value.h:612
sequence_t::const_iterator end() const
Definition value.h:927
~value_t()
Destructor.
Definition value.h:364
bool operator<(const T &amt) const
Definition value.h:395
value_t rounded() const
Definition value.h:433
boost::any & as_any_lval()
Definition value.h:763
void set_commodity(const commodity_t &val)
long to_long() const
void in_place_unround()
bool is_boolean() const
Data manipulation methods.
Definition value.h:558
type_t
type_t gives the type of the data contained or referenced by a value_t object.
Definition value.h:102
datetime_t to_datetime() const
bool is_type(type_t _type) const
Definition value.h:521
value_t & operator[](const std::size_t index)
Collection-style access methods for SEQUENCE values.
Definition value.h:856
value_t(const datetime_t &val)
Definition value.h:287
bool is_equal_to(const value_t &val) const
Comparison operators.
const amount_t & as_amount() const
Definition value.h:634
bool is_sequence() const
Definition value.h:717
void set_any(const boost::any &val)
Definition value.h:780
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:725
sequence_t::iterator begin()
Definition value.h:914
void set_sequence(const sequence_t &val)
Definition value.h:729
bool is_any() const
Dealing with any type at all is bit involved because we actually deal with typed object.
Definition value.h:755
value_t simplified() const
Definition value.h:831
bool is_nonzero() const
Definition value.h:502
value_t & operator/=(const value_t &val)
void in_place_roundto(int places)
balance_t & as_balance_lval()
Definition value.h:647
value_t(scope_t *item)
Definition value.h:347
void annotate(const annotation_t &details)
Annotated commodity methods.
balance_t to_balance() const
value_t negated() const
Unary arithmetic operators.
Definition value.h:419
value_t & operator=(const value_t &val)
Definition value.h:377
date_t & as_date_lval()
Definition value.h:595
amount_t to_amount() const
T & as_any_lval()
Definition value.h:769
void push_front(const value_t &val)
Definition value.h:879
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:638
bool is_datetime() const
Definition value.h:575
const commodity_t & as_commodity() const
Definition value.h:665
const bool & as_boolean() const
Definition value.h:566
value_t(const char *val, bool literal=false)
Definition value.h:333
value_t(const mask_t &val)
Definition value.h:320
void set_mask(const mask_t &val)
Definition value.h:712
static void initialize()
bool operator>(const T &amt) const
Definition value.h:399
bool is_zero() const
value_t(const amount_t &val)
Definition value.h:308
bool is_date() const
Definition value.h:592
static void shutdown()
value_t(const unsigned long val)
Definition value.h:300
sequence_t::difference_type difference_type
Definition value.h:95
void in_place_cast(type_t cast_type)
value_t(const sequence_t &val)
Definition value.h:342
const T & as_any() const
Definition value.h:777
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:475
void dump(std::ostream &out, const bool relaxed=true) const
value_t(const balance_t &val)
Definition value.h:312
sequence_t::const_iterator const_iterator
Definition value.h:94
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:92
value_t(const value_t &val)
Assignment and copy operators.
Definition value.h:373
value_t truncated() const
Definition value.h:447
void set_string(const string &val="")
Definition value.h:683
bool to_boolean() const
Data conversion methods.
value_t unrounded() const
Definition value.h:468
value_t roundto(int places) const
Definition value.h:440
value_t unreduced() const
Definition value.h:482
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:210
~storage_t()
Destructor.
Definition value.h:173
friend void intrusive_ptr_release(value_t::storage_t *storage_ptr)
Definition value.h:213
friend class value_t
Definition value.h:120