change commodity->symbol to const, and added set_symbol
This commit is contained in:
parent
6261da4660
commit
e414123ecb
5 changed files with 39 additions and 28 deletions
|
|
@ -1120,9 +1120,8 @@ void export_amount()
|
||||||
class_< commodity_t > ("Commodity")
|
class_< commodity_t > ("Commodity")
|
||||||
.def(init<std::string, optional<unsigned int, unsigned int> >())
|
.def(init<std::string, optional<unsigned int, unsigned int> >())
|
||||||
|
|
||||||
// make this a function which called check_symbol after being set
|
.def_readonly("symbol", &commodity_t::symbol)
|
||||||
.def_readwrite("symbol", &commodity_t::symbol)
|
.def("set_symbol", &commodity_t::set_symbol)
|
||||||
.def_readwrite("quote", &commodity_t::quote)
|
|
||||||
.def_readwrite("name", &commodity_t::name)
|
.def_readwrite("name", &commodity_t::name)
|
||||||
.def_readwrite("note", &commodity_t::name)
|
.def_readwrite("note", &commodity_t::name)
|
||||||
.def_readwrite("precision", &commodity_t::precision)
|
.def_readwrite("precision", &commodity_t::precision)
|
||||||
|
|
@ -1137,7 +1136,6 @@ void export_amount()
|
||||||
.def("find_commodity", &commodity_t::find_commodity,
|
.def("find_commodity", &commodity_t::find_commodity,
|
||||||
return_value_policy<reference_existing_object>())
|
return_value_policy<reference_existing_object>())
|
||||||
|
|
||||||
.def("check_symbol", &commodity_t::check_symbol)
|
|
||||||
.def("add_price", &commodity_t::add_price)
|
.def("add_price", &commodity_t::add_price)
|
||||||
.def("remove_price", &commodity_t::remove_price)
|
.def("remove_price", &commodity_t::remove_price)
|
||||||
.def("set_conversion", &commodity_t::set_conversion)
|
.def("set_conversion", &commodity_t::set_conversion)
|
||||||
|
|
|
||||||
12
amount.h
12
amount.h
|
|
@ -271,7 +271,7 @@ class commodity_t
|
||||||
|
|
||||||
typedef unsigned long ident_t;
|
typedef unsigned long ident_t;
|
||||||
|
|
||||||
std::string symbol;
|
const std::string symbol;
|
||||||
bool quote;
|
bool quote;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string note;
|
std::string note;
|
||||||
|
|
@ -315,9 +315,8 @@ class commodity_t
|
||||||
commodity_t(const std::string& _symbol = "",
|
commodity_t(const std::string& _symbol = "",
|
||||||
unsigned int _precision = 0,
|
unsigned int _precision = 0,
|
||||||
unsigned int _flags = COMMODITY_STYLE_DEFAULTS)
|
unsigned int _flags = COMMODITY_STYLE_DEFAULTS)
|
||||||
: symbol(_symbol), quote(false), precision(_precision),
|
: precision(_precision), flags(_flags), last_lookup(0) {
|
||||||
flags(_flags), last_lookup(0) {
|
set_symbol(_symbol);
|
||||||
check_symbol();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
|
|
@ -330,12 +329,15 @@ class commodity_t
|
||||||
return this != &comm;
|
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++)
|
for (const char * p = symbol.c_str(); *p; p++)
|
||||||
if (std::isspace(*p) || std::isdigit(*p) || *p == '-' || *p == '.') {
|
if (std::isspace(*p) || std::isdigit(*p) || *p == '-' || *p == '.') {
|
||||||
quote = true;
|
quote = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_price(const std::time_t date, const amount_t& price);
|
void add_price(const std::time_t date, const amount_t& price);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
static unsigned long binary_magic_number = 0xFFEED765;
|
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;
|
||||||
static account_t ** accounts_next;
|
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);
|
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->name);
|
||||||
read_binary_string(data, commodity->note);
|
read_binary_string(data, commodity->note);
|
||||||
read_binary_number(data, commodity->precision);
|
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_number(out, commodity->ident);
|
||||||
write_binary_string(out, commodity->symbol);
|
write_binary_string(out, commodity->symbol);
|
||||||
|
write_binary_number(out, commodity->quote);
|
||||||
write_binary_string(out, commodity->name);
|
write_binary_string(out, commodity->name);
|
||||||
write_binary_string(out, commodity->note);
|
write_binary_string(out, commodity->note);
|
||||||
write_binary_number(out, commodity->precision);
|
write_binary_number(out, commodity->precision);
|
||||||
|
|
|
||||||
12
gnucash.cc
12
gnucash.cc
|
|
@ -165,16 +165,12 @@ static void dataHandler(void *userData, const char *s, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
case COMM_SYM:
|
case COMM_SYM:
|
||||||
if (curr_comm) {
|
if (curr_comm)
|
||||||
curr_comm->symbol = std::string(s, len);
|
curr_comm->set_symbol(std::string(s, len));
|
||||||
curr_comm->check_symbol();
|
else if (curr_account)
|
||||||
}
|
|
||||||
else if (curr_account) {
|
|
||||||
curr_account_comm = commodity_t::find_commodity(std::string(s, len));
|
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));
|
entry_comm = commodity_t::find_commodity(std::string(s, len));
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COMM_NAME:
|
case COMM_NAME:
|
||||||
|
|
|
||||||
13
walk.cc
13
walk.cc
|
|
@ -335,6 +335,16 @@ struct item_handler_wrap : public item_handler<T>
|
||||||
void (subtotal_transactions::*subtotal_transactions_flush)() =
|
void (subtotal_transactions::*subtotal_transactions_flush)() =
|
||||||
&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()
|
void export_walk()
|
||||||
{
|
{
|
||||||
class_< item_handler<transaction_t>,
|
class_< item_handler<transaction_t>,
|
||||||
|
|
@ -431,6 +441,9 @@ void export_walk()
|
||||||
.def("flush", &item_handler<transaction_t>::flush)
|
.def("flush", &item_handler<transaction_t>::flush)
|
||||||
.def("__call__", &related_transactions::operator());
|
.def("__call__", &related_transactions::operator());
|
||||||
;
|
;
|
||||||
|
|
||||||
|
def("walk_entries", py_walk_entries);
|
||||||
|
def("walk_transactions", py_walk_transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_BOOST_PYTHON
|
#endif // USE_BOOST_PYTHON
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue