diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commodity.cc | 5 | ||||
-rw-r--r-- | src/commodity.h | 130 | ||||
-rw-r--r-- | src/utils.h | 6 |
3 files changed, 73 insertions, 68 deletions
diff --git a/src/commodity.cc b/src/commodity.cc index 1fac4a4e..ababfd67 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -279,8 +279,9 @@ commodity_pool_t::commodity_pool_t() : default_commodity(NULL) commodity_t * commodity_pool_t::create(const string& symbol) { - shared_ptr<commodity_base_t> base_commodity(new commodity_base_t(symbol)); - std::auto_ptr<commodity_t> commodity(new commodity_t(this, base_commodity)); + shared_ptr<commodity_t::base_t> + base_commodity(new commodity_t::base_t(symbol)); + std::auto_ptr<commodity_t> commodity(new commodity_t(this, base_commodity)); DEBUG("amounts.commodities", "Creating base commodity " << symbol); diff --git a/src/commodity.h b/src/commodity.h index 29534729..7b9a7be4 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -45,73 +45,70 @@ namespace ledger { -#define COMMODITY_STYLE_DEFAULTS 0x0000 -#define COMMODITY_STYLE_SUFFIXED 0x0001 -#define COMMODITY_STYLE_SEPARATED 0x0002 -#define COMMODITY_STYLE_EUROPEAN 0x0004 -#define COMMODITY_STYLE_THOUSANDS 0x0008 -#define COMMODITY_STYLE_NOMARKET 0x0010 -#define COMMODITY_STYLE_BUILTIN 0x0020 - -class commodity_base_t : public noncopyable +class commodity_t + : public equality_comparable1<commodity_t, noncopyable> { -private: - friend class commodity_pool_t; - friend class commodity_t; - friend class annotated_commodity_t; - - typedef std::map<const moment_t, amount_t> history_map; - typedef std::pair<const moment_t, amount_t> history_pair; - - struct history_t { - history_map prices; - ptime last_lookup; - }; - - typedef uint_least8_t flags_t; - - flags_t flags; - string symbol; - amount_t::precision_t precision; - optional<string> name; - optional<string> note; - optional<history_t> history; - optional<amount_t> smaller; - optional<amount_t> larger; - -public: - explicit commodity_base_t() - : flags(COMMODITY_STYLE_DEFAULTS), precision(0) { - TRACE_CTOR(commodity_base_t, ""); - } - explicit commodity_base_t + class base_t : public noncopyable + { + private: + friend class commodity_pool_t; + friend class commodity_t; + + typedef std::map<const moment_t, amount_t> history_map; + typedef std::pair<const moment_t, amount_t> history_pair; + + struct history_t { + history_map prices; + ptime last_lookup; + }; + + typedef uint_least8_t flags_t; + +#define COMMODITY_STYLE_DEFAULTS 0x00 +#define COMMODITY_STYLE_SUFFIXED 0x01 +#define COMMODITY_STYLE_SEPARATED 0x02 +#define COMMODITY_STYLE_EUROPEAN 0x04 +#define COMMODITY_STYLE_THOUSANDS 0x08 +#define COMMODITY_STYLE_NOMARKET 0x10 +#define COMMODITY_STYLE_BUILTIN 0x20 + + flags_t flags; + string symbol; + amount_t::precision_t precision; + optional<string> name; + optional<string> note; + optional<history_t> history; + optional<amount_t> smaller; + optional<amount_t> larger; + + public: + explicit base_t() + : flags(COMMODITY_STYLE_DEFAULTS), precision(0) { + TRACE_CTOR(base_t, ""); + } + explicit base_t (const string& _symbol, amount_t::precision_t _precision = 0, unsigned int _flags = COMMODITY_STYLE_DEFAULTS) - : flags(_flags), symbol(_symbol), precision(_precision) { - TRACE_CTOR(commodity_base_t, - "const string&, amount_t::precision_t, unsigned int"); - } - ~commodity_base_t() { - TRACE_DTOR(commodity_base_t); - } -}; - -class annotated_commodity_t; + : flags(_flags), symbol(_symbol), precision(_precision) { + TRACE_CTOR(base_t, + "const string&, amount_t::precision_t, unsigned int"); + } + ~base_t() { + TRACE_DTOR(base_t); + } + }; -class commodity_t - : public equality_comparable1<commodity_t, noncopyable> -{ public: static bool symbol_needs_quotes(const string& symbol); - typedef commodity_base_t::flags_t flags_t; - typedef commodity_base_t::history_t history_t; - typedef commodity_base_t::history_map history_map; - typedef commodity_base_t::history_pair history_pair; + typedef base_t::flags_t flags_t; + typedef base_t::history_t history_t; + typedef base_t::history_map history_map; + typedef base_t::history_pair history_pair; typedef uint_least32_t ident_t; - shared_ptr<commodity_base_t> base; + shared_ptr<base_t> base; commodity_pool_t * parent_; ident_t ident; @@ -121,7 +118,7 @@ public: public: explicit commodity_t(commodity_pool_t * _parent, - const shared_ptr<commodity_base_t>& _base) + const shared_ptr<base_t>& _base) : base(_base), parent_(_parent), annotated(false) { TRACE_CTOR(commodity_t, ""); } @@ -234,9 +231,10 @@ struct annotation_t : public equality_comparable<annotation_t> optional<moment_t> date; optional<string> tag; - explicit annotation_t(const optional<amount_t>& _price = optional<amount_t>(), - const optional<moment_t>& _date = optional<moment_t>(), - const optional<string>& _tag = optional<string>()) + explicit annotation_t + (const optional<amount_t>& _price = optional<amount_t>(), + const optional<moment_t>& _date = optional<moment_t>(), + const optional<string>& _tag = optional<string>()) : price(_price), date(_date), tag(_tag) {} operator bool() const { @@ -267,7 +265,9 @@ inline std::ostream& operator<<(std::ostream& out, const annotation_t& details) class annotated_commodity_t : public commodity_t, - equality_comparable1<annotated_commodity_t, noncopyable> + equality_comparable<annotated_commodity_t, + equality_comparable2<annotated_commodity_t, commodity_t, + noncopyable> > { public: commodity_t * ptr; @@ -284,6 +284,9 @@ public: } virtual bool operator==(const commodity_t& comm) const; + virtual bool operator==(const annotated_commodity_t& comm) const { + return *this == static_cast<commodity_t&>(comm); + } commodity_t& referent() { return *ptr; @@ -306,7 +309,6 @@ struct compare_amount_commodities { class commodity_pool_t : public noncopyable { -public: /** * The commodities collection in commodity_pool_t maintains pointers * to all the commodities which have ever been created by the user, @@ -332,6 +334,8 @@ public: > commodities_t; commodities_t commodities; + +public: commodity_t * null_commodity; commodity_t * default_commodity; diff --git a/src/utils.h b/src/utils.h index 4a7213b7..bde23b2b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,7 +1,7 @@ #ifndef _UTILS_H #define _UTILS_H -#if defined(FULL_DEBUG) +#if defined(DEBUG_MODE) #define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE 1 #define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING 1 #endif @@ -13,13 +13,13 @@ * Default values */ -#if defined(FULL_DEBUG) +#if defined(DEBUG_MODE) #define VERIFY_ON 1 #define TRACING_ON 1 #define DEBUG_ON 1 #define TIMERS_ON 1 #define FREE_MEMORY 1 -#elif defined(NO_DEBUG) +#elif defined(NDEBUG) #define NO_ASSERTS 1 #define NO_LOGGING 1 #else |