summaryrefslogtreecommitdiff
path: root/src/history.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/history.h')
-rw-r--r--src/history.h132
1 files changed, 15 insertions, 117 deletions
diff --git a/src/history.h b/src/history.h
index fc984c1b..71cbad0c 100644
--- a/src/history.h
+++ b/src/history.h
@@ -60,93 +60,12 @@ namespace ledger {
typedef std::map<datetime_t, amount_t> price_map_t;
-template <typename EdgeWeightMap,
- typename PricePointMap,
- typename PriceRatioMap>
-class recent_edge_weight
-{
-public:
- EdgeWeightMap weight;
- PricePointMap price_point;
- PriceRatioMap ratios;
-
- datetime_t * reftime;
- optional<datetime_t> * last_reftime;
- optional<datetime_t> * oldest;
- optional<datetime_t> * last_oldest;
-
- recent_edge_weight() { }
- recent_edge_weight(EdgeWeightMap _weight,
- PricePointMap _price_point,
- PriceRatioMap _ratios,
- datetime_t * _reftime,
- optional<datetime_t> * _last_reftime,
- optional<datetime_t> * _oldest,
- optional<datetime_t> * _last_oldest)
- : weight(_weight), price_point(_price_point), ratios(_ratios),
- reftime(_reftime), last_reftime(_last_reftime),
- oldest(_oldest), last_oldest(_last_oldest) { }
-
- template <typename Edge>
- bool operator()(const Edge& e) const
- {
- DEBUG("history.find", " reftime = " << *reftime);
- if (*last_reftime)
- DEBUG("history.find", " last_reftime = " << **last_reftime);
- if (*oldest)
- DEBUG("history.find", " oldest = " << **oldest);
- if (*last_oldest)
- DEBUG("history.find", " last_oldest = " << **last_oldest);
-
-#if 0
- if (*last_reftime && *reftime == **last_reftime &&
- *oldest == *last_oldest) {
- DEBUG("history.find", " using previous reftime");
- return get(weight, e) != std::numeric_limits<std::size_t>::max();
- }
-#endif
-
- const price_map_t& prices(get(ratios, e));
- if (prices.empty()) {
- DEBUG("history.find", " prices map is empty for this edge");
- put(weight, e, std::numeric_limits<std::size_t>::max());
- return false;
- }
-
- price_map_t::const_iterator low = prices.upper_bound(*reftime);
- if (low != prices.end() && low == prices.begin()) {
- DEBUG("history.find", " don't use this edge");
- put(weight, e, std::numeric_limits<std::size_t>::max());
- return false;
- } else {
- --low;
- assert(((*low).first <= *reftime));
-
- if (*oldest && (*low).first < **oldest) {
- DEBUG("history.find", " edge is out of range");
- put(weight, e, std::numeric_limits<std::size_t>::max());
- return false;
- }
-
- long secs = (*reftime - (*low).first).total_seconds();
- assert(secs >= 0);
-
- put(weight, e, secs);
- put(price_point, e, price_point_t((*low).first, (*low).second));
-
- DEBUG("history.find", " using edge at price point "
- << (*low).first << " " << (*low).second);
- return true;
- }
- }
-};
-
class commodity_history_t : public noncopyable
{
public:
typedef adjacency_list
- <setS, // Store all edges as a set
- setS, // Store all vertices in a set
+ <vecS, // Store all edges in a vector
+ vecS, // Store all vertices in a vector
undirectedS, // Relations are both ways
// All vertices are commodities
@@ -170,36 +89,16 @@ public:
typedef graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef graph_traits<Graph>::edge_descriptor edge_descriptor;
- typedef property_map<Graph, vertex_index_t>::type IndexMap;
- typedef property_map<Graph, vertex_name_t>::type NameMap;
-
- typedef iterator_property_map<vertex_descriptor*, IndexMap,
- vertex_descriptor,
- vertex_descriptor&> PredecessorMap;
- typedef iterator_property_map<long*, IndexMap, long, long&> DistanceMap;
-
+ typedef property_map<Graph, vertex_name_t>::type NameMap;
typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap;
typedef property_map<Graph, edge_price_point_t>::type PricePointMap;
typedef property_map<Graph, edge_price_ratio_t>::type PriceRatioMap;
- IndexMap indexmap;
PricePointMap pricemap;
PriceRatioMap ratiomap;
- typedef filtered_graph<Graph, recent_edge_weight<EdgeWeightMap,
- PricePointMap,
- PriceRatioMap> > FGraph;
- typedef property_map<FGraph, vertex_name_t>::type FNameMap;
-
- // jww (2012-03-05): Prevents threading
- mutable datetime_t reftime;
- mutable optional<datetime_t> last_reftime;
- mutable optional<datetime_t> oldest;
- mutable optional<datetime_t> last_oldest;
-
commodity_history_t()
- : indexmap(get(vertex_index, price_graph)),
- pricemap(get(edge_price_point, price_graph)),
+ : pricemap(get(edge_price_point, price_graph)),
ratiomap(get(edge_price_ratio, price_graph)) {}
void add_commodity(commodity_t& comm);
@@ -212,23 +111,22 @@ public:
const datetime_t& date);
void map_prices(function<void(datetime_t, const amount_t&)> fn,
- const commodity_t& source,
- const datetime_t& moment,
- const optional<datetime_t>& _oldest = none);
+ const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& _oldest = datetime_t());
optional<price_point_t>
- find_price(const commodity_t& source,
- const datetime_t& moment,
- const optional<datetime_t>& oldest = none);
+ find_price(const commodity_t& source,
+ const datetime_t& moment,
+ const datetime_t& oldest = datetime_t());
optional<price_point_t>
- find_price(const commodity_t& source,
- const commodity_t& target,
- const datetime_t& moment,
- const optional<datetime_t>& oldest = none);
+ find_price(const commodity_t& source,
+ const commodity_t& target,
+ const datetime_t& moment,
+ const datetime_t& oldest = datetime_t());
- void print_map(std::ostream& out,
- const optional<datetime_t>& moment = none);
+ void print_map(std::ostream& out, const datetime_t& moment = datetime_t());
};
} // namespace ledger