diff options
-rw-r--r-- | src/amount.cc | 4 | ||||
-rw-r--r-- | src/annotate.cc | 6 | ||||
-rw-r--r-- | src/commodity.cc | 12 | ||||
-rw-r--r-- | src/commodity.h | 16 | ||||
-rw-r--r-- | src/pool.cc | 2 | ||||
-rw-r--r-- | src/py_amount.cc | 3 | ||||
-rw-r--r-- | src/py_balance.cc | 3 | ||||
-rw-r--r-- | src/py_commodity.cc | 70 | ||||
-rw-r--r-- | src/py_utils.cc | 44 |
9 files changed, 122 insertions, 38 deletions
diff --git a/src/amount.cc b/src/amount.cc index 435cdea4..e9b971f8 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -770,7 +770,7 @@ commodity_t& amount_t::commodity() const bool amount_t::has_commodity() const { - return commodity_ && commodity_ != commodity_->parent().null_commodity; + return commodity_ && commodity_ != commodity_->pool().null_commodity; } void amount_t::annotate(const annotation_t& details) @@ -795,7 +795,7 @@ void amount_t::annotate(const annotation_t& details) << *this << std::endl << details); if (commodity_t * ann_comm = - this_base->parent().find_or_create(*this_base, details)) + this_base->pool().find_or_create(*this_base, details)) set_commodity(*ann_comm); #ifdef ASSERTS_ON else diff --git a/src/annotate.cc b/src/annotate.cc index 9c676086..45a4e7c8 100644 --- a/src/annotate.cc +++ b/src/annotate.cc @@ -185,12 +185,12 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep) (keep_date && details.date) || (keep_tag && details.tag)) { - new_comm = parent().find_or_create + new_comm = pool().find_or_create (referent(), annotation_t(keep_price ? details.price : none, keep_date ? details.date : none, keep_tag ? details.tag : none)); } else { - new_comm = parent().find_or_create(base_symbol()); + new_comm = pool().find_or_create(base_symbol()); } assert(new_comm); @@ -199,7 +199,7 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep) void annotated_commodity_t::write_annotations(std::ostream& out) const { - details.print(out, parent().keep_base); + details.print(out, pool().keep_base); } } // namespace ledger diff --git a/src/commodity.cc b/src/commodity.cc index d896572f..a0827e7a 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -375,7 +375,7 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point, const optional<datetime_t>& moment, const optional<commodity_t&>& in_terms_of) { - if (parent().get_quotes && ! has_flags(COMMODITY_NOMARKET)) { + if (pool().get_quotes && ! has_flags(COMMODITY_NOMARKET)) { bool exceeds_leeway = true; if (point) { @@ -389,8 +389,8 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point, DEBUG("commodity.download", "slip.now = " << seconds_diff); } - DEBUG("commodity.download", "leeway = " << parent().quote_leeway); - if (seconds_diff < parent().quote_leeway) + DEBUG("commodity.download", "leeway = " << pool().quote_leeway); + if (seconds_diff < pool().quote_leeway) exceeds_leeway = false; } @@ -398,7 +398,7 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point, DEBUG("commodity.download", "attempting to download a more current quote..."); if (optional<price_point_t> quote = - parent().get_commodity_quote(*this, in_terms_of)) { + pool().get_commodity_quote(*this, in_terms_of)) { if (! in_terms_of || (quote->price.has_commodity() && quote->price.commodity() == *in_terms_of)) @@ -411,7 +411,7 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point, commodity_t::operator bool() const { - return this != parent().null_commodity; + return this != pool().null_commodity; } bool commodity_t::symbol_needs_quotes(const string& symbol) @@ -568,7 +568,7 @@ void commodity_t::parse_symbol(char *& p, string& symbol) bool commodity_t::valid() const { - if (symbol().empty() && this != parent().null_commodity) { + if (symbol().empty() && this != pool().null_commodity) { DEBUG("ledger.validate", "commodity_t: symbol().empty() && this != null_commodity"); return false; diff --git a/src/commodity.h b/src/commodity.h index d30a0847..f65df1b9 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -245,30 +245,31 @@ public: operator bool() const; - static bool symbol_needs_quotes(const string& symbol); - - bool is_annotated() const { - return annotated; - } - virtual bool operator==(const commodity_t& comm) const { if (comm.annotated) return comm == *this; return base.get() == comm.base.get(); } + static bool symbol_needs_quotes(const string& symbol); + virtual commodity_t& referent() { return *this; } virtual const commodity_t& referent() const { return *this; } + + bool is_annotated() const { + return annotated; + } + virtual commodity_t& strip_annotations(const keep_details_t&) { return *this; } virtual void write_annotations(std::ostream&) const {} - commodity_pool_t& parent() const { + commodity_pool_t& pool() const { return *parent_; } @@ -329,7 +330,6 @@ public: optional<history_t&> history(const optional<commodity_t&>& commodity); -public: // These methods provide a transparent pass-through to the underlying // base->varied_history object. diff --git a/src/pool.cc b/src/pool.cc index 06a4706c..b08c8fad 100644 --- a/src/pool.cc +++ b/src/pool.cc @@ -118,7 +118,7 @@ string commodity_pool_t::make_qualified_name(const commodity_t& comm, std::ostringstream name; comm.print(name); - details.print(name, comm.parent().keep_base); + details.print(name, comm.pool().keep_base); DEBUG("amounts.commodities", "make_qualified_name for " << *comm.qualified_symbol << std::endl << details); diff --git a/src/py_amount.cc b/src/py_amount.cc index efae7514..c6b3284a 100644 --- a/src/py_amount.cc +++ b/src/py_amount.cc @@ -282,9 +282,6 @@ internal precision.")) .def("parse_conversion", &amount_t::parse_conversion) .staticmethod("parse_conversion") - .def("print_", py_print) - .def("dump", &amount_t::dump) - .def("valid", &amount_t::valid) ; diff --git a/src/py_balance.cc b/src/py_balance.cc index 2d940876..effc6937 100644 --- a/src/py_balance.cc +++ b/src/py_balance.cc @@ -211,9 +211,6 @@ void export_balance() .def("strip_annotations", &balance_t::strip_annotations) - .def("print_", py_print) - .def("dump", &balance_t::dump) - .def("valid", &balance_t::valid) ; diff --git a/src/py_commodity.cc b/src/py_commodity.cc index a39d1408..78c6ce2c 100644 --- a/src/py_commodity.cc +++ b/src/py_commodity.cc @@ -40,13 +40,6 @@ namespace ledger { using namespace boost::python; -void py_add_price(commodity_t& commodity, - const datetime_t& date, - const amount_t& price) -{ - commodity.add_price(date, price); -} - namespace { commodity_t * py_create_1(commodity_pool_t& pool, @@ -106,6 +99,16 @@ namespace { return pool.exchange(amount, cost, is_per_unit, moment, tag); } + void py_add_price_2(commodity_t& commodity, + const datetime_t& date, const amount_t& price) { + commodity.add_price(date, price); + } + + void py_add_price_3(commodity_t& commodity, const datetime_t& date, + const amount_t& price, const bool reflexive) { + commodity.add_price(date, price, reflexive); + } + } // unnamed namespace void export_commodity() @@ -170,18 +173,61 @@ void export_commodity() scope().attr("COMMODITY_KNOWN") = COMMODITY_KNOWN; scope().attr("COMMODITY_PRIMARY") = COMMODITY_PRIMARY; - class_< commodity_t, bases<>, - commodity_t, boost::noncopyable > ("Commodity", no_init) + class_< commodity_t, boost::noncopyable > ("Commodity", no_init) +#if 1 + .def("flags", &delegates_flags<uint_least16_t>::flags) + .def("has_flags", &delegates_flags<uint_least16_t>::has_flags) + .def("set_flags", &delegates_flags<uint_least16_t>::set_flags) + .def("clear_flags", &delegates_flags<uint_least16_t>::clear_flags) + .def("add_flags", &delegates_flags<uint_least16_t>::add_flags) + .def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags) +#endif + + .add_static_property("european_by_default", + make_getter(&commodity_t::european_by_default), + make_setter(&commodity_t::european_by_default)) + + .def("__nonzero__", &commodity_t::operator bool) + + .def(self == self) + .def("symbol_needs_quotes", &commodity_t::symbol_needs_quotes) .staticmethod("symbol_needs_quotes") - .def(self == self) +#if 0 + .def("referent", &commodity_t::referent, + return_value_policy<reference_existing_object>()) +#endif + + .def("is_annotated", &commodity_t::is_annotated) + .def("strip_annotations", &commodity_t::strip_annotations, + return_value_policy<reference_existing_object>()) + .def("write_annotations", &commodity_t::write_annotations) - .def("drop_flags", &commodity_t::drop_flags) + .def("pool", &commodity_t::pool, + return_value_policy<reference_existing_object>()) - .def("add_price", py_add_price) + .def("base_symbol", &commodity_t::base_symbol) + .def("symbol", &commodity_t::symbol) + .def("mapping_key", &commodity_t::mapping_key) + .def("name", &commodity_t::name) + .def("set_name", &commodity_t::set_name) + .def("note", &commodity_t::note) + .def("set_note", &commodity_t::set_note) .def("precision", &commodity_t::precision) + .def("set_precision", &commodity_t::set_precision) + .def("smaller", &commodity_t::smaller) + .def("set_smaller", &commodity_t::set_smaller) + .def("larger", &commodity_t::larger) + .def("set_larger", &commodity_t::set_larger) + + .def("add_price", py_add_price_2) + .def("add_price", py_add_price_3) + .def("remove_price", &commodity_t::remove_price, + with_custodian_and_ward<1, 3>()) + .def("find_price", &commodity_t::find_price) + .def("check_for_updated_price", &commodity_t::check_for_updated_price) ; #if 0 diff --git a/src/py_utils.cc b/src/py_utils.cc index cf98c5fe..3e788442 100644 --- a/src/py_utils.cc +++ b/src/py_utils.cc @@ -164,6 +164,50 @@ typedef register_python_conversion<std::ostream, ostream_to_python, ostream_from void export_utils() { + class_< supports_flags<uint_least8_t> > ("SupportFlags8") + .def(init<supports_flags<uint_least8_t> >()) + .def(init<uint_least8_t>()) + + .def("flags", &supports_flags<uint_least8_t>::flags) + .def("has_flags", &supports_flags<uint_least8_t>::has_flags) + .def("set_flags", &supports_flags<uint_least8_t>::set_flags) + .def("clear_flags", &supports_flags<uint_least8_t>::clear_flags) + .def("add_flags", &supports_flags<uint_least8_t>::add_flags) + .def("drop_flags", &supports_flags<uint_least8_t>::drop_flags) + ; + + class_< supports_flags<uint_least16_t> > ("SupportFlags16") + .def(init<supports_flags<uint_least16_t> >()) + .def(init<uint_least16_t>()) + + .def("flags", &supports_flags<uint_least16_t>::flags) + .def("has_flags", &supports_flags<uint_least16_t>::has_flags) + .def("set_flags", &supports_flags<uint_least16_t>::set_flags) + .def("clear_flags", &supports_flags<uint_least16_t>::clear_flags) + .def("add_flags", &supports_flags<uint_least16_t>::add_flags) + .def("drop_flags", &supports_flags<uint_least16_t>::drop_flags) + ; + +#if 0 + class_< basic_flags_t<uint_least8_t>, + bases<supports_flags<uint_least8_t> > > ("BasicFlags8") + .def(init<uint_least8_t>()) + + .def("plus_flags", &basic_flags_t<uint_least8_t>::plus_flags) + .def("minus_flags", &basic_flags_t<uint_least8_t>::minus_flags) + ; +#endif + + class_< delegates_flags<uint_least16_t>, + boost::noncopyable > ("DelegatesFlags16", no_init) + .def("flags", &delegates_flags<uint_least16_t>::flags) + .def("has_flags", &delegates_flags<uint_least16_t>::has_flags) + .def("set_flags", &delegates_flags<uint_least16_t>::set_flags) + .def("clear_flags", &delegates_flags<uint_least16_t>::clear_flags) + .def("add_flags", &delegates_flags<uint_least16_t>::add_flags) + .def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags) + ; + bool_python_conversion(); string_python_conversion(); istream_python_conversion(); |