Normalized the value() method for Python numerics
This commit is contained in:
parent
b00e7ac19a
commit
aa086686ea
3 changed files with 37 additions and 27 deletions
|
|
@ -44,13 +44,16 @@ using namespace boost::python;
|
|||
|
||||
namespace {
|
||||
|
||||
boost::optional<amount_t>
|
||||
py_value_1(const amount_t& amount, commodity_t& in_terms_of) {
|
||||
boost::optional<amount_t> py_value_0(const amount_t& amount) {
|
||||
return amount.value(false, CURRENT_TIME());
|
||||
}
|
||||
boost::optional<amount_t> py_value_1(const amount_t& amount,
|
||||
commodity_t& in_terms_of) {
|
||||
return amount.value(false, CURRENT_TIME(), in_terms_of);
|
||||
}
|
||||
boost::optional<amount_t>
|
||||
py_value_2(const amount_t& amount, commodity_t& in_terms_of,
|
||||
datetime_t& moment) {
|
||||
boost::optional<amount_t> py_value_2(const amount_t& amount,
|
||||
commodity_t& in_terms_of,
|
||||
datetime_t& moment) {
|
||||
return amount.value(false, moment, in_terms_of);
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +229,8 @@ internal precision."))
|
|||
.def("in_place_unreduce", &amount_t::in_place_unreduce,
|
||||
return_internal_reference<>())
|
||||
|
||||
.def("value", py_value_1, args("moment"))
|
||||
.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("price", &amount_t::price)
|
||||
|
|
|
|||
|
|
@ -45,28 +45,18 @@ using namespace boost::python;
|
|||
namespace {
|
||||
|
||||
boost::optional<balance_t> py_value_0(const balance_t& balance) {
|
||||
return balance.value();
|
||||
return balance.value(false, CURRENT_TIME());
|
||||
}
|
||||
boost::optional<balance_t> py_value_1(const balance_t& balance,
|
||||
const bool primary_only) {
|
||||
return balance.value(primary_only);
|
||||
commodity_t& in_terms_of) {
|
||||
return balance.value(false, CURRENT_TIME(), in_terms_of);
|
||||
}
|
||||
|
||||
boost::optional<balance_t>
|
||||
py_value_2(const balance_t& balance,
|
||||
const bool primary_only,
|
||||
const boost::optional<datetime_t>& moment) {
|
||||
return balance.value(primary_only, moment);
|
||||
boost::optional<balance_t> py_value_2(const balance_t& balance,
|
||||
commodity_t& in_terms_of,
|
||||
datetime_t& moment) {
|
||||
return balance.value(false, moment, in_terms_of);
|
||||
}
|
||||
|
||||
boost::optional<balance_t>
|
||||
py_value_3(const balance_t& balance,
|
||||
const bool primary_only,
|
||||
const boost::optional<datetime_t>& moment,
|
||||
const boost::optional<commodity_t&>& in_terms_of) {
|
||||
return balance.value(primary_only, moment, in_terms_of);
|
||||
}
|
||||
|
||||
|
||||
boost::optional<amount_t>
|
||||
py_commodity_amount_0(const balance_t& balance) {
|
||||
return balance.commodity_amount();
|
||||
|
|
@ -200,9 +190,8 @@ void export_balance()
|
|||
return_internal_reference<>())
|
||||
|
||||
.def("value", py_value_0)
|
||||
.def("value", py_value_1, args("primary_only"))
|
||||
.def("value", py_value_2, args("primary_only", "moment"))
|
||||
.def("value", py_value_3, args("primary_only", "moment", "in_terms_of"))
|
||||
.def("value", py_value_1, args("in_terms_of"))
|
||||
.def("value", py_value_2, args("in_terms_of", "moment"))
|
||||
|
||||
.def("price", &balance_t::price)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,19 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_overloads, set_string, 0, 2)
|
|||
|
||||
namespace {
|
||||
|
||||
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()) {
|
||||
|
|
@ -244,6 +257,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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue