Added nail_down() for pinning market value exprs
This commit is contained in:
parent
17a84642fb
commit
21e8b7f6f0
4 changed files with 32 additions and 0 deletions
|
|
@ -217,6 +217,15 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point,
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commodity_t& commodity_t::nail_down(const expr_t& expr)
|
||||||
|
{
|
||||||
|
annotation_t new_details;
|
||||||
|
new_details.value_expr = expr;
|
||||||
|
commodity_t * new_comm =
|
||||||
|
commodity_pool_t::current_pool->find_or_create(symbol(), new_details);
|
||||||
|
return *new_comm;
|
||||||
|
}
|
||||||
|
|
||||||
commodity_t::operator bool() const
|
commodity_t::operator bool() const
|
||||||
{
|
{
|
||||||
return this != pool().null_commodity;
|
return this != pool().null_commodity;
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,8 @@ public:
|
||||||
const optional<datetime_t>& moment,
|
const optional<datetime_t>& moment,
|
||||||
const optional<commodity_t&>& in_terms_of);
|
const optional<commodity_t&>& in_terms_of);
|
||||||
|
|
||||||
|
commodity_t& nail_down(const expr_t& expr);
|
||||||
|
|
||||||
// Methods related to parsing, reading, writing, etc., the commodity
|
// Methods related to parsing, reading, writing, etc., the commodity
|
||||||
// itself.
|
// itself.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -736,6 +736,24 @@ value_t report_t::fn_commodity(call_scope_t& args)
|
||||||
return string_value(args.get<amount_t>(0).commodity().symbol());
|
return string_value(args.get<amount_t>(0).commodity().symbol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_t report_t::fn_nail_down(call_scope_t& args)
|
||||||
|
{
|
||||||
|
value_t arg0(args[0]);
|
||||||
|
switch (arg0.type()) {
|
||||||
|
case value_t::AMOUNT: {
|
||||||
|
amount_t tmp(arg0.as_amount());
|
||||||
|
if (tmp.has_commodity())
|
||||||
|
tmp.set_commodity(tmp.commodity()
|
||||||
|
.nail_down(args[1].as_any<expr_t::ptr_op_t>()));
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw_(std::runtime_error, _("Attempting to nail down %1")
|
||||||
|
<< args[0].label());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
value_t report_t::fn_lot_date(call_scope_t& args)
|
value_t report_t::fn_lot_date(call_scope_t& args)
|
||||||
{
|
{
|
||||||
if (args[0].has_annotation()) {
|
if (args[0].has_annotation()) {
|
||||||
|
|
@ -1261,6 +1279,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
return WRAP_FUNCTOR(fn_null);
|
return WRAP_FUNCTOR(fn_null);
|
||||||
else if (is_eq(p, "now"))
|
else if (is_eq(p, "now"))
|
||||||
return MAKE_FUNCTOR(report_t::fn_now);
|
return MAKE_FUNCTOR(report_t::fn_now);
|
||||||
|
else if (is_eq(p, "nail_down"))
|
||||||
|
return MAKE_FUNCTOR(report_t::fn_nail_down);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ public:
|
||||||
value_t fn_ansify_if(call_scope_t& scope);
|
value_t fn_ansify_if(call_scope_t& scope);
|
||||||
value_t fn_percent(call_scope_t& scope);
|
value_t fn_percent(call_scope_t& scope);
|
||||||
value_t fn_commodity(call_scope_t& scope);
|
value_t fn_commodity(call_scope_t& scope);
|
||||||
|
value_t fn_nail_down(call_scope_t& scope);
|
||||||
value_t fn_lot_date(call_scope_t& scope);
|
value_t fn_lot_date(call_scope_t& scope);
|
||||||
value_t fn_lot_price(call_scope_t& scope);
|
value_t fn_lot_price(call_scope_t& scope);
|
||||||
value_t fn_lot_tag(call_scope_t& scope);
|
value_t fn_lot_tag(call_scope_t& scope);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue