simplified some code
This commit is contained in:
parent
02168c7823
commit
6365b8b7a8
5 changed files with 19 additions and 51 deletions
10
amount.cc
10
amount.cc
|
|
@ -57,7 +57,7 @@ static struct init_amounts {
|
||||||
mpz_clear(temp);
|
mpz_clear(temp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} initializer;
|
} _init;
|
||||||
|
|
||||||
static void mpz_round(mpz_t out, mpz_t value, int value_prec, int round_prec)
|
static void mpz_round(mpz_t out, mpz_t value, int value_prec, int round_prec)
|
||||||
{
|
{
|
||||||
|
|
@ -931,10 +931,9 @@ commodity_t * commodity_t::null_commodity =
|
||||||
commodity_t::find_commodity("", true);
|
commodity_t::find_commodity("", true);
|
||||||
|
|
||||||
#ifdef DO_CLEANUP
|
#ifdef DO_CLEANUP
|
||||||
|
static struct cleanup_t
|
||||||
static struct cleanup_commodities
|
|
||||||
{
|
{
|
||||||
~cleanup_commodities() {
|
~cleanup_t() {
|
||||||
if (commodity_t::updater)
|
if (commodity_t::updater)
|
||||||
delete commodity_t::updater;
|
delete commodity_t::updater;
|
||||||
|
|
||||||
|
|
@ -945,8 +944,7 @@ static struct cleanup_commodities
|
||||||
delete (*i).second;
|
delete (*i).second;
|
||||||
}
|
}
|
||||||
} _cleanup;
|
} _cleanup;
|
||||||
|
#endif
|
||||||
#endif // DO_CLEANUP
|
|
||||||
|
|
||||||
commodity_t * commodity_t::find_commodity(const std::string& symbol,
|
commodity_t * commodity_t::find_commodity(const std::string& symbol,
|
||||||
bool auto_create)
|
bool auto_create)
|
||||||
|
|
|
||||||
22
format.cc
22
format.cc
|
|
@ -33,14 +33,19 @@ std::string partial_account_name(const account_t * account)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string format_t::date_format = "%Y/%m/%d";
|
std::string format_t::date_format = "%Y/%m/%d";
|
||||||
|
value_expr_t * format_t::value_expr = NULL;
|
||||||
|
value_expr_t * format_t::total_expr = NULL;
|
||||||
|
|
||||||
#ifdef DO_CLEANUP
|
#ifdef DO_CLEANUP
|
||||||
std::auto_ptr<value_expr_t> format_t::value_expr;
|
static struct cleanup_t {
|
||||||
std::auto_ptr<value_expr_t> format_t::total_expr;
|
~cleanup_t() {
|
||||||
#else
|
if (format_t::value_expr)
|
||||||
value_expr_t * format_t::value_expr = NULL;
|
delete format_t::value_expr;
|
||||||
value_expr_t * format_t::total_expr = NULL;
|
if (format_t::total_expr)
|
||||||
|
delete format_t::total_expr;
|
||||||
|
}
|
||||||
|
} _cleanup;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
element_t * format_t::parse_elements(const std::string& fmt)
|
element_t * format_t::parse_elements(const std::string& fmt)
|
||||||
|
|
@ -200,13 +205,8 @@ void format_t::format_elements(std::ostream& out,
|
||||||
case element_t::VALUE_EXPR: {
|
case element_t::VALUE_EXPR: {
|
||||||
value_expr_t * expr = NULL;
|
value_expr_t * expr = NULL;
|
||||||
switch (elem->type) {
|
switch (elem->type) {
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
case element_t::VALUE: expr = value_expr.get(); break;
|
|
||||||
case element_t::TOTAL: expr = total_expr.get(); break;
|
|
||||||
#else
|
|
||||||
case element_t::VALUE: expr = value_expr; break;
|
case element_t::VALUE: expr = value_expr; break;
|
||||||
case element_t::TOTAL: expr = total_expr; break;
|
case element_t::TOTAL: expr = total_expr; break;
|
||||||
#endif
|
|
||||||
case element_t::VALUE_EXPR: expr = elem->val_expr; break;
|
case element_t::VALUE_EXPR: expr = elem->val_expr; break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
16
format.h
16
format.h
|
|
@ -52,15 +52,9 @@ struct format_t
|
||||||
{
|
{
|
||||||
element_t * elements;
|
element_t * elements;
|
||||||
|
|
||||||
static std::string date_format;
|
static std::string date_format;
|
||||||
|
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
static std::auto_ptr<value_expr_t> value_expr;
|
|
||||||
static std::auto_ptr<value_expr_t> total_expr;
|
|
||||||
#else
|
|
||||||
static value_expr_t * value_expr;
|
static value_expr_t * value_expr;
|
||||||
static value_expr_t * total_expr;
|
static value_expr_t * total_expr;
|
||||||
#endif
|
|
||||||
|
|
||||||
format_t(const std::string& _format) : elements(NULL) {
|
format_t(const std::string& _format) : elements(NULL) {
|
||||||
reset(_format);
|
reset(_format);
|
||||||
|
|
@ -80,20 +74,12 @@ struct format_t
|
||||||
void format_elements(std::ostream& out, const details_t& details) const;
|
void format_elements(std::ostream& out, const details_t& details) const;
|
||||||
|
|
||||||
static void compute_value(value_t& result, const details_t& details) {
|
static void compute_value(value_t& result, const details_t& details) {
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
if (value_expr.get())
|
|
||||||
#else
|
|
||||||
if (value_expr)
|
if (value_expr)
|
||||||
#endif
|
|
||||||
value_expr->compute(result, details);
|
value_expr->compute(result, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_total(value_t& result, const details_t& details) {
|
static void compute_total(value_t& result, const details_t& details) {
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
if (total_expr.get())
|
|
||||||
#else
|
|
||||||
if (total_expr)
|
if (total_expr)
|
||||||
#endif
|
|
||||||
total_expr->compute(result, details);
|
total_expr->compute(result, details);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
14
main.cc
14
main.cc
|
|
@ -369,11 +369,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
// Setup the values of %t and %T, used in format strings
|
// Setup the values of %t and %T, used in format strings
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
format_t::value_expr.reset(parse_value_expr(config->value_expr));
|
|
||||||
#else
|
|
||||||
format_t::value_expr = parse_value_expr(config->value_expr);
|
format_t::value_expr = parse_value_expr(config->value_expr);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
catch (const value_expr_error& err) {
|
catch (const value_expr_error& err) {
|
||||||
std::cerr << "Error in amount (-t) specifier: " << err.what()
|
std::cerr << "Error in amount (-t) specifier: " << err.what()
|
||||||
|
|
@ -382,11 +378,7 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
format_t::total_expr.reset(parse_value_expr(config->total_expr));
|
|
||||||
#else
|
|
||||||
format_t::total_expr = parse_value_expr(config->total_expr);
|
format_t::total_expr = parse_value_expr(config->total_expr);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
catch (const value_expr_error& err) {
|
catch (const value_expr_error& err) {
|
||||||
std::cerr << "Error in total (-T) specifier: " << err.what()
|
std::cerr << "Error in total (-T) specifier: " << err.what()
|
||||||
|
|
@ -608,11 +600,11 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DO_CLEANUP
|
#ifdef DO_CLEANUP
|
||||||
// The transaction display flags (dflags) are not recorded in the
|
// Cleanup the data handlers that might be present on some objects.
|
||||||
// binary cache, and only need to be cleared if the transactions
|
|
||||||
// are to be displayed a second time.
|
|
||||||
clear_transaction_data xact_cleanup;
|
clear_transaction_data xact_cleanup;
|
||||||
walk_entries(journal->entries, xact_cleanup);
|
walk_entries(journal->entries, xact_cleanup);
|
||||||
|
|
||||||
clear_account_data acct_cleanup;
|
clear_account_data acct_cleanup;
|
||||||
walk_accounts(journal->master, acct_cleanup);
|
walk_accounts(journal->master, acct_cleanup);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -114,19 +114,11 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALUE_EXPR:
|
case VALUE_EXPR:
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
assert(format_t::value_expr.get());
|
|
||||||
#else
|
|
||||||
assert(format_t::value_expr);
|
assert(format_t::value_expr);
|
||||||
#endif
|
|
||||||
format_t::value_expr->compute(result, details);
|
format_t::value_expr->compute(result, details);
|
||||||
break;
|
break;
|
||||||
case TOTAL_EXPR:
|
case TOTAL_EXPR:
|
||||||
#ifdef DO_CLEANUP
|
|
||||||
assert(format_t::total_expr.get());
|
|
||||||
#else
|
|
||||||
assert(format_t::total_expr);
|
assert(format_t::total_expr);
|
||||||
#endif
|
|
||||||
format_t::total_expr->compute(result, details);
|
format_t::total_expr->compute(result, details);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue