diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-02 17:05:51 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-02 17:05:51 -0500 |
commit | e663a13502b8813a28b8aebbc611fbc040d4246b (patch) | |
tree | aece620f1644c495bd024f6f32409bfb6bf962ae /src | |
parent | dea9530cb7d65486143b866b60d9bd1e4914aa56 (diff) | |
download | fork-ledger-e663a13502b8813a28b8aebbc611fbc040d4246b.tar.gz fork-ledger-e663a13502b8813a28b8aebbc611fbc040d4246b.tar.bz2 fork-ledger-e663a13502b8813a28b8aebbc611fbc040d4246b.zip |
Changed protection level of many parts of commodity_t
Diffstat (limited to 'src')
-rw-r--r-- | src/commodity.cc | 46 | ||||
-rw-r--r-- | src/commodity.h | 167 | ||||
-rw-r--r-- | src/iterators.cc | 4 | ||||
-rw-r--r-- | src/session.h | 2 |
4 files changed, 106 insertions, 113 deletions
diff --git a/src/commodity.cc b/src/commodity.cc index 26038a0b..d896572f 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -38,12 +38,12 @@ namespace ledger { -bool commodity_t::base_t::european_by_default = false; +bool commodity_t::european_by_default = false; -void commodity_t::base_t::history_t::add_price(commodity_t& source, - const datetime_t& date, - const amount_t& price, - const bool reflexive) +void commodity_t::history_t::add_price(commodity_t& source, + const datetime_t& date, + const amount_t& price, + const bool reflexive) { DEBUG("commodity.prices.add", "add_price to " << source << (reflexive ? " (secondary)" : " (primary)") @@ -69,7 +69,7 @@ void commodity_t::base_t::history_t::add_price(commodity_t& source, } } -bool commodity_t::base_t::history_t::remove_price(const datetime_t& date) +bool commodity_t::history_t::remove_price(const datetime_t& date) { DEBUG("commodity.prices.add", "remove_price: " << date); @@ -79,7 +79,7 @@ bool commodity_t::base_t::history_t::remove_price(const datetime_t& date) return false; } -void commodity_t::base_t::varied_history_t:: +void commodity_t::varied_history_t:: add_price(commodity_t& source, const datetime_t& date, const amount_t& price, @@ -99,9 +99,8 @@ void commodity_t::base_t::varied_history_t:: hist->add_price(source, date, price, reflexive); } -bool commodity_t::base_t::varied_history_t:: - remove_price(const datetime_t& date, - commodity_t& comm) +bool commodity_t::varied_history_t::remove_price(const datetime_t& date, + commodity_t& comm) { DEBUG("commodity.prices.add", "varied_remove_price: " << date << ", " << comm); @@ -111,13 +110,12 @@ bool commodity_t::base_t::varied_history_t:: } optional<price_point_t> - commodity_t::base_t::history_t:: - find_price(const optional<datetime_t>& moment, - const optional<datetime_t>& oldest +commodity_t::history_t::find_price(const optional<datetime_t>& moment, + const optional<datetime_t>& oldest #if defined(DEBUG_ON) - , const int indent + , const int indent #endif - ) const + ) const { price_point_t point; bool found = false; @@ -222,15 +220,14 @@ optional<price_point_t> } optional<price_point_t> - commodity_t::base_t::varied_history_t:: - find_price(const commodity_t& source, - const optional<commodity_t&>& commodity, - const optional<datetime_t>& moment, - const optional<datetime_t>& oldest +commodity_t::varied_history_t::find_price(const commodity_t& source, + const optional<commodity_t&>& commodity, + const optional<datetime_t>& moment, + const optional<datetime_t>& oldest #if defined(DEBUG_ON) - , const int indent + , const int indent #endif - ) const + ) const { optional<price_point_t> point; optional<datetime_t> limit = oldest; @@ -354,9 +351,8 @@ optional<price_point_t> return none; } -optional<commodity_t::base_t::history_t&> - commodity_t::base_t::varied_history_t:: - history(const optional<commodity_t&>& commodity) +optional<commodity_t::history_t&> +commodity_t::varied_history_t::history(const optional<commodity_t&>& commodity) { commodity_t * comm = NULL; if (! commodity) { diff --git a/src/commodity.h b/src/commodity.h index af92271e..25397131 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -86,87 +86,85 @@ class commodity_t : public delegates_flags<uint_least16_t>, public equality_comparable1<commodity_t, noncopyable> { - friend class commodity_pool_t; - public: - class base_t : public noncopyable, public supports_flags<uint_least16_t> - { - base_t() { - TRACE_CTOR(base_t, ""); - } + typedef std::map<const datetime_t, amount_t> history_map; - public: - typedef std::map<const datetime_t, amount_t> history_map; - - struct history_t - { - history_map prices; + struct history_t + { + history_map prices; - void add_price(commodity_t& source, - const datetime_t& date, - const amount_t& price, - const bool reflexive = true); - bool remove_price(const datetime_t& date); + void add_price(commodity_t& source, + const datetime_t& date, + const amount_t& price, + const bool reflexive = true); + bool remove_price(const datetime_t& date); - optional<price_point_t> - find_price(const optional<datetime_t>& moment = none, - const optional<datetime_t>& oldest = none + optional<price_point_t> + find_price(const optional<datetime_t>& moment = none, + const optional<datetime_t>& oldest = none #if defined(DEBUG_ON) - , const int indent = 0 + , const int indent = 0 #endif - ) const; + ) const; #if defined(HAVE_BOOST_SERIALIZATION) - private: - /** Serialization. */ + private: + /** Serialization. */ - friend class boost::serialization::access; + friend class boost::serialization::access; - template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { - ar & prices; - } + template<class Archive> + void serialize(Archive & ar, const unsigned int /* version */) { + ar & prices; + } #endif // HAVE_BOOST_SERIALIZATION - }; - - typedef std::map<commodity_t *, history_t> history_by_commodity_map; - - struct varied_history_t - { - history_by_commodity_map histories; + }; - void add_price(commodity_t& source, - const datetime_t& date, - const amount_t& price, - const bool reflexive = true); - bool remove_price(const datetime_t& date, commodity_t& commodity); + typedef std::map<commodity_t *, history_t> history_by_commodity_map; - optional<price_point_t> - find_price(const commodity_t& source, - const optional<commodity_t&>& commodity = none, - const optional<datetime_t>& moment = none, - const optional<datetime_t>& oldest = none + struct varied_history_t + { + history_by_commodity_map histories; + + void add_price(commodity_t& source, + const datetime_t& date, + const amount_t& price, + const bool reflexive = true); + bool remove_price(const datetime_t& date, commodity_t& commodity); + + optional<price_point_t> + find_price(const commodity_t& source, + const optional<commodity_t&>& commodity = none, + const optional<datetime_t>& moment = none, + const optional<datetime_t>& oldest = none #if defined(DEBUG_ON) - , const int indent = 0 + , const int indent = 0 #endif - ) const; + ) const; - optional<history_t&> - history(const optional<commodity_t&>& commodity = none); + optional<history_t&> + history(const optional<commodity_t&>& commodity = none); #if defined(HAVE_BOOST_SERIALIZATION) - private: - /** Serialization. */ + private: + /** Serialization. */ - friend class boost::serialization::access; + friend class boost::serialization::access; - template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { - ar & histories; - } + template<class Archive> + void serialize(Archive & ar, const unsigned int /* version */) { + ar & histories; + } #endif // HAVE_BOOST_SERIALIZATION - }; + }; +protected: + friend class commodity_pool_t; + friend class annotated_commodity_t; + + class base_t : public noncopyable, public supports_flags<uint_least16_t> + { + public: #define COMMODITY_STYLE_DEFAULTS 0x000 #define COMMODITY_STYLE_SUFFIXED 0x001 #define COMMODITY_STYLE_SEPARATED 0x002 @@ -188,11 +186,9 @@ public: mutable bool searched; - static bool european_by_default; - public: explicit base_t(const string& _symbol) - : supports_flags<uint_least16_t>(european_by_default ? + : supports_flags<uint_least16_t>(commodity_t::european_by_default ? COMMODITY_STYLE_EUROPEAN : COMMODITY_STYLE_DEFAULTS), symbol(_symbol), precision(0), searched(false) { @@ -203,33 +199,31 @@ public: } #if defined(HAVE_BOOST_SERIALIZATION) - private: - /** Serialization. */ - - friend class boost::serialization::access; - - template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { - ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this); - ar & symbol; - ar & precision; - ar & name; - ar & note; - ar & varied_history; - ar & smaller; - ar & larger; - } + private: + base_t() { + TRACE_CTOR(base_t, ""); + } + + /** Serialization. */ + + friend class boost::serialization::access; + + template<class Archive> + void serialize(Archive & ar, const unsigned int /* version */) { + ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this); + ar & symbol; + ar & precision; + ar & name; + ar & note; + ar & varied_history; + ar & smaller; + ar & larger; + } #endif // HAVE_BOOST_SERIALIZATION }; -public: static bool symbol_needs_quotes(const string& symbol); - typedef base_t::history_t history_t; - typedef base_t::history_map history_map; - typedef base_t::varied_history_t varied_history_t; - typedef base_t::history_by_commodity_map history_by_commodity_map; - shared_ptr<base_t> base; commodity_pool_t * parent_; @@ -237,13 +231,16 @@ public: optional<string> mapping_key_; bool annotated; -public: explicit commodity_t(commodity_pool_t * _parent, const shared_ptr<base_t>& _base) : delegates_flags<uint_least16_t>(*_base.get()), base(_base), parent_(_parent), annotated(false) { TRACE_CTOR(commodity_t, "commodity_pool_t *, shared_ptr<base_t>"); } + +public: + static bool european_by_default; + virtual ~commodity_t() { TRACE_DTOR(commodity_t); } diff --git a/src/iterators.cc b/src/iterators.cc index 50c67ade..540ba8ae 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -94,9 +94,9 @@ void posts_commodities_iterator::reset(journal_t& journal) comm->varied_history()) { account_t * account = journal.master->find_account(comm->symbol()); - foreach (commodity_t::base_t::history_by_commodity_map::value_type pair, + foreach (commodity_t::history_by_commodity_map::value_type pair, history->histories) { - foreach (commodity_t::base_t::history_map::value_type hpair, + foreach (commodity_t::history_map::value_type hpair, pair.second.prices) { xact_t * xact; string symbol = hpair.second.commodity().symbol(); diff --git a/src/session.h b/src/session.h index d8bfa05f..58e33f6b 100644 --- a/src/session.h +++ b/src/session.h @@ -127,7 +127,7 @@ public: OPTION(session_t, download); // -Q OPTION_(session_t, european, DO() { - commodity_t::base_t::european_by_default = true; + commodity_t::european_by_default = true; }); OPTION__ |