Changed protection level of many parts of commodity_t
This commit is contained in:
parent
dea9530cb7
commit
e663a13502
4 changed files with 122 additions and 129 deletions
|
|
@ -38,12 +38,12 @@
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
DEBUG("commodity.prices.add", "add_price to " << source
|
DEBUG("commodity.prices.add", "add_price to " << source
|
||||||
<< (reflexive ? " (secondary)" : " (primary)")
|
<< (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);
|
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,9 +99,8 @@ 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,13 +110,12 @@ 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
|
||||||
#endif
|
#endif
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
price_point_t point;
|
price_point_t point;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
@ -222,15 +220,14 @@ 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
|
|
||||||
#if defined(DEBUG_ON)
|
#if defined(DEBUG_ON)
|
||||||
, const int indent
|
, const int indent
|
||||||
#endif
|
#endif
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
optional<price_point_t> point;
|
optional<price_point_t> point;
|
||||||
optional<datetime_t> limit = oldest;
|
optional<datetime_t> limit = 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) {
|
||||||
|
|
|
||||||
199
src/commodity.h
199
src/commodity.h
|
|
@ -86,87 +86,85 @@ 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:
|
public:
|
||||||
|
typedef std::map<const datetime_t, amount_t> history_map;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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
|
||||||
|
#endif
|
||||||
|
) const;
|
||||||
|
|
||||||
|
#if defined(HAVE_BOOST_SERIALIZATION)
|
||||||
|
private:
|
||||||
|
/** Serialization. */
|
||||||
|
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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
|
||||||
|
#endif
|
||||||
|
) const;
|
||||||
|
|
||||||
|
optional<history_t&>
|
||||||
|
history(const optional<commodity_t&>& commodity = none);
|
||||||
|
|
||||||
|
#if defined(HAVE_BOOST_SERIALIZATION)
|
||||||
|
private:
|
||||||
|
/** Serialization. */
|
||||||
|
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
|
||||||
|
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>
|
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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
|
||||||
#endif
|
|
||||||
) const;
|
|
||||||
|
|
||||||
#if defined(HAVE_BOOST_SERIALIZATION)
|
|
||||||
private:
|
|
||||||
/** Serialization. */
|
|
||||||
|
|
||||||
friend class boost::serialization::access;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
|
||||||
#endif
|
|
||||||
) const;
|
|
||||||
|
|
||||||
optional<history_t&>
|
|
||||||
history(const optional<commodity_t&>& commodity = none);
|
|
||||||
|
|
||||||
#if defined(HAVE_BOOST_SERIALIZATION)
|
|
||||||
private:
|
|
||||||
/** Serialization. */
|
|
||||||
|
|
||||||
friend class boost::serialization::access;
|
|
||||||
|
|
||||||
template<class Archive>
|
|
||||||
void serialize(Archive & ar, const unsigned int /* version */) {
|
|
||||||
ar & histories;
|
|
||||||
}
|
|
||||||
#endif // HAVE_BOOST_SERIALIZATION
|
|
||||||
};
|
|
||||||
|
|
||||||
#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) {
|
||||||
|
|
@ -203,33 +199,31 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_BOOST_SERIALIZATION)
|
#if defined(HAVE_BOOST_SERIALIZATION)
|
||||||
private:
|
private:
|
||||||
/** Serialization. */
|
base_t() {
|
||||||
|
TRACE_CTOR(base_t, "");
|
||||||
|
}
|
||||||
|
|
||||||
friend class boost::serialization::access;
|
/** Serialization. */
|
||||||
|
|
||||||
template<class Archive>
|
friend class boost::serialization::access;
|
||||||
void serialize(Archive & ar, const unsigned int /* version */) {
|
|
||||||
ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this);
|
template<class Archive>
|
||||||
ar & symbol;
|
void serialize(Archive & ar, const unsigned int /* version */) {
|
||||||
ar & precision;
|
ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this);
|
||||||
ar & name;
|
ar & symbol;
|
||||||
ar & note;
|
ar & precision;
|
||||||
ar & varied_history;
|
ar & name;
|
||||||
ar & smaller;
|
ar & note;
|
||||||
ar & larger;
|
ar & varied_history;
|
||||||
}
|
ar & smaller;
|
||||||
|
ar & larger;
|
||||||
|
}
|
||||||
#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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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__
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue