From 0528a1e49a82221e63039abc7f759a43f4d4ffc9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 4 May 2007 13:41:23 +0000 Subject: Added boost::optional support for using with Boost.Python. --- src/py_amount.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/py_amount.cc') diff --git a/src/py_amount.cc b/src/py_amount.cc index 61e3e4b5..c4f476c3 100644 --- a/src/py_amount.cc +++ b/src/py_amount.cc @@ -1,7 +1,9 @@ #include "pyinterp.h" +#include "pyutils.h" #include "amount.h" #include +#include namespace ledger { @@ -21,6 +23,14 @@ amount_t py_round_2(const amount_t& amount) { return amount.round(); } +boost::optional py_value_1(const amount_t& amount, + const boost::optional& moment) { + return amount.value(moment); +} +boost::optional py_value_2(const amount_t& amount) { + return amount.value(); +} + #define EXC_TRANSLATOR(type) \ void exc_translate_ ## type(const type& err) { \ PyErr_SetString(PyExc_ArithmeticError, err.what()); \ @@ -161,7 +171,8 @@ void export_amount() .def("in_place_unreduce", &amount_t::in_place_unreduce, return_value_policy()) - .def("value", &amount_t::value) + .def("value", py_value_1) + .def("value", py_value_2) .def("sign", &amount_t::sign) .def("__nonzero__", &amount_t::nonzero) @@ -213,6 +224,12 @@ void export_amount() .def("valid", &amount_t::valid) ; + python_optional(); + + implicitly_convertible(); + implicitly_convertible(); + implicitly_convertible(); + #define EXC_TRANSLATE(type) \ register_exception_translator(&exc_translate_ ## type); -- cgit v1.2.3