Changed protection level of many parts of commodity_t

This commit is contained in:
John Wiegley 2009-11-02 17:05:51 -05:00
parent dea9530cb7
commit e663a13502
4 changed files with 122 additions and 129 deletions

View file

@ -38,9 +38,9 @@
namespace ledger { 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, void commodity_t::history_t::add_price(commodity_t& source,
const datetime_t& date, const datetime_t& date,
const amount_t& price, const amount_t& price,
const bool reflexive) const bool reflexive)
@ -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); 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; return false;
} }
void commodity_t::base_t::varied_history_t:: void commodity_t::varied_history_t::
add_price(commodity_t& source, add_price(commodity_t& source,
const datetime_t& date, const datetime_t& date,
const amount_t& price, const amount_t& price,
@ -99,8 +99,7 @@ void commodity_t::base_t::varied_history_t::
hist->add_price(source, date, price, reflexive); hist->add_price(source, date, price, reflexive);
} }
bool commodity_t::base_t::varied_history_t:: bool commodity_t::varied_history_t::remove_price(const datetime_t& date,
remove_price(const datetime_t& date,
commodity_t& comm) commodity_t& comm)
{ {
DEBUG("commodity.prices.add", "varied_remove_price: " << date << ", " << comm); DEBUG("commodity.prices.add", "varied_remove_price: " << date << ", " << comm);
@ -111,8 +110,7 @@ bool commodity_t::base_t::varied_history_t::
} }
optional<price_point_t> optional<price_point_t>
commodity_t::base_t::history_t:: commodity_t::history_t::find_price(const optional<datetime_t>& moment,
find_price(const optional<datetime_t>& moment,
const optional<datetime_t>& oldest const optional<datetime_t>& oldest
#if defined(DEBUG_ON) #if defined(DEBUG_ON)
, const int indent , const int indent
@ -222,8 +220,7 @@ optional<price_point_t>
} }
optional<price_point_t> optional<price_point_t>
commodity_t::base_t::varied_history_t:: commodity_t::varied_history_t::find_price(const commodity_t& source,
find_price(const commodity_t& source,
const optional<commodity_t&>& commodity, const optional<commodity_t&>& commodity,
const optional<datetime_t>& moment, const optional<datetime_t>& moment,
const optional<datetime_t>& oldest const optional<datetime_t>& oldest
@ -354,9 +351,8 @@ optional<price_point_t>
return none; return none;
} }
optional<commodity_t::base_t::history_t&> optional<commodity_t::history_t&>
commodity_t::base_t::varied_history_t:: commodity_t::varied_history_t::history(const optional<commodity_t&>& commodity)
history(const optional<commodity_t&>& commodity)
{ {
commodity_t * comm = NULL; commodity_t * comm = NULL;
if (! commodity) { if (! commodity) {

View file

@ -86,15 +86,6 @@ class commodity_t
: public delegates_flags<uint_least16_t>, : public delegates_flags<uint_least16_t>,
public equality_comparable1<commodity_t, noncopyable> 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, "");
}
public: public:
typedef std::map<const datetime_t, amount_t> history_map; typedef std::map<const datetime_t, amount_t> history_map;
@ -167,6 +158,13 @@ public:
#endif // HAVE_BOOST_SERIALIZATION #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_DEFAULTS 0x000
#define COMMODITY_STYLE_SUFFIXED 0x001 #define COMMODITY_STYLE_SUFFIXED 0x001
#define COMMODITY_STYLE_SEPARATED 0x002 #define COMMODITY_STYLE_SEPARATED 0x002
@ -188,11 +186,9 @@ public:
mutable bool searched; mutable bool searched;
static bool european_by_default;
public: public:
explicit base_t(const string& _symbol) 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_EUROPEAN :
COMMODITY_STYLE_DEFAULTS), COMMODITY_STYLE_DEFAULTS),
symbol(_symbol), precision(0), searched(false) { symbol(_symbol), precision(0), searched(false) {
@ -204,6 +200,10 @@ public:
#if defined(HAVE_BOOST_SERIALIZATION) #if defined(HAVE_BOOST_SERIALIZATION)
private: private:
base_t() {
TRACE_CTOR(base_t, "");
}
/** Serialization. */ /** Serialization. */
friend class boost::serialization::access; friend class boost::serialization::access;
@ -222,14 +222,8 @@ public:
#endif // HAVE_BOOST_SERIALIZATION #endif // HAVE_BOOST_SERIALIZATION
}; };
public:
static bool symbol_needs_quotes(const string& symbol); 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; shared_ptr<base_t> base;
commodity_pool_t * parent_; commodity_pool_t * parent_;
@ -237,13 +231,16 @@ public:
optional<string> mapping_key_; optional<string> mapping_key_;
bool annotated; bool annotated;
public:
explicit commodity_t(commodity_pool_t * _parent, explicit commodity_t(commodity_pool_t * _parent,
const shared_ptr<base_t>& _base) const shared_ptr<base_t>& _base)
: delegates_flags<uint_least16_t>(*_base.get()), base(_base), : delegates_flags<uint_least16_t>(*_base.get()), base(_base),
parent_(_parent), annotated(false) { parent_(_parent), annotated(false) {
TRACE_CTOR(commodity_t, "commodity_pool_t *, shared_ptr<base_t>"); TRACE_CTOR(commodity_t, "commodity_pool_t *, shared_ptr<base_t>");
} }
public:
static bool european_by_default;
virtual ~commodity_t() { virtual ~commodity_t() {
TRACE_DTOR(commodity_t); TRACE_DTOR(commodity_t);
} }

View file

@ -94,9 +94,9 @@ void posts_commodities_iterator::reset(journal_t& journal)
comm->varied_history()) { comm->varied_history()) {
account_t * account = journal.master->find_account(comm->symbol()); 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) { history->histories) {
foreach (commodity_t::base_t::history_map::value_type hpair, foreach (commodity_t::history_map::value_type hpair,
pair.second.prices) { pair.second.prices) {
xact_t * xact; xact_t * xact;
string symbol = hpair.second.commodity().symbol(); string symbol = hpair.second.commodity().symbol();

View file

@ -127,7 +127,7 @@ public:
OPTION(session_t, download); // -Q OPTION(session_t, download); // -Q
OPTION_(session_t, european, DO() { OPTION_(session_t, european, DO() {
commodity_t::base_t::european_by_default = true; commodity_t::european_by_default = true;
}); });
OPTION__ OPTION__