summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/amount.h11
-rw-r--r--src/commodity.h11
-rw-r--r--src/py_amount.cc88
-rw-r--r--src/py_commodity.cc93
-rw-r--r--src/pyledger.cc12
5 files changed, 114 insertions, 101 deletions
diff --git a/src/amount.h b/src/amount.h
index 280613d7..e15c9704 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -76,11 +76,9 @@ class amount_t
ordered_field_operators<amount_t, unsigned long,
ordered_field_operators<amount_t, double> > > >
{
+ // jww (2007-05-03): Make this private, and then make
+ // ledger::initialize into a member function of session_t.
public:
- class bigint_t;
-
- typedef uint_least16_t precision_t;
-
/**
* The initialize and shutdown methods ready the amount subsystem
* for use. Normally they are called by `ledger::initialize' and
@@ -89,6 +87,11 @@ public:
static void initialize();
static void shutdown();
+public:
+ class bigint_t;
+
+ typedef uint_least16_t precision_t;
+
/**
* The default_pool is a static variable indicating which commodity
* pool should be used when none is specified.
diff --git a/src/commodity.h b/src/commodity.h
index 7b9a7be4..72ded1e4 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -45,15 +45,16 @@
namespace ledger {
+class annotated_commodity_t;
+
class commodity_t
: public equality_comparable1<commodity_t, noncopyable>
{
+ friend class commodity_pool_t;
+
class base_t : public noncopyable
{
- private:
- friend class commodity_pool_t;
- friend class commodity_t;
-
+ public:
typedef std::map<const moment_t, amount_t> history_map;
typedef std::pair<const moment_t, amount_t> history_pair;
@@ -285,7 +286,7 @@ public:
virtual bool operator==(const commodity_t& comm) const;
virtual bool operator==(const annotated_commodity_t& comm) const {
- return *this == static_cast<commodity_t&>(comm);
+ return *this == static_cast<const commodity_t&>(comm);
}
commodity_t& referent() {
diff --git a/src/py_amount.cc b/src/py_amount.cc
index f152ceb1..c1dd7649 100644
--- a/src/py_amount.cc
+++ b/src/py_amount.cc
@@ -7,42 +7,20 @@ namespace ledger {
using namespace boost::python;
-void py_parse_1(amount_t& amount, const string& str,
- unsigned char flags) {
+void py_parse_1(amount_t& amount, const string& str, unsigned char flags) {
amount.parse(str, flags);
}
void py_parse_2(amount_t& amount, const string& str) {
amount.parse(str);
}
-amount_t py_round_1(amount_t& amount, unsigned int prec) {
+amount_t py_round_1(const amount_t& amount, amount_t::precision_t prec) {
return amount.round(prec);
}
-amount_t py_round_2(amount_t& amount) {
+amount_t py_round_2(const amount_t& amount) {
return amount.round();
}
-#if 0
-struct commodity_updater_wrap : public commodity_base_t::updater_t
-{
- PyObject * self;
- commodity_updater_wrap(PyObject * self_) : self(self_) {}
-
- virtual void operator()(commodity_base_t& commodity,
- const moment_t& moment,
- const moment_t& date,
- const moment_t& last,
- amount_t& price) {
- call_method<void>(self, "__call__", commodity, moment, date, last, price);
- }
-};
-
-commodity_t * py_find_commodity(const string& symbol)
-{
- return commodity_t::find(symbol);
-}
-#endif
-
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
@@ -214,15 +192,16 @@ void export_amount()
.def("strip_annotations", &amount_t::strip_annotations)
#if 0
- .def("price", &amount_t::price)
- .def("date", &amount_t::date)
- .def("tag", &amount_t::tag)
+ // jww (2007-05-03): This method depends on annotation_t
+ .def("annotation_details", &amount_t::annotation_details)
#endif
+ // jww (2007-05-03): There are four versions of this method now
.def("parse", py_parse_1)
.def("parse", py_parse_2)
#if 0
+ // jww (2007-05-03): This method has two forms
.def("parse_conversion", &amount_t::parse_conversion)
.staticmethod("parse_conversion")
#endif
@@ -230,59 +209,6 @@ void export_amount()
.def("valid", &amount_t::valid)
;
-#if 0
- class_< commodity_base_t::updater_t, commodity_updater_wrap,
- boost::noncopyable >
- ("updater")
- ;
-#endif
-
- 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;
- scope().attr("COMMODITY_STYLE_BUILTIN") = COMMODITY_STYLE_BUILTIN;
-
-#if 0
- class_< commodity_t > ("commodity")
- .add_property("symbol", &commodity_t::symbol)
-
- .add_property("name", &commodity_t::name, &commodity_t::set_name)
- .add_property("note", &commodity_t::note, &commodity_t::set_note)
- .add_property("precision", &commodity_t::precision,
- &commodity_t::set_precision)
- .add_property("flags", &commodity_t::flags, &commodity_t::set_flags)
- .add_property("add_flags", &commodity_t::add_flags)
- .add_property("drop_flags", &commodity_t::drop_flags)
- //.add_property("updater", &commodity_t::updater)
-
- .add_property("smaller",
- make_getter(&commodity_t::smaller,
- return_value_policy<reference_existing_object>()),
- make_setter(&commodity_t::smaller,
- return_value_policy<reference_existing_object>()))
- .add_property("larger",
- make_getter(&commodity_t::larger,
- return_value_policy<reference_existing_object>()),
- make_setter(&commodity_t::larger,
- return_value_policy<reference_existing_object>()))
-
- .def(self_ns::str(self))
-
- .def("find", py_find_commodity,
- return_value_policy<reference_existing_object>())
- .staticmethod("find")
-
- .def("add_price", &commodity_t::add_price)
- .def("remove_price", &commodity_t::remove_price)
- .def("value", &commodity_t::value)
-
- .def("valid", &commodity_t::valid)
- ;
-#endif
-
#define EXC_TRANSLATE(type) \
register_exception_translator<type>(&exc_translate_ ## type);
diff --git a/src/py_commodity.cc b/src/py_commodity.cc
new file mode 100644
index 00000000..eb94821f
--- /dev/null
+++ b/src/py_commodity.cc
@@ -0,0 +1,93 @@
+#include "pyinterp.h"
+#include "amount.h"
+
+#include <boost/python/exception_translator.hpp>
+
+namespace ledger {
+
+using namespace boost::python;
+
+struct commodity_updater_wrap : public commodity_base_t::updater_t
+{
+ PyObject * self;
+ commodity_updater_wrap(PyObject * self_) : self(self_) {}
+
+ virtual void operator()(commodity_base_t& commodity,
+ const moment_t& moment,
+ const moment_t& date,
+ const moment_t& last,
+ amount_t& price) {
+ call_method<void>(self, "__call__", commodity, moment, date, last, price);
+ }
+};
+
+commodity_t * py_find_commodity(const string& symbol)
+{
+ return commodity_t::find(symbol);
+}
+
+#define EXC_TRANSLATOR(type) \
+ void exc_translate_ ## type(const type& err) { \
+ PyErr_SetString(PyExc_ArithmeticError, err.what()); \
+ }
+
+EXC_TRANSLATOR(commodity_error)
+
+void export_commodity()
+{
+ class_< commodity_base_t::updater_t, commodity_updater_wrap,
+ boost::noncopyable >
+ ("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;
+ scope().attr("COMMODITY_STYLE_BUILTIN") = COMMODITY_STYLE_BUILTIN;
+
+ class_< commodity_t > ("commodity")
+ .add_property("symbol", &commodity_t::symbol)
+
+ .add_property("name", &commodity_t::name, &commodity_t::set_name)
+ .add_property("note", &commodity_t::note, &commodity_t::set_note)
+ .add_property("precision", &commodity_t::precision,
+ &commodity_t::set_precision)
+ .add_property("flags", &commodity_t::flags, &commodity_t::set_flags)
+ .add_property("add_flags", &commodity_t::add_flags)
+ .add_property("drop_flags", &commodity_t::drop_flags)
+ //.add_property("updater", &commodity_t::updater)
+
+ .add_property("smaller",
+ make_getter(&commodity_t::smaller,
+ return_value_policy<reference_existing_object>()),
+ make_setter(&commodity_t::smaller,
+ return_value_policy<reference_existing_object>()))
+ .add_property("larger",
+ make_getter(&commodity_t::larger,
+ return_value_policy<reference_existing_object>()),
+ make_setter(&commodity_t::larger,
+ return_value_policy<reference_existing_object>()))
+
+ .def(self_ns::str(self))
+
+ .def("find", py_find_commodity,
+ return_value_policy<reference_existing_object>())
+ .staticmethod("find")
+
+ .def("add_price", &commodity_t::add_price)
+ .def("remove_price", &commodity_t::remove_price)
+ .def("value", &commodity_t::value)
+
+ .def("valid", &commodity_t::valid)
+ ;
+
+#define EXC_TRANSLATE(type) \
+ register_exception_translator<type>(&exc_translate_ ## type);
+
+ EXC_TRANSLATE(commodity_error);
+}
+
+} // namespace ledger
diff --git a/src/pyledger.cc b/src/pyledger.cc
index 688374a6..08e6dbd1 100644
--- a/src/pyledger.cc
+++ b/src/pyledger.cc
@@ -8,7 +8,6 @@ void export_amount();
#if 0
void export_balance();
void export_value();
-
void export_journal();
void export_parser();
void export_option();
@@ -16,8 +15,6 @@ void export_walk();
void export_report();
void export_format();
void export_valexpr();
-
-void shutdown_option();
#endif
void initialize_for_python()
@@ -26,7 +23,6 @@ void initialize_for_python()
#if 0
export_balance();
export_value();
-
export_journal();
export_parser();
export_option();
@@ -37,18 +33,12 @@ void initialize_for_python()
#endif
}
-void shutdown_for_python()
-{
-#if 0
- shutdown_option();
-#endif
-}
-
}
ledger::session_t python_session;
BOOST_PYTHON_MODULE(ledger)
{
+ ledger::initialize_for_python();
ledger::set_session_context(&python_session);
}