diff options
-rw-r--r-- | amount.cc | 6 | ||||
-rw-r--r-- | amount.h | 30 | ||||
-rw-r--r-- | binary.cc | 6 | ||||
-rw-r--r-- | gnucash.cc | 12 | ||||
-rw-r--r-- | walk.cc | 13 |
5 files changed, 39 insertions, 28 deletions
@@ -1120,9 +1120,8 @@ void export_amount() class_< commodity_t > ("Commodity") .def(init<std::string, optional<unsigned int, unsigned int> >()) - // make this a function which called check_symbol after being set - .def_readwrite("symbol", &commodity_t::symbol) - .def_readwrite("quote", &commodity_t::quote) + .def_readonly("symbol", &commodity_t::symbol) + .def("set_symbol", &commodity_t::set_symbol) .def_readwrite("name", &commodity_t::name) .def_readwrite("note", &commodity_t::name) .def_readwrite("precision", &commodity_t::precision) @@ -1137,7 +1136,6 @@ void export_amount() .def("find_commodity", &commodity_t::find_commodity, return_value_policy<reference_existing_object>()) - .def("check_symbol", &commodity_t::check_symbol) .def("add_price", &commodity_t::add_price) .def("remove_price", &commodity_t::remove_price) .def("set_conversion", &commodity_t::set_conversion) @@ -271,16 +271,16 @@ class commodity_t typedef unsigned long ident_t; - std::string symbol; - bool quote; - std::string name; - std::string note; - unsigned short precision; - unsigned short flags; - history_map history; - std::time_t last_lookup; - amount_t conversion; - ident_t ident; + const std::string symbol; + bool quote; + std::string name; + std::string note; + unsigned short precision; + unsigned short flags; + history_map history; + std::time_t last_lookup; + amount_t conversion; + ident_t ident; // If set, this global function pointer is called to determine // whether prices have been updated in the meanwhile. @@ -315,9 +315,8 @@ class commodity_t commodity_t(const std::string& _symbol = "", unsigned int _precision = 0, unsigned int _flags = COMMODITY_STYLE_DEFAULTS) - : symbol(_symbol), quote(false), precision(_precision), - flags(_flags), last_lookup(0) { - check_symbol(); + : precision(_precision), flags(_flags), last_lookup(0) { + set_symbol(_symbol); } operator bool() const { @@ -330,12 +329,15 @@ class commodity_t return this != &comm; } - void check_symbol() { + void set_symbol(const std::string& sym) { + *(const_cast<std::string *>(&symbol)) = sym; + quote = false; for (const char * p = symbol.c_str(); *p; p++) if (std::isspace(*p) || std::isdigit(*p) || *p == '-' || *p == '.') { quote = true; return; } + } void add_price(const std::time_t date, const amount_t& price); @@ -9,7 +9,7 @@ namespace ledger { static unsigned long binary_magic_number = 0xFFEED765; -static unsigned long format_version = 0x0002001a; +static unsigned long format_version = 0x0002001b; static account_t ** accounts; static account_t ** accounts_next; @@ -216,7 +216,8 @@ inline commodity_t * read_binary_commodity(char *& data) commodity->ident = read_binary_number<commodity_t::ident_t>(data); - read_binary_string(data, commodity->symbol); + read_binary_string(data, *(const_cast<std::string *>(&commodity->symbol))); + read_binary_number(data, commodity->quote); read_binary_string(data, commodity->name); read_binary_string(data, commodity->note); read_binary_number(data, commodity->precision); @@ -472,6 +473,7 @@ void write_binary_commodity(std::ostream& out, commodity_t * commodity) write_binary_number(out, commodity->ident); write_binary_string(out, commodity->symbol); + write_binary_number(out, commodity->quote); write_binary_string(out, commodity->name); write_binary_string(out, commodity->note); write_binary_number(out, commodity->precision); @@ -165,16 +165,12 @@ static void dataHandler(void *userData, const char *s, int len) } case COMM_SYM: - if (curr_comm) { - curr_comm->symbol = std::string(s, len); - curr_comm->check_symbol(); - } - else if (curr_account) { + if (curr_comm) + curr_comm->set_symbol(std::string(s, len)); + else if (curr_account) curr_account_comm = commodity_t::find_commodity(std::string(s, len)); - } - else if (curr_entry) { + else if (curr_entry) entry_comm = commodity_t::find_commodity(std::string(s, len)); - } break; case COMM_NAME: @@ -335,6 +335,16 @@ struct item_handler_wrap : public item_handler<T> void (subtotal_transactions::*subtotal_transactions_flush)() = &subtotal_transactions::flush; +void py_walk_entries(journal_t& journal, item_handler<transaction_t>& handler) +{ + walk_entries(journal.entries, handler); +} + +void py_walk_transactions(entry_t& entry, item_handler<transaction_t>& handler) +{ + walk_transactions(entry.transactions, handler); +} + void export_walk() { class_< item_handler<transaction_t>, @@ -431,6 +441,9 @@ void export_walk() .def("flush", &item_handler<transaction_t>::flush) .def("__call__", &related_transactions::operator()); ; + + def("walk_entries", py_walk_entries); + def("walk_transactions", py_walk_transactions); } #endif // USE_BOOST_PYTHON |