summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-14 04:40:39 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-14 04:40:39 -0400
commit47e91a8a92b5b86944af3190680e5cfdcf562ef1 (patch)
treec2ac5a123a9a976f989be0c73ff86e9f9b7e8643
parentc2a77c12377e6dcecb9ba50274a3896412f5eaaf (diff)
downloadfork-ledger-47e91a8a92b5b86944af3190680e5cfdcf562ef1.tar.gz
fork-ledger-47e91a8a92b5b86944af3190680e5cfdcf562ef1.tar.bz2
fork-ledger-47e91a8a92b5b86944af3190680e5cfdcf562ef1.zip
Added initial implementation of lot_*() functions
-rw-r--r--src/session.cc35
-rw-r--r--src/session.h3
2 files changed, 37 insertions, 1 deletions
diff --git a/src/session.cc b/src/session.cc
index 3b043952..85b5fab2 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -194,12 +194,36 @@ value_t session_t::fn_min(call_scope_t& args)
{
return args[1] < args[0] ? args[1] : args[0];
}
-
value_t session_t::fn_max(call_scope_t& args)
{
return args[1] > args[0] ? args[1] : args[0];
}
+value_t session_t::fn_lot_price(call_scope_t& args)
+{
+ amount_t amt(args.get<amount_t>(1, false));
+ if (amt.has_annotation() && amt.annotation().price)
+ return *amt.annotation().price;
+ else
+ return NULL_VALUE;
+}
+value_t session_t::fn_lot_date(call_scope_t& args)
+{
+ amount_t amt(args.get<amount_t>(1, false));
+ if (amt.has_annotation() && amt.annotation().date)
+ return *amt.annotation().date;
+ else
+ return NULL_VALUE;
+}
+value_t session_t::fn_lot_tag(call_scope_t& args)
+{
+ amount_t amt(args.get<amount_t>(1, false));
+ if (amt.has_annotation() && amt.annotation().tag)
+ return string_value(*amt.annotation().tag);
+ else
+ return NULL_VALUE;
+}
+
option_t<session_t> * session_t::lookup_option(const char * p)
{
switch (*p) {
@@ -252,6 +276,15 @@ expr_t::ptr_op_t session_t::lookup(const symbol_t::kind_t kind,
return MAKE_FUNCTOR(session_t::fn_account);
break;
+ case 'l':
+ if (is_eq(p, "lot_price"))
+ return MAKE_FUNCTOR(session_t::fn_lot_price);
+ else if (is_eq(p, "lot_date"))
+ return MAKE_FUNCTOR(session_t::fn_lot_date);
+ else if (is_eq(p, "lot_tag"))
+ return MAKE_FUNCTOR(session_t::fn_lot_tag);
+ break;
+
case 'm':
if (is_eq(p, "min"))
return MAKE_FUNCTOR(session_t::fn_min);
diff --git a/src/session.h b/src/session.h
index d52a1e49..6de4b2dd 100644
--- a/src/session.h
+++ b/src/session.h
@@ -76,6 +76,9 @@ public:
value_t fn_account(call_scope_t& scope);
value_t fn_min(call_scope_t& scope);
value_t fn_max(call_scope_t& scope);
+ value_t fn_lot_price(call_scope_t& scope);
+ value_t fn_lot_date(call_scope_t& scope);
+ value_t fn_lot_tag(call_scope_t& scope);
void report_options(std::ostream& out)
{