summaryrefslogtreecommitdiff
path: root/src/commodity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/commodity.h')
-rw-r--r--src/commodity.h49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/commodity.h b/src/commodity.h
index 524daaab..bd1aedb9 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -47,6 +47,8 @@
#ifndef _COMMODITY_H
#define _COMMODITY_H
+#include "expr.h"
+
namespace ledger {
struct keep_details_t;
@@ -113,15 +115,14 @@ protected:
optional<string> note;
optional<amount_t> smaller;
optional<amount_t> larger;
+ optional<expr_t> value_expr;
- typedef std::pair<optional<datetime_t>,
- optional<datetime_t> > optional_time_pair_t;
- typedef std::pair<optional_time_pair_t,
- commodity_t *> time_and_commodity_t;
- typedef std::map<time_and_commodity_t,
+ typedef tuple<datetime_t, datetime_t,
+ const commodity_t *> memoized_price_entry;
+ typedef std::map<memoized_price_entry,
optional<price_point_t> > memoized_price_map;
- static const std::size_t max_price_map_size = 16;
+ static const std::size_t max_price_map_size = 8;
mutable memoized_price_map price_map;
public:
@@ -164,7 +165,6 @@ protected:
commodity_pool_t * parent_;
optional<string> qualified_symbol;
- optional<string> mapping_key_;
bool annotated;
explicit commodity_t(commodity_pool_t * _parent,
@@ -218,13 +218,6 @@ public:
return qualified_symbol ? *qualified_symbol : base_symbol();
}
- string mapping_key() const {
- if (mapping_key_)
- return *mapping_key_;
- else
- return base_symbol();
- }
-
optional<std::size_t> graph_index() const {;
return base->graph_index;
}
@@ -267,23 +260,36 @@ public:
base->larger = arg;
}
+ virtual optional<expr_t> value_expr() const {
+ return base->value_expr;
+ }
+ void set_value_expr(const optional<expr_t>& expr = none) {
+ base->value_expr = expr;
+ }
+
void add_price(const datetime_t& date, const amount_t& price,
const bool reflexive = true);
void remove_price(const datetime_t& date, commodity_t& commodity);
void map_prices(function<void(datetime_t, const amount_t&)> fn,
- const optional<datetime_t>& moment = none,
- const optional<datetime_t>& _oldest = none);
+ const datetime_t& moment = datetime_t(),
+ const datetime_t& _oldest = datetime_t());
+
+ optional<price_point_t>
+ find_price_from_expr(expr_t& expr, const commodity_t * commodity,
+ const datetime_t& moment) const;
optional<price_point_t>
- find_price(const optional<commodity_t&>& commodity = none,
- const optional<datetime_t>& moment = none,
- const optional<datetime_t>& oldest = none) const;
+ virtual find_price(const commodity_t * commodity = NULL,
+ const datetime_t& moment = datetime_t(),
+ const datetime_t& oldest = datetime_t()) const;
optional<price_point_t>
check_for_updated_price(const optional<price_point_t>& point,
- const optional<datetime_t>& moment,
- const optional<commodity_t&>& in_terms_of);
+ const datetime_t& moment,
+ const commodity_t * in_terms_of);
+
+ commodity_t& nail_down(const expr_t& expr);
// Methods related to parsing, reading, writing, etc., the commodity
// itself.
@@ -325,7 +331,6 @@ private:
ar & base;
ar & parent_;
ar & qualified_symbol;
- ar & mapping_key_;
ar & annotated;
}
#endif // HAVE_BOOST_SERIALIZATION