Changes to get all the code to compile

This commit is contained in:
John Wiegley 2012-03-04 04:03:32 -06:00
parent 48ab6ad1db
commit e910878312
5 changed files with 64 additions and 56 deletions

View file

@ -60,42 +60,52 @@ void commodity_t::remove_price(const datetime_t& date, commodity_t& commodity)
}
optional<price_point_t>
commodity_t::find_price(const optional<commodity_t&>& target = none,
const optional<datetime_t>& moment = none,
const optional<datetime_t>& oldest = none) const
commodity_t::find_price(const optional<commodity_t&>& commodity,
const optional<datetime_t>& moment,
const optional<datetime_t>& oldest) const
{
pair = base_t::time_and_commodity_t
(base_t::optional_time_pair_t(moment, oldest),
commodity ? &(*commodity) : NULL);
DEBUG_INDENT("commodity.prices.find", indent);
DEBUG("commodity.prices.find", "looking for memoized args: "
<< (moment ? format_datetime(*moment) : "NONE") << ", "
<< (oldest ? format_datetime(*oldest) : "NONE") << ", "
<< (commodity ? commodity->symbol() : "NONE"));
optional<base_t::time_and_commodity_t> pair =
base_t::time_and_commodity_t(base_t::optional_time_pair_t(moment, oldest),
commodity ? &(*commodity) : NULL);
base_t::memoized_price_map::iterator i = base->price_map.find(*pair);
if (i != base->price_map.end()) {
DEBUG_INDENT("commodity.prices.find", indent);
DEBUG("commodity.prices.find", "found! returning: "
<< ((*i).second ? (*i).second->price : amount_t(0L)));
return (*i).second;
DEBUG("commodity.prices.find", "looking for memoized args: "
<< (moment ? format_datetime(*moment) : "NONE") << ", "
<< (oldest ? format_datetime(*oldest) : "NONE") << ", "
<< (commodity ? commodity->symbol() : "NONE"));
{
base_t::memoized_price_map::iterator i = base->price_map.find(*pair);
if (i != base->price_map.end()) {
DEBUG("commodity.prices.find", "found! returning: "
<< ((*i).second ? (*i).second->price : amount_t(0L)));
return (*i).second;
}
}
datetime_t when;
if (moment)
when = *moment;
else if (epoch)
when = *epoch;
else
when = CURRENT_TIME();
optional<commodity_t&> target;
if (commodity)
target = commodity;
else if (pool().default_commodity)
target = *pool().default_commodity;
optional<price_point_t> point =
pool().commodity_price_history.find_price
(*this, commodity, moment ? *moment : epoch, oldest);
pool().commodity_price_history.find_price(*this, when, oldest, target);
if (pair) {
if (base->price_map.size() > base_t::max_price_map_size) {
DEBUG_INDENT("commodity.prices.find", indent);
DEBUG("commodity.prices.find",
"price map has grown too large, clearing it by half");
for (std::size_t i = 0; i < base_t::max_price_map_size >> 1; i++)
base->price_map.erase(base->price_map.begin());
}
DEBUG_INDENT("commodity.prices.find", indent);
DEBUG("commodity.prices.find",
"remembered: " << (point ? point->price : amount_t(0L)));
base->price_map.insert

View file

@ -106,12 +106,13 @@ protected:
#define COMMODITY_SAW_ANN_PRICE_FLOAT 0x400
#define COMMODITY_SAW_ANN_PRICE_FIXATED 0x800
string symbol;
amount_t::precision_t precision;
optional<string> name;
optional<string> note;
optional<amount_t> smaller;
optional<amount_t> larger;
string symbol;
optional<std::size_t> graph_index;
amount_t::precision_t precision;
optional<string> name;
optional<string> note;
optional<amount_t> smaller;
optional<amount_t> larger;
typedef std::pair<optional<datetime_t>,
optional<datetime_t> > optional_time_pair_t;
@ -123,15 +124,13 @@ protected:
static const std::size_t max_price_map_size = 16;
mutable memoized_price_map price_map;
mutable bool searched;
public:
explicit base_t(const string& _symbol)
: supports_flags<uint_least16_t>
(commodity_t::decimal_comma_by_default ?
static_cast<uint_least16_t>(COMMODITY_STYLE_DECIMAL_COMMA) :
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
symbol(_symbol), precision(0), searched(false) {
symbol(_symbol), precision(0) {
TRACE_CTOR(base_t, "const string&");
}
virtual ~base_t() {
@ -226,6 +225,13 @@ public:
return base_symbol();
}
optional<std::size_t> graph_index() const {;
return base->graph_index;
}
void set_graph_index(const optional<std::size_t>& arg = none) {
base->graph_index = arg;
}
optional<string> name() const {
return base->name;
}

View file

@ -42,20 +42,22 @@ struct f_max : public std::binary_function<T, T, bool> {
namespace ledger {
void commodity_history_t::add_commodity(const commodity_t& comm)
void commodity_history_t::add_commodity(commodity_t& comm)
{
const vertex_descriptor vert = add_vertex(&comm, price_graph);
put(indexmap, vert, reinterpret_cast<std::size_t>(&comm));
if (! comm.graph_index()) {
std::size_t index = num_vertices(price_graph);
comm.set_graph_index(index);
const vertex_descriptor vert = add_vertex(&comm, price_graph);
put(indexmap, vert, index);
}
}
void commodity_history_t::add_price(const commodity_t& source,
const datetime_t& when,
const amount_t& price)
{
vertex_descriptor sv =
vertex(reinterpret_cast<std::size_t>(&source), price_graph);
vertex_descriptor tv =
vertex(reinterpret_cast<std::size_t>(&price.commodity()), price_graph);
vertex_descriptor sv = vertex(*source.graph_index(), price_graph);
vertex_descriptor tv = vertex(*price.commodity().graph_index(), price_graph);
std::pair<edge_descriptor, bool> e1 = add_edge(sv, tv, 0, price_graph);
price_map_t& prices(get(ratiomap, e1.first));
@ -72,10 +74,8 @@ void commodity_history_t::remove_price(const commodity_t& source,
const commodity_t& target,
const datetime_t& date)
{
vertex_descriptor sv =
vertex(reinterpret_cast<std::size_t>(&source), price_graph);
vertex_descriptor tv =
vertex(reinterpret_cast<std::size_t>(&target), price_graph);
vertex_descriptor sv = vertex(*source.graph_index(), price_graph);
vertex_descriptor tv = vertex(*target.graph_index(), price_graph);
std::pair<edge_descriptor, bool> e1 = add_edge(sv, tv, 0, price_graph);
price_map_t& prices(get(ratiomap, e1.first));
@ -90,10 +90,11 @@ commodity_history_t::find_price(const commodity_t& source,
const optional<datetime_t>& oldest,
const optional<commodity_t&>& target)
{
vertex_descriptor sv =
vertex(reinterpret_cast<std::size_t>(&source), price_graph);
vertex_descriptor tv =
vertex(reinterpret_cast<std::size_t>(&*target), price_graph);
vertex_descriptor sv = vertex(*source.graph_index(), price_graph);
// jww (2012-03-04): What to do when target is null? In that case,
// should we just return whatever is the most recent price for that
// commodity?
vertex_descriptor tv = vertex(*target->graph_index(), price_graph);
// Filter out edges which came into being after the reference time

View file

@ -163,7 +163,7 @@ public:
pricemap(get(edge_price_point, price_graph)),
ratiomap(get(edge_price_ratio, price_graph)) {}
void add_commodity(const commodity_t& comm);
void add_commodity(commodity_t& comm);
void add_price(const commodity_t& source,
const datetime_t& when,

View file

@ -223,15 +223,6 @@ commodity_t * commodity_pool_t::find_or_create(commodity_t& comm,
return create(comm, details, name);
}
optional<price_point_t>
commodity_pool_t::find_price(const commodity_t& source,
const optional<commodity_t&>& commodity,
const optional<datetime_t>& moment,
const optional<datetime_t>& oldest) const
{
return commodity_price_history.find_price(source, commodity, moment, oldest);
}
void commodity_pool_t::exchange(commodity_t& commodity,
const amount_t& per_unit_cost,
const datetime_t& moment)