summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-02 03:05:35 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:36 -0400
commitfd1d109b29ce4a87acb33c0c01d6984f569e46b9 (patch)
tree9c6416a0f01b7287224241050801f9fc9ee96764 /src
parentde64861182dfc9b3deaaf95846997986bca41cd9 (diff)
downloadfork-ledger-fd1d109b29ce4a87acb33c0c01d6984f569e46b9.tar.gz
fork-ledger-fd1d109b29ce4a87acb33c0c01d6984f569e46b9.tar.bz2
fork-ledger-fd1d109b29ce4a87acb33c0c01d6984f569e46b9.zip
More organization of amount code.
Diffstat (limited to 'src')
-rw-r--r--src/main.cc4
-rw-r--r--src/py_amount.cc162
2 files changed, 99 insertions, 67 deletions
diff --git a/src/main.cc b/src/main.cc
index 99f1ff93..ade5b6a1 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -445,7 +445,7 @@ int main(int argc, char * argv[], char * envp[])
status = read_and_report(report.get(), argc, argv, envp);
- if (! ledger::do_cleanup) {
+ IF_VERIFY() {
report.release();
session.release();
}
@@ -480,7 +480,7 @@ int main(int argc, char * argv[], char * envp[])
status = _status;
}
- if (ledger::do_cleanup)
+ IF_VERIFY()
ledger::shutdown();
return status;
diff --git a/src/py_amount.cc b/src/py_amount.cc
index e39f32e0..c2d1291d 100644
--- a/src/py_amount.cc
+++ b/src/py_amount.cc
@@ -54,11 +54,68 @@ void export_amount()
scope().attr("AMOUNT_PARSE_NO_REDUCE") = AMOUNT_PARSE_NO_REDUCE;
class_< amount_t > ("amount")
- .def(init<amount_t>())
+ .def("initialize", &amount_t::initialize)
+ .staticmethod("initialize")
+ .def("shutdown", &amount_t::shutdown)
+ .staticmethod("shutdown")
+
+ .add_static_property("keep_base", &amount_t::keep_base)
+
+ .add_static_property("keep_price", &amount_t::keep_price)
+ .add_static_property("keep_date", &amount_t::keep_date)
+ .add_static_property("keep_tag", &amount_t::keep_tag)
+
+ .add_static_property("full_strings", &amount_t::full_strings)
+
+ .def(init<double>())
+ .def(init<long>())
.def(init<std::string>())
.def(init<char *>())
- .def(init<long>())
- .def(init<double>())
+
+ .def("exact", &amount_t::exact)
+ .staticmethod("exact")
+
+ .def(init<amount_t>())
+
+ .def("compare", &amount_t::compare)
+
+ .def(self == self)
+ .def(self == long())
+ .def(long() == self)
+ .def(self == double())
+ .def(double() == self)
+
+ .def(self != self)
+ .def(self != long())
+ .def(long() != self)
+ .def(self != double())
+ .def(double() != self)
+
+ .def(! self)
+
+ .def(self < self)
+ .def(self < long())
+ .def(long() < self)
+ .def(self < double())
+ .def(double() < self)
+
+ .def(self <= self)
+ .def(self <= long())
+ .def(long() <= self)
+ .def(self <= double())
+ .def(double() <= self)
+
+ .def(self > self)
+ .def(self > long())
+ .def(long() > self)
+ .def(self > double())
+ .def(double() > self)
+
+ .def(self >= self)
+ .def(self >= long())
+ .def(long() >= self)
+ .def(self >= double())
+ .def(double() >= self)
.def(self += self)
.def(self += long())
@@ -100,53 +157,46 @@ void export_amount()
.def(self / double())
.def(double() / self)
+ .def("negate", &amount_t::negate)
+ .def("in_place_negate", &amount_t::in_place_negate,
+ return_value_policy<reference_existing_object>())
.def(- self)
- .def(self < self)
- .def(self < long())
- .def(long() < self)
- .def(self < double())
- .def(double() < self)
-
- .def(self <= self)
- .def(self <= long())
- .def(long() <= self)
- .def(self <= double())
- .def(double() <= self)
+ .def("abs", &amount_t::abs)
+ .def("__abs__", &amount_t::abs)
- .def(self > self)
- .def(self > long())
- .def(long() > self)
- .def(self > double())
- .def(double() > self)
+ .def("round", py_round_1)
+ .def("round", py_round_2)
+ .def("unround", &amount_t::unround)
- .def(self >= self)
- .def(self >= long())
- .def(long() >= self)
- .def(self >= double())
- .def(double() >= self)
+ .def("reduce", &amount_t::reduce)
+ .def("in_place_reduce", &amount_t::in_place_reduce,
+ return_value_policy<reference_existing_object>())
- .def(self == self)
- .def(self == long())
- .def(long() == self)
- .def(self == double())
- .def(double() == self)
+ .def("unreduce", &amount_t::unreduce)
+ .def("in_place_unreduce", &amount_t::in_place_unreduce,
+ return_value_policy<reference_existing_object>())
- .def(self != self)
- .def(self != long())
- .def(long() != self)
- .def(self != double())
- .def(double() != self)
+ .def("value", &amount_t::value)
- .def(! self)
+ .def("sign", &amount_t::sign)
+ .def("__nonzero__", &amount_t::nonzero)
+ .def("nonzero", &amount_t::nonzero)
+ .def("zero", &amount_t::zero)
+ .def("realzero", &amount_t::realzero)
+ .def("is_null", &amount_t::is_null)
- .def("__int__", &amount_t::to_long)
+ .def("to_double", &amount_t::to_double)
.def("__float__", &amount_t::to_double)
- .def("__nonzero__", &amount_t::nonzero)
- .def("__abs__", &amount_t::abs)
+ .def("to_long", &amount_t::to_long)
+ .def("__int__", &amount_t::to_long)
+ .def("to_string", &amount_t::to_string)
.def("__str__", &amount_t::to_string)
+ .def("to_fullstring", &amount_t::to_fullstring)
.def("__repr__", &amount_t::to_fullstring)
+ .def("quantity_string", &amount_t::quantity_string)
+
.def("has_commodity", &amount_t::has_commodity)
.add_property("commodity",
@@ -155,41 +205,23 @@ void export_amount()
make_function(&amount_t::set_commodity,
with_custodian_and_ward<1, 2>()))
- .def("annotate_commodity", &amount_t::annotate_commodity)
- .def("strip_annotations", &amount_t::strip_annotations)
.def("clear_commodity", &amount_t::clear_commodity)
+ .def("number", &amount_t::number)
- //.add_static_property("full_strings", &amount_t::full_strings)
-
- .def("to_string", &amount_t::to_string)
- .def("to_fullstring", &amount_t::to_fullstring)
- .def("quantity_string", &amount_t::quantity_string)
-
- .def("exact", &amount_t::exact)
- .staticmethod("exact")
+ .def("annotate_commodity", &amount_t::annotate_commodity)
+ .def("strip_annotations", &amount_t::strip_annotations)
- .def("compare", &amount_t::compare)
+ .def("price", &amount_t::price)
.def("date", &amount_t::date)
- .def("negate", &amount_t::negate)
- .def("is_null", &amount_t::is_null)
+ .def("tag", &amount_t::tag)
+
.def("parse", py_parse_1)
.def("parse", py_parse_2)
- .def("price", &amount_t::price)
- .def("realzero", &amount_t::realzero)
- .def("reduce", &amount_t::reduce)
- .def("round", py_round_1)
- .def("round", py_round_2)
- .def("sign", &amount_t::sign)
- .def("unround", &amount_t::unround)
- .def("value", &amount_t::value)
- .def("zero", &amount_t::zero)
- .def("valid", &amount_t::valid)
+ .def("parse_conversion", &amount_t::parse_conversion)
+ .staticmethod("parse_conversion")
- .def("initialize", &amount_t::initialize)
- .staticmethod("initialize")
- .def("shutdown", &amount_t::shutdown)
- .staticmethod("shutdown")
+ .def("valid", &amount_t::valid)
;
class_< commodity_base_t::updater_t, commodity_updater_wrap,