diff options
Diffstat (limited to 'src/py_value.cc')
-rw-r--r-- | src/py_value.cc | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/src/py_value.cc b/src/py_value.cc index ee039519..713dc3d4 100644 --- a/src/py_value.cc +++ b/src/py_value.cc @@ -47,7 +47,21 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_overloads, set_string, 0, 2) namespace { - PyObject * py_base_type(value_t& value) { + boost::optional<value_t> py_value_0(const value_t& value) { + return value.value(false, CURRENT_TIME()); + } + boost::optional<value_t> py_value_1(const value_t& value, + commodity_t& in_terms_of) { + return value.value(false, CURRENT_TIME(), in_terms_of); + } + boost::optional<value_t> py_value_2(const value_t& value, + commodity_t& in_terms_of, + datetime_t& moment) { + return value.value(false, moment, in_terms_of); + } + + PyObject * py_base_type(value_t& value) + { if (value.is_boolean()) { return (PyObject *)&PyBool_Type; } @@ -63,16 +77,6 @@ namespace { } } - expr_t py_value_getattr(const value_t& value, const string& name) - { - if (value.is_scope()) { - if (scope_t * scope = value.as_scope()) - return expr_t(scope->lookup(symbol_t::FUNCTION, name), scope); - } - throw_(value_error, _("Cannot lookup attributes in %1") << value.label()); - return expr_t(); - } - string py_dump(const value_t& value) { std::ostringstream buf; value.dump(buf); @@ -85,8 +89,23 @@ namespace { return buf.str(); } - void py_set_string(value_t& amount, const string& str) { - return amount.set_string(str); + void py_set_string(value_t& value, const string& str) { + return value.set_string(str); + } + + annotation_t& py_value_annotation(value_t& value) { + return value.annotation(); + } + + value_t py_strip_annotations_0(value_t& value) { + return value.strip_annotations(keep_details_t()); + } + value_t py_strip_annotations_1(value_t& value, const keep_details_t& keep) { + return value.strip_annotations(keep); + } + + PyObject * py_value_unicode(value_t& value) { + return str_to_py_unicode(value.to_string()); } } // unnamed namespace @@ -101,16 +120,16 @@ EXC_TRANSLATOR(value_error) void export_value() { enum_< value_t::type_t >("ValueType") - .value("VOID", value_t::VOID) - .value("BOOLEAN", value_t::BOOLEAN) - .value("DATETIME", value_t::DATETIME) - .value("DATE", value_t::DATE) - .value("INTEGER", value_t::INTEGER) - .value("AMOUNT", value_t::AMOUNT) - .value("BALANCE", value_t::BALANCE) - .value("STRING", value_t::STRING) - .value("SEQUENCE", value_t::SEQUENCE) - .value("SCOPE", value_t::SCOPE) + .value("Void", value_t::VOID) + .value("Boolean", value_t::BOOLEAN) + .value("DateTime", value_t::DATETIME) + .value("Date", value_t::DATE) + .value("Integer", value_t::INTEGER) + .value("Amount", value_t::AMOUNT) + .value("Balance", value_t::BALANCE) + .value("String", value_t::STRING) + .value("Sequence", value_t::SEQUENCE) + .value("Scope", value_t::SCOPE) ; class_< value_t > ("Value") @@ -243,6 +262,10 @@ void export_value() .def("unreduced", &value_t::unreduced) .def("in_place_unreduce", &value_t::in_place_unreduce) + .def("value", py_value_0) + .def("value", py_value_1, args("in_terms_of")) + .def("value", py_value_2, args("in_terms_of", "moment")) + .def("value", &value_t::value, value_overloads()) .def("price", &value_t::price) .def("exchange_commodities", &value_t::exchange_commodities, @@ -291,11 +314,13 @@ void export_value() .def("to_date", &value_t::to_date) .def("to_amount", &value_t::to_amount) .def("to_balance", &value_t::to_balance) + .def("__str__", &value_t::to_string) + .def("__unicode__", py_value_unicode) .def("to_string", &value_t::to_string) .def("to_mask", &value_t::to_mask) .def("to_sequence", &value_t::to_sequence) - .def("__str__", py_dump_relaxed) + .def("__unicode__", py_dump_relaxed) .def("__repr__", py_dump) .def("casted", &value_t::casted) @@ -306,16 +331,16 @@ void export_value() .def("number", &value_t::number) .def("annotate", &value_t::annotate) - .def("is_annotated", &value_t::is_annotated) -#if 0 - .def("annotation", &value_t::annotation) -#endif - .def("strip_annotations", &value_t::strip_annotations) + .def("has_annotation", &value_t::has_annotation) + .add_property("annotation", + make_function(py_value_annotation, + return_internal_reference<>())) + .def("strip_annotations", py_strip_annotations_0) + .def("strip_annotations", py_strip_annotations_1) #if 0 .def("__getitem__", &value_t::operator[]) #endif - .def("__getattr__", py_value_getattr) .def("push_back", &value_t::push_back) .def("pop_back", &value_t::pop_back) .def("size", &value_t::size) |