summaryrefslogtreecommitdiff
path: root/src/py_amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-02 04:41:07 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-02 04:41:07 -0500
commit4e78dcff3f7aa9b829ce543022cf0f5f42769db9 (patch)
tree3b084ca8ec7156f3b90bb0d4c36243c3797c5de2 /src/py_amount.cc
parentf9b833b685251e0787a8282a256588328bd68ad7 (diff)
downloadfork-ledger-4e78dcff3f7aa9b829ce543022cf0f5f42769db9.tar.gz
fork-ledger-4e78dcff3f7aa9b829ce543022cf0f5f42769db9.tar.bz2
fork-ledger-4e78dcff3f7aa9b829ce543022cf0f5f42769db9.zip
Fixes to the Python bindings for amount_t
Diffstat (limited to 'src/py_amount.cc')
-rw-r--r--src/py_amount.cc102
1 files changed, 54 insertions, 48 deletions
diff --git a/src/py_amount.cc b/src/py_amount.cc
index 16e1807a..efae7514 100644
--- a/src/py_amount.cc
+++ b/src/py_amount.cc
@@ -42,59 +42,66 @@ namespace ledger {
using namespace boost::python;
-boost::optional<amount_t> py_value_0(const amount_t& amount) {
- return amount.value();
-}
-boost::optional<amount_t> py_value_1(const amount_t& amount,
- const bool primary_only) {
- return amount.value(primary_only);
-}
-boost::optional<amount_t> py_value_2(const amount_t& amount,
- const bool primary_only,
- const boost::optional<datetime_t>& moment) {
- return amount.value(primary_only, moment);
-}
-boost::optional<amount_t> py_value_3(const amount_t& amount,
- const bool primary_only,
- const boost::optional<datetime_t>& moment,
- const boost::optional<commodity_t&>& in_terms_of) {
- return amount.value(primary_only, moment, in_terms_of);
-}
+namespace {
-void py_parse_2(amount_t& amount, object in, unsigned char flags) {
- if (PyFile_Check(in.ptr())) {
- pyifstream instr(reinterpret_cast<PyFileObject *>(in.ptr()));
- amount.parse(instr, flags);
- } else {
- PyErr_SetString(PyExc_IOError,
- _("Argument to amount.parse(file) is not a file object"));
+ boost::optional<amount_t> py_value_0(const amount_t& amount) {
+ return amount.value();
+ }
+ boost::optional<amount_t> py_value_1(const amount_t& amount,
+ const bool primary_only) {
+ return amount.value(primary_only);
}
-}
-void py_parse_1(amount_t& amount, object in) {
- py_parse_2(amount, in, 0);
-}
-void py_parse_str_1(amount_t& amount, const string& str) {
- amount.parse(str);
-}
-void py_parse_str_2(amount_t& amount, const string& str, unsigned char flags) {
- amount.parse(str, flags);
-}
+ boost::optional<amount_t>
+ py_value_2(const amount_t& amount,
+ const bool primary_only,
+ const boost::optional<datetime_t>& moment) {
+ return amount.value(primary_only, moment);
+ }
-void py_print(amount_t& amount, object out)
-{
- if (PyFile_Check(out.ptr())) {
- pyofstream outstr(reinterpret_cast<PyFileObject *>(out.ptr()));
- amount.print(outstr);
- } else {
- PyErr_SetString(PyExc_IOError,
- _("Argument to amount.print_(file) is not a file object"));
+ boost::optional<amount_t>
+ py_value_3(const amount_t& amount,
+ const bool primary_only,
+ const boost::optional<datetime_t>& moment,
+ const boost::optional<commodity_t&>& in_terms_of) {
+ return amount.value(primary_only, moment, in_terms_of);
}
-}
-void py_amount_initialize() {
- amount_t::initialize();
-}
+ void py_parse_2(amount_t& amount, object in, unsigned char flags) {
+ if (PyFile_Check(in.ptr())) {
+ pyifstream instr(reinterpret_cast<PyFileObject *>(in.ptr()));
+ amount.parse(instr, flags);
+ } else {
+ PyErr_SetString(PyExc_IOError,
+ _("Argument to amount.parse(file) is not a file object"));
+ }
+ }
+ void py_parse_1(amount_t& amount, object in) {
+ py_parse_2(amount, in, 0);
+ }
+
+ void py_parse_str_1(amount_t& amount, const string& str) {
+ amount.parse(str);
+ }
+ void py_parse_str_2(amount_t& amount, const string& str, unsigned char flags) {
+ amount.parse(str, flags);
+ }
+
+ void py_print(amount_t& amount, object out) {
+ if (PyFile_Check(out.ptr())) {
+ pyofstream outstr(reinterpret_cast<PyFileObject *>(out.ptr()));
+ amount.print(outstr);
+ } else {
+ PyErr_SetString(PyExc_IOError,
+ _("Argument to amount.print_(file) is not a file object"));
+ }
+ }
+
+ void py_amount_initialize() {
+ amount_t::initialize();
+ }
+
+} // unnamed namespace
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
@@ -276,7 +283,6 @@ internal precision."))
.staticmethod("parse_conversion")
.def("print_", py_print)
-
.def("dump", &amount_t::dump)
.def("valid", &amount_t::valid)