improvements to python exposure of commodity_t
This commit is contained in:
parent
ff4589caae
commit
6c66d1e0ef
4 changed files with 32 additions and 12 deletions
30
amount.cc
30
amount.cc
|
|
@ -1056,6 +1056,16 @@ struct commodity_updater_wrap : public commodity_t::updater_t
|
|||
}
|
||||
};
|
||||
|
||||
commodity_t * py_find_commodity_1(const std::string& symbol)
|
||||
{
|
||||
return commodity_t::find_commodity(symbol);
|
||||
}
|
||||
|
||||
commodity_t * py_find_commodity_2(const std::string& symbol, bool auto_create)
|
||||
{
|
||||
return commodity_t::find_commodity(symbol, auto_create);
|
||||
}
|
||||
|
||||
void export_amount()
|
||||
{
|
||||
class_< amount_t > ("Amount")
|
||||
|
|
@ -1117,6 +1127,13 @@ void export_amount()
|
|||
("Updater")
|
||||
;
|
||||
|
||||
scope().attr("COMMODITY_STYLE_DEFAULTS") = COMMODITY_STYLE_DEFAULTS;
|
||||
scope().attr("COMMODITY_STYLE_SUFFIXED") = COMMODITY_STYLE_SUFFIXED;
|
||||
scope().attr("COMMODITY_STYLE_SEPARATED") = COMMODITY_STYLE_SEPARATED;
|
||||
scope().attr("COMMODITY_STYLE_EUROPEAN") = COMMODITY_STYLE_EUROPEAN;
|
||||
scope().attr("COMMODITY_STYLE_THOUSANDS") = COMMODITY_STYLE_THOUSANDS;
|
||||
scope().attr("COMMODITY_STYLE_NOMARKET") = COMMODITY_STYLE_NOMARKET;
|
||||
|
||||
class_< commodity_t > ("Commodity")
|
||||
.def(init<std::string, optional<unsigned int, unsigned int> >())
|
||||
|
||||
|
|
@ -1131,18 +1148,21 @@ void export_amount()
|
|||
.def_readwrite("ident", &commodity_t::ident)
|
||||
.def_readwrite("updater", &commodity_t::updater)
|
||||
|
||||
.def("add_commodity", &commodity_t::add_commodity)
|
||||
.def("remove_commodity", &commodity_t::remove_commodity)
|
||||
.def("find_commodity", &commodity_t::find_commodity,
|
||||
return_value_policy<reference_existing_object>())
|
||||
.def(self_ns::str(self))
|
||||
|
||||
.def("add_price", &commodity_t::add_price)
|
||||
.def("remove_price", &commodity_t::remove_price)
|
||||
.def("set_conversion", &commodity_t::set_conversion)
|
||||
.def("value", &commodity_t::value)
|
||||
|
||||
.def("valid", &commodity_t::valid)
|
||||
;
|
||||
|
||||
def("add_commodity", &commodity_t::add_commodity);
|
||||
def("remove_commodity", &commodity_t::remove_commodity);
|
||||
def("find_commodity", py_find_commodity_1,
|
||||
return_value_policy<reference_existing_object>());
|
||||
def("find_commodity", py_find_commodity_2,
|
||||
return_value_policy<reference_existing_object>());
|
||||
}
|
||||
|
||||
#endif // USE_BOOST_PYTHON
|
||||
|
|
|
|||
9
amount.h
9
amount.h
|
|
@ -346,10 +346,6 @@ class commodity_t
|
|||
return n > 0;
|
||||
}
|
||||
|
||||
void set_conversion(const amount_t& price) {
|
||||
conversion = price;
|
||||
}
|
||||
|
||||
amount_t value(const std::time_t moment = std::time(NULL));
|
||||
|
||||
bool valid() const {
|
||||
|
|
@ -369,6 +365,11 @@ class commodity_t
|
|||
}
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
|
||||
out << comm.symbol;
|
||||
return out;
|
||||
}
|
||||
|
||||
inline commodity_t& amount_t::commodity() const {
|
||||
if (! commodity_)
|
||||
return *commodity_t::null_commodity;
|
||||
|
|
|
|||
3
main.py
3
main.py
|
|
@ -37,6 +37,5 @@ for entry in journal:
|
|||
for xact in entry:
|
||||
handler (xact)
|
||||
|
||||
span = Interval ("weekly last month")
|
||||
for date in span:
|
||||
for date in Interval ("weekly last month"):
|
||||
print time.strftime ("%c", time.localtime (date))
|
||||
|
|
|
|||
|
|
@ -484,7 +484,7 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
|||
price.parse(skip_ws(line));
|
||||
|
||||
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
|
||||
commodity->set_conversion(price);
|
||||
commodity->conversion = price;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue