diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-04 13:41:23 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:38 -0400 |
commit | 0528a1e49a82221e63039abc7f759a43f4d4ffc9 (patch) | |
tree | e433db931847f003aef895ea255a2c541057bd3f /src/py_amount.cc | |
parent | 96684b72ca367bfd4dbe2e45a9a66c56204eb533 (diff) | |
download | fork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.tar.gz fork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.tar.bz2 fork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.zip |
Added boost::optional support for using with Boost.Python.
Diffstat (limited to 'src/py_amount.cc')
-rw-r--r-- | src/py_amount.cc | 19 |
1 files changed, 18 insertions, 1 deletions
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 <boost/python/exception_translator.hpp> +#include <boost/python/implicit.hpp> namespace ledger { @@ -21,6 +23,14 @@ amount_t py_round_2(const amount_t& amount) { return amount.round(); } +boost::optional<amount_t> py_value_1(const amount_t& amount, + const boost::optional<moment_t>& moment) { + return amount.value(moment); +} +boost::optional<amount_t> 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<reference_existing_object>()) - .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<amount_t>(); + + implicitly_convertible<double, amount_t>(); + implicitly_convertible<long, amount_t>(); + implicitly_convertible<string, amount_t>(); + #define EXC_TRANSLATE(type) \ register_exception_translator<type>(&exc_translate_ ## type); |