From 944c63e6f26d1f05ba6f63c60f510d3796872f3e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 23 Feb 2009 19:07:30 -0400 Subject: The Great Renaming, Part II The last commit did not contain the majority of changes because of a slight mishap. This contains the real changeset. --- python/py_entry.cc | 76 ------------------- python/py_journal.cc | 206 +++++++++++++++++++++++++-------------------------- python/py_post.cc | 64 ++++++++++++++++ python/py_timelog.cc | 2 +- python/py_xact.cc | 12 +++ python/pyinterp.cc | 10 +-- 6 files changed, 185 insertions(+), 185 deletions(-) delete mode 100644 python/py_entry.cc create mode 100644 python/py_post.cc (limited to 'python') diff --git a/python/py_entry.cc b/python/py_entry.cc deleted file mode 100644 index 8743886e..00000000 --- a/python/py_entry.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2003-2009, John Wiegley. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of New Artisans LLC nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "pyinterp.h" -#include "pyutils.h" -#include "entry.h" - -namespace ledger { - -using namespace boost::python; - -#define EXC_TRANSLATOR(type) \ - void exc_translate_ ## type(const type& err) { \ - PyErr_SetString(PyExc_ArithmeticError, err.what()); \ - } - -//EXC_TRANSLATOR(entry_error) - -void export_entry() -{ -#if 0 - class_< entry_base_t > ("EntryBase") - ; - class_< entry_t > ("Entry") - ; - struct_< entry_finalizer_t > ("EntryFinalizer") - ; - class_< auto_entry_t > ("AutoEntry") - ; - struct_< auto_entry_finalizer_t > ("AutoEntryFinalizer") - ; - class_< period_entry_t > ("PeriodEntry") - ; - class_< func_finalizer_t > ("FuncFinalizer") - ; -#endif - - //register_optional_to_python(); - - //implicitly_convertible(); - -#define EXC_TRANSLATE(type) \ - register_exception_translator(&exc_translate_ ## type); - - //EXC_TRANSLATE(entry_error); -} - -} // namespace ledger diff --git a/python/py_journal.cc b/python/py_journal.cc index 7f8d76c6..b0328844 100644 --- a/python/py_journal.cc +++ b/python/py_journal.cc @@ -64,57 +64,57 @@ void export_journal() } // namespace ledger #if 0 -entry_t& transaction_entry(const transaction_t& xact) +xact_t& post_xact(const post_t& post) { - return *xact.entry; + return *post.xact; } -unsigned int transactions_len(entry_base_t& entry) +unsigned int posts_len(xact_base_t& xact) { - return entry.transactions.size(); + return xact.posts.size(); } -transaction_t& transactions_getitem(entry_base_t& entry, int i) +post_t& posts_getitem(xact_base_t& xact, int i) { static int last_index = 0; - static entry_base_t * last_entry = NULL; - static transactions_list::iterator elem; + static xact_base_t * last_xact = NULL; + static posts_list::iterator elem; - std::size_t len = entry.transactions.size(); + std::size_t len = xact.posts.size(); if (abs(i) >= len) { PyErr_SetString(PyExc_IndexError, "Index out of range"); throw_error_already_set(); } - if (&entry == last_entry && i == last_index + 1) { + if (&xact == last_xact && i == last_index + 1) { last_index = i; return **++elem; } int x = i < 0 ? len + i : i; - elem = entry.transactions.begin(); + elem = xact.posts.begin(); while (--x >= 0) elem++; - last_entry = &entry; + last_xact = &xact; last_index = i; return **elem; } -unsigned int entries_len(journal_t& journal) +unsigned int xacts_len(journal_t& journal) { - return journal.entries.size(); + return journal.xacts.size(); } -entry_t& entries_getitem(journal_t& journal, int i) +xact_t& xacts_getitem(journal_t& journal, int i) { static int last_index = 0; static journal_t * last_journal = NULL; - static entries_list::iterator elem; + static xacts_list::iterator elem; - std::size_t len = journal.entries.size(); + std::size_t len = journal.xacts.size(); if (abs(i) >= len) { PyErr_SetString(PyExc_IndexError, "Index out of range"); @@ -127,7 +127,7 @@ entry_t& entries_getitem(journal_t& journal, int i) } int x = i < 0 ? len + i : i; - elem = journal.entries.begin(); + elem = journal.xacts.begin(); while (--x >= 0) elem++; @@ -192,58 +192,58 @@ account_t * py_find_account_2(journal_t& journal, const string& name, return journal.find_account(name, auto_create); } -bool py_add_entry(journal_t& journal, entry_t * entry) { - return journal.add_entry(new entry_t(*entry)); +bool py_add_xact(journal_t& journal, xact_t * xact) { + return journal.add_xact(new xact_t(*xact)); } -void py_add_transaction(entry_base_t& entry, transaction_t * xact) { - return entry.add_transaction(new transaction_t(*xact)); +void py_add_post(xact_base_t& xact, post_t * post) { + return xact.add_post(new post_t(*post)); } -struct entry_base_wrap : public entry_base_t +struct xact_base_wrap : public xact_base_t { PyObject * self; - entry_base_wrap(PyObject * self_) : self(self_) {} + xact_base_wrap(PyObject * self_) : self(self_) {} virtual bool valid() const { return call_method(self, "valid"); } }; -struct py_entry_finalizer_t : public entry_finalizer_t { +struct py_xact_finalizer_t : public xact_finalizer_t { object pyobj; - py_entry_finalizer_t() {} - py_entry_finalizer_t(object obj) : pyobj(obj) {} - py_entry_finalizer_t(const py_entry_finalizer_t& other) + py_xact_finalizer_t() {} + py_xact_finalizer_t(object obj) : pyobj(obj) {} + py_xact_finalizer_t(const py_xact_finalizer_t& other) : pyobj(other.pyobj) {} - virtual bool operator()(entry_t& entry, bool post) { - return call(pyobj.ptr(), entry, post); + virtual bool operator()(xact_t& xact, bool post) { + return call(pyobj.ptr(), xact, post); } }; -std::list py_finalizers; +std::list py_finalizers; -void py_add_entry_finalizer(journal_t& journal, object x) +void py_add_xact_finalizer(journal_t& journal, object x) { - py_finalizers.push_back(py_entry_finalizer_t(x)); - journal.add_entry_finalizer(&py_finalizers.back()); + py_finalizers.push_back(py_xact_finalizer_t(x)); + journal.add_xact_finalizer(&py_finalizers.back()); } -void py_remove_entry_finalizer(journal_t& journal, object x) +void py_remove_xact_finalizer(journal_t& journal, object x) { - for (std::list::iterator i = py_finalizers.begin(); + for (std::list::iterator i = py_finalizers.begin(); i != py_finalizers.end(); i++) if ((*i).pyobj == x) { - journal.remove_entry_finalizer(&(*i)); + journal.remove_xact_finalizer(&(*i)); py_finalizers.erase(i); return; } } -void py_run_entry_finalizers(journal_t& journal, entry_t& entry, bool post) +void py_run_xact_finalizers(journal_t& journal, xact_t& xact, bool post) { - run_hooks(journal.entry_finalize_hooks, entry, post); + run_hooks(journal.xact_finalize_hooks, xact, post); } #define EXC_TRANSLATOR(type) \ @@ -256,70 +256,70 @@ EXC_TRANSLATOR(interval_expr_error) EXC_TRANSLATOR(format_error) EXC_TRANSLATOR(parse_error) -value_t py_transaction_amount(transaction_t * xact) { - return value_t(xact->amount); +value_t py_post_amount(post_t * post) { + return value_t(post->amount); } -transaction_t::state_t py_entry_state(entry_t * entry) { - transaction_t::state_t state; - if (entry->get_state(&state)) +post_t::state_t py_xact_state(xact_t * xact) { + post_t::state_t state; + if (xact->get_state(&state)) return state; else - return transaction_t::UNCLEARED; + return post_t::UNCLEARED; } void export_journal() { - scope().attr("TRANSACTION_NORMAL") = TRANSACTION_NORMAL; - scope().attr("TRANSACTION_VIRTUAL") = TRANSACTION_VIRTUAL; - scope().attr("TRANSACTION_BALANCE") = TRANSACTION_BALANCE; - scope().attr("TRANSACTION_AUTO") = TRANSACTION_AUTO; - scope().attr("TRANSACTION_BULK_ALLOC") = TRANSACTION_BULK_ALLOC; - scope().attr("TRANSACTION_CALCULATED") = TRANSACTION_CALCULATED; - - enum_< transaction_t::state_t > ("State") - .value("Uncleared", transaction_t::UNCLEARED) - .value("Cleared", transaction_t::CLEARED) - .value("Pending", transaction_t::PENDING) + scope().attr("POST_NORMAL") = POST_NORMAL; + scope().attr("POST_VIRTUAL") = POST_VIRTUAL; + scope().attr("POST_BALANCE") = POST_BALANCE; + scope().attr("POST_AUTO") = POST_AUTO; + scope().attr("POST_BULK_ALLOC") = POST_BULK_ALLOC; + scope().attr("POST_CALCULATED") = POST_CALCULATED; + + enum_< post_t::state_t > ("State") + .value("Uncleared", post_t::UNCLEARED) + .value("Cleared", post_t::CLEARED) + .value("Pending", post_t::PENDING) ; - class_< transaction_t > ("Transaction") + class_< post_t > ("Post") .def(init >()) .def(init >()) .def(self == self) .def(self != self) - .add_property("entry", - make_getter(&transaction_t::entry, + .add_property("xact", + make_getter(&post_t::xact, return_value_policy())) .add_property("account", - make_getter(&transaction_t::account, + make_getter(&post_t::account, return_value_policy())) - .add_property("amount", &py_transaction_amount) - .def_readonly("amount_expr", &transaction_t::amount_expr) + .add_property("amount", &py_post_amount) + .def_readonly("amount_expr", &post_t::amount_expr) .add_property("cost", - make_getter(&transaction_t::cost, + make_getter(&post_t::cost, return_internal_reference<1>())) - .def_readonly("cost_expr", &transaction_t::cost_expr) + .def_readonly("cost_expr", &post_t::cost_expr) - .def_readwrite("state", &transaction_t::state) - .def_readwrite("flags", &transaction_t::flags) - .def_readwrite("note", &transaction_t::note) + .def_readwrite("state", &post_t::state) + .def_readwrite("flags", &post_t::flags) + .def_readwrite("note", &post_t::note) - .def_readonly("beg_pos", &transaction_t::beg_pos) - .def_readonly("beg_line", &transaction_t::beg_line) - .def_readonly("end_pos", &transaction_t::end_pos) - .def_readonly("end_line", &transaction_t::end_line) + .def_readonly("beg_pos", &post_t::beg_pos) + .def_readonly("beg_line", &post_t::beg_line) + .def_readonly("end_pos", &post_t::end_pos) + .def_readonly("end_line", &post_t::end_line) - .def("actual_date", &transaction_t::actual_date) - .def("effective_date", &transaction_t::effective_date) - .def("date", &transaction_t::date) + .def("actual_date", &post_t::actual_date) + .def("effective_date", &post_t::effective_date) + .def("date", &post_t::date) - .def("use_effective_date", &transaction_t::use_effective_date) + .def("use_effective_date", &post_t::use_effective_date) - .def("valid", &transaction_t::valid) + .def("valid", &post_t::valid) ; class_< account_t > @@ -360,8 +360,8 @@ void export_journal() .def(self == self) .def(self != self) - .def("__len__", entries_len) - .def("__getitem__", entries_getitem, return_internal_reference<1>()) + .def("__len__", xacts_len) + .def("__getitem__", xacts_getitem, return_internal_reference<1>()) .add_property("master", make_getter(&journal_t::master, return_internal_reference<1>())) @@ -380,50 +380,50 @@ void export_journal() .def("find_account_re", &journal_t::find_account_re, return_internal_reference<1>()) - .def("add_entry", py_add_entry) - .def("remove_entry", &journal_t::remove_entry) + .def("add_xact", py_add_xact) + .def("remove_xact", &journal_t::remove_xact) - .def("add_entry_finalizer", py_add_entry_finalizer) - .def("remove_entry_finalizer", py_remove_entry_finalizer) - .def("run_entry_finalizers", py_run_entry_finalizers) + .def("add_xact_finalizer", py_add_xact_finalizer) + .def("remove_xact_finalizer", py_remove_xact_finalizer) + .def("run_xact_finalizers", py_run_xact_finalizers) .def("valid", &journal_t::valid) ; - class_< entry_base_t, entry_base_wrap, boost::noncopyable > ("EntryBase") - .def("__len__", transactions_len) - .def("__getitem__", transactions_getitem, + class_< xact_base_t, xact_base_wrap, boost::noncopyable > ("XactBase") + .def("__len__", posts_len) + .def("__getitem__", posts_getitem, return_internal_reference<1>()) - .def_readonly("journal", &entry_base_t::journal) + .def_readonly("journal", &xact_base_t::journal) - .def_readonly("src_idx", &entry_base_t::src_idx) - .def_readonly("beg_pos", &entry_base_t::beg_pos) - .def_readonly("beg_line", &entry_base_t::beg_line) - .def_readonly("end_pos", &entry_base_t::end_pos) - .def_readonly("end_line", &entry_base_t::end_line) + .def_readonly("src_idx", &xact_base_t::src_idx) + .def_readonly("beg_pos", &xact_base_t::beg_pos) + .def_readonly("beg_line", &xact_base_t::beg_line) + .def_readonly("end_pos", &xact_base_t::end_pos) + .def_readonly("end_line", &xact_base_t::end_line) - .def("add_transaction", py_add_transaction) - .def("remove_transaction", &entry_base_t::remove_transaction) + .def("add_post", py_add_post) + .def("remove_post", &xact_base_t::remove_post) .def(self == self) .def(self != self) - .def("finalize", &entry_base_t::finalize) - .def("valid", &entry_base_t::valid) + .def("finalize", &xact_base_t::finalize) + .def("valid", &xact_base_t::valid) ; - class_< entry_t, bases > ("Entry") - .add_property("date", &entry_t::date) - .add_property("effective_date", &entry_t::effective_date) - .add_property("actual_date", &entry_t::actual_date) + class_< xact_t, bases > ("Xact") + .add_property("date", &xact_t::date) + .add_property("effective_date", &xact_t::effective_date) + .add_property("actual_date", &xact_t::actual_date) - .def_readwrite("code", &entry_t::code) - .def_readwrite("payee", &entry_t::payee) + .def_readwrite("code", &xact_t::code) + .def_readwrite("payee", &xact_t::payee) - .add_property("state", &py_entry_state) + .add_property("state", &py_xact_state) - .def("valid", &entry_t::valid) + .def("valid", &xact_t::valid) ; #define EXC_TRANSLATE(type) \ diff --git a/python/py_post.cc b/python/py_post.cc new file mode 100644 index 00000000..a60b79f9 --- /dev/null +++ b/python/py_post.cc @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2003-2009, John Wiegley. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of New Artisans LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "pyinterp.h" +#include "pyutils.h" +#include "post.h" + +namespace ledger { + +using namespace boost::python; + +#define EXC_TRANSLATOR(type) \ + void exc_translate_ ## type(const type& err) { \ + PyErr_SetString(PyExc_ArithmeticError, err.what()); \ + } + +//EXC_TRANSLATOR(post_error) + +void export_post() +{ +#if 0 + class_< post_t > ("Post") + ; +#endif + + //register_optional_to_python(); + + //implicitly_convertible(); + +#define EXC_TRANSLATE(type) \ + register_exception_translator(&exc_translate_ ## type); + + //EXC_TRANSLATE(post_error); +} + +} // namespace ledger diff --git a/python/py_timelog.cc b/python/py_timelog.cc index 127bf641..03416ec2 100644 --- a/python/py_timelog.cc +++ b/python/py_timelog.cc @@ -47,7 +47,7 @@ using namespace boost::python; void export_timelog() { #if 0 - class_< time_entry_t > ("TimeEntry") + class_< time_xact_t > ("TimeXact") ; class_< time_log_t > ("TimeLog") ; diff --git a/python/py_xact.cc b/python/py_xact.cc index fb5dbf8e..441d5741 100644 --- a/python/py_xact.cc +++ b/python/py_xact.cc @@ -47,8 +47,20 @@ using namespace boost::python; void export_xact() { #if 0 + class_< xact_base_t > ("XactBase") + ; class_< xact_t > ("Xact") ; + struct_< xact_finalizer_t > ("XactFinalizer") + ; + class_< auto_xact_t > ("AutoXact") + ; + struct_< auto_xact_finalizer_t > ("AutoXactFinalizer") + ; + class_< period_xact_t > ("PeriodXact") + ; + class_< func_finalizer_t > ("FuncFinalizer") + ; #endif //register_optional_to_python(); diff --git a/python/pyinterp.cc b/python/pyinterp.cc index cc6a5688..cd877f80 100644 --- a/python/pyinterp.cc +++ b/python/pyinterp.cc @@ -39,7 +39,7 @@ shared_ptr python_session; void export_chain(); void export_commodity(); -void export_entry(); +void export_xact(); void export_expr(); void export_flags(); void export_format(); @@ -53,13 +53,13 @@ void export_timelog(); void export_times(); void export_utils(); void export_value(); -void export_xact(); +void export_post(); void initialize_for_python() { export_chain(); export_commodity(); - export_entry(); + export_xact(); export_expr(); export_flags(); export_format(); @@ -73,7 +73,7 @@ void initialize_for_python() export_times(); export_utils(); export_value(); - export_xact(); + export_post(); } struct python_run @@ -132,7 +132,7 @@ object python_interpreter_t::import(const string& str) if (! mod) throw_(std::logic_error, "Failed to import Python module " << str); - // Import all top-level entries directly into the main namespace + // Import all top-level xacts directly into the main namespace main_nspace.update(mod.attr("__dict__")); TRACE_FINISH(python_import, 1); -- cgit v1.2.3