Fixes to the Python bindings for amount_t
This commit is contained in:
parent
f9b833b685
commit
4e78dcff3f
1 changed files with 56 additions and 50 deletions
|
|
@ -42,26 +42,32 @@ namespace ledger {
|
||||||
|
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
|
||||||
boost::optional<amount_t> py_value_0(const amount_t& amount) {
|
namespace {
|
||||||
|
|
||||||
|
boost::optional<amount_t> py_value_0(const amount_t& amount) {
|
||||||
return amount.value();
|
return amount.value();
|
||||||
}
|
}
|
||||||
boost::optional<amount_t> py_value_1(const amount_t& amount,
|
boost::optional<amount_t> py_value_1(const amount_t& amount,
|
||||||
const bool primary_only) {
|
const bool primary_only) {
|
||||||
return amount.value(primary_only);
|
return amount.value(primary_only);
|
||||||
}
|
}
|
||||||
boost::optional<amount_t> py_value_2(const amount_t& amount,
|
|
||||||
|
boost::optional<amount_t>
|
||||||
|
py_value_2(const amount_t& amount,
|
||||||
const bool primary_only,
|
const bool primary_only,
|
||||||
const boost::optional<datetime_t>& moment) {
|
const boost::optional<datetime_t>& moment) {
|
||||||
return amount.value(primary_only, moment);
|
return amount.value(primary_only, moment);
|
||||||
}
|
}
|
||||||
boost::optional<amount_t> py_value_3(const amount_t& amount,
|
|
||||||
|
boost::optional<amount_t>
|
||||||
|
py_value_3(const amount_t& amount,
|
||||||
const bool primary_only,
|
const bool primary_only,
|
||||||
const boost::optional<datetime_t>& moment,
|
const boost::optional<datetime_t>& moment,
|
||||||
const boost::optional<commodity_t&>& in_terms_of) {
|
const boost::optional<commodity_t&>& in_terms_of) {
|
||||||
return amount.value(primary_only, moment, in_terms_of);
|
return amount.value(primary_only, moment, in_terms_of);
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_parse_2(amount_t& amount, object in, unsigned char flags) {
|
void py_parse_2(amount_t& amount, object in, unsigned char flags) {
|
||||||
if (PyFile_Check(in.ptr())) {
|
if (PyFile_Check(in.ptr())) {
|
||||||
pyifstream instr(reinterpret_cast<PyFileObject *>(in.ptr()));
|
pyifstream instr(reinterpret_cast<PyFileObject *>(in.ptr()));
|
||||||
amount.parse(instr, flags);
|
amount.parse(instr, flags);
|
||||||
|
|
@ -69,20 +75,19 @@ void py_parse_2(amount_t& amount, object in, unsigned char flags) {
|
||||||
PyErr_SetString(PyExc_IOError,
|
PyErr_SetString(PyExc_IOError,
|
||||||
_("Argument to amount.parse(file) is not a file object"));
|
_("Argument to amount.parse(file) is not a file object"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void py_parse_1(amount_t& amount, object in) {
|
void py_parse_1(amount_t& amount, object in) {
|
||||||
py_parse_2(amount, in, 0);
|
py_parse_2(amount, in, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_parse_str_1(amount_t& amount, const string& str) {
|
void py_parse_str_1(amount_t& amount, const string& str) {
|
||||||
amount.parse(str);
|
amount.parse(str);
|
||||||
}
|
}
|
||||||
void py_parse_str_2(amount_t& amount, const string& str, unsigned char flags) {
|
void py_parse_str_2(amount_t& amount, const string& str, unsigned char flags) {
|
||||||
amount.parse(str, flags);
|
amount.parse(str, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_print(amount_t& amount, object out)
|
void py_print(amount_t& amount, object out) {
|
||||||
{
|
|
||||||
if (PyFile_Check(out.ptr())) {
|
if (PyFile_Check(out.ptr())) {
|
||||||
pyofstream outstr(reinterpret_cast<PyFileObject *>(out.ptr()));
|
pyofstream outstr(reinterpret_cast<PyFileObject *>(out.ptr()));
|
||||||
amount.print(outstr);
|
amount.print(outstr);
|
||||||
|
|
@ -90,11 +95,13 @@ void py_print(amount_t& amount, object out)
|
||||||
PyErr_SetString(PyExc_IOError,
|
PyErr_SetString(PyExc_IOError,
|
||||||
_("Argument to amount.print_(file) is not a file object"));
|
_("Argument to amount.print_(file) is not a file object"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void py_amount_initialize() {
|
void py_amount_initialize() {
|
||||||
amount_t::initialize();
|
amount_t::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
#define EXC_TRANSLATOR(type) \
|
#define EXC_TRANSLATOR(type) \
|
||||||
void exc_translate_ ## type(const type& err) { \
|
void exc_translate_ ## type(const type& err) { \
|
||||||
|
|
@ -276,7 +283,6 @@ internal precision."))
|
||||||
.staticmethod("parse_conversion")
|
.staticmethod("parse_conversion")
|
||||||
|
|
||||||
.def("print_", py_print)
|
.def("print_", py_print)
|
||||||
|
|
||||||
.def("dump", &amount_t::dump)
|
.def("dump", &amount_t::dump)
|
||||||
|
|
||||||
.def("valid", &amount_t::valid)
|
.def("valid", &amount_t::valid)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue