summaryrefslogtreecommitdiff
path: root/src/py_item.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-03 02:09:38 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-03 02:09:38 -0500
commited0e01812a1d604002f3ff23d3cbdffe60bd9297 (patch)
treef62cbcd2cb156b6c133304d444e657a8bf0d7432 /src/py_item.cc
parent3043faf79f6b3fa82c98066818e44f4d41ed2aa3 (diff)
downloadfork-ledger-ed0e01812a1d604002f3ff23d3cbdffe60bd9297.tar.gz
fork-ledger-ed0e01812a1d604002f3ff23d3cbdffe60bd9297.tar.bz2
fork-ledger-ed0e01812a1d604002f3ff23d3cbdffe60bd9297.zip
Added Python interface for item_t
Diffstat (limited to 'src/py_item.cc')
-rw-r--r--src/py_item.cc102
1 files changed, 95 insertions, 7 deletions
diff --git a/src/py_item.cc b/src/py_item.cc
index 0e1fe0f9..dbf5b6f7 100644
--- a/src/py_item.cc
+++ b/src/py_item.cc
@@ -32,11 +32,39 @@
#include <system.hh>
#include "pyinterp.h"
+#include "mask.h"
+#include "item.h"
namespace ledger {
using namespace boost::python;
+namespace {
+
+ bool py_has_tag_1s(item_t& item, const string& tag) {
+ return item.has_tag(tag);
+ }
+ bool py_has_tag_1m(item_t& item, const mask_t& tag_mask) {
+ return item.has_tag(tag_mask);
+ }
+ bool py_has_tag_2m(item_t& item, const mask_t& tag_mask,
+ const boost::optional<mask_t>& value_mask) {
+ return item.has_tag(tag_mask, value_mask);
+ }
+
+ boost::optional<string> py_get_tag_1s(item_t& item, const string& tag) {
+ return item.get_tag(tag);
+ }
+ boost::optional<string> py_get_tag_1m(item_t& item, const mask_t& tag_mask) {
+ return item.get_tag(tag_mask);
+ }
+ boost::optional<string> py_get_tag_2m(item_t& item, const mask_t& tag_mask,
+ const boost::optional<mask_t>& value_mask) {
+ return item.get_tag(tag_mask, value_mask);
+ }
+
+} // unnamed namespace
+
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_ArithmeticError, err.what()); \
@@ -46,19 +74,79 @@ using namespace boost::python;
void export_item()
{
-#if 0
- class_< item_t > ("Item")
+ class_< position_t > ("Position")
+ .add_property("pathname",
+ make_getter(&position_t::pathname),
+ make_setter(&position_t::pathname))
+ .add_property("beg_pos",
+ make_getter(&position_t::beg_pos),
+ make_setter(&position_t::beg_pos))
+ .add_property("beg_line",
+ make_getter(&position_t::beg_line),
+ make_setter(&position_t::beg_line))
+ .add_property("end_pos",
+ make_getter(&position_t::end_pos),
+ make_setter(&position_t::end_pos))
+ .add_property("end_line",
+ make_getter(&position_t::end_line),
+ make_setter(&position_t::end_line))
;
+
+ scope().attr("ITEM_NORMAL") = ITEM_NORMAL;
+ scope().attr("ITEM_GENERATED") = ITEM_GENERATED;
+ scope().attr("ITEM_TEMP") = ITEM_TEMP;
+
+ class_< item_t > ("Item", init<uint_least8_t>())
+#if 1
+ .def("flags", &supports_flags<>::flags)
+ .def("has_flags", &supports_flags<>::has_flags)
+ .def("set_flags", &supports_flags<>::set_flags)
+ .def("clear_flags", &supports_flags<>::clear_flags)
+ .def("add_flags", &supports_flags<>::add_flags)
+ .def("drop_flags", &supports_flags<>::drop_flags)
#endif
- //register_optional_to_python<amount_t>();
+ .add_property("note",
+ make_getter(&item_t::note),
+ make_setter(&item_t::note))
+ .add_property("pos",
+ make_getter(&item_t::pos),
+ make_setter(&item_t::pos))
+ .add_property("metadata",
+ make_getter(&item_t::metadata),
+ make_setter(&item_t::metadata))
+
+ .def("copy_details", &item_t::copy_details)
+
+ .def(self == self)
+ .def(self != self)
+
+ .def("has_tag", py_has_tag_1s)
+ .def("has_tag", py_has_tag_1m)
+ .def("has_tag", py_has_tag_2m)
+ .def("get_tag", py_get_tag_1s)
+ .def("get_tag", py_get_tag_1m)
+ .def("get_tag", py_get_tag_2m)
- //implicitly_convertible<string, amount_t>();
+ .def("set_tag", &item_t::set_tag)
-#define EXC_TRANSLATE(type) \
- register_exception_translator<type>(&exc_translate_ ## type);
+ .def("parse_tags", &item_t::parse_tags)
+ .def("append_note", &item_t::append_note)
- //EXC_TRANSLATE(item_error);
+ .add_static_property("use_effective_date",
+ make_getter(&item_t::use_effective_date),
+ make_setter(&item_t::use_effective_date))
+
+ .def("date", &item_t::date)
+ .def("effective_date", &item_t::effective_date)
+
+ .def("set_state", &item_t::set_state)
+ .def("state", &item_t::state)
+
+ .def("lookup", &item_t::lookup)
+
+ .def("valid", &item_t::valid)
+ ;
}
} // namespace ledger