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);
|
||||
}
|
||||
#endif
|
||||
} initializer;
|
||||
} _init;
|
||||
|
||||
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);
|
||||
|
||||
#ifdef DO_CLEANUP
|
||||
|
||||
static struct cleanup_commodities
|
||||
static struct cleanup_t
|
||||
{
|
||||
~cleanup_commodities() {
|
||||
~cleanup_t() {
|
||||
if (commodity_t::updater)
|
||||
delete commodity_t::updater;
|
||||
|
||||
|
|
@ -945,8 +944,7 @@ static struct cleanup_commodities
|
|||
delete (*i).second;
|
||||
}
|
||||
} _cleanup;
|
||||
|
||||
#endif // DO_CLEANUP
|
||||
#endif
|
||||
|
||||
commodity_t * commodity_t::find_commodity(const std::string& symbol,
|
||||
bool auto_create)
|
||||
|
|
|
|||
22
format.cc
22
format.cc
|
|
@ -33,14 +33,19 @@ std::string partial_account_name(const account_t * account)
|
|||
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
|
||||
std::auto_ptr<value_expr_t> format_t::value_expr;
|
||||
std::auto_ptr<value_expr_t> format_t::total_expr;
|
||||
#else
|
||||
value_expr_t * format_t::value_expr = NULL;
|
||||
value_expr_t * format_t::total_expr = NULL;
|
||||
static struct cleanup_t {
|
||||
~cleanup_t() {
|
||||
if (format_t::value_expr)
|
||||
delete format_t::value_expr;
|
||||
if (format_t::total_expr)
|
||||
delete format_t::total_expr;
|
||||
}
|
||||
} _cleanup;
|
||||
#endif
|
||||
|
||||
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: {
|
||||
value_expr_t * expr = NULL;
|
||||
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::TOTAL: expr = total_expr; break;
|
||||
#endif
|
||||
case element_t::VALUE_EXPR: expr = elem->val_expr; break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
16
format.h
16
format.h
|
|
@ -52,15 +52,9 @@ struct format_t
|
|||
{
|
||||
element_t * elements;
|
||||
|
||||
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 std::string date_format;
|
||||
static value_expr_t * value_expr;
|
||||
static value_expr_t * total_expr;
|
||||
#endif
|
||||
|
||||
format_t(const std::string& _format) : elements(NULL) {
|
||||
reset(_format);
|
||||
|
|
@ -80,20 +74,12 @@ struct format_t
|
|||
void format_elements(std::ostream& out, const details_t& details) const;
|
||||
|
||||
static void compute_value(value_t& result, const details_t& details) {
|
||||
#ifdef DO_CLEANUP
|
||||
if (value_expr.get())
|
||||
#else
|
||||
if (value_expr)
|
||||
#endif
|
||||
value_expr->compute(result, details);
|
||||
}
|
||||
|
||||
static void compute_total(value_t& result, const details_t& details) {
|
||||
#ifdef DO_CLEANUP
|
||||
if (total_expr.get())
|
||||
#else
|
||||
if (total_expr)
|
||||
#endif
|
||||
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
|
||||
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
catch (const value_expr_error& err) {
|
||||
std::cerr << "Error in amount (-t) specifier: " << err.what()
|
||||
|
|
@ -382,11 +378,7 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
catch (const value_expr_error& err) {
|
||||
std::cerr << "Error in total (-T) specifier: " << err.what()
|
||||
|
|
@ -608,11 +600,11 @@ int main(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
|
||||
#ifdef DO_CLEANUP
|
||||
// The transaction display flags (dflags) are not recorded in the
|
||||
// binary cache, and only need to be cleared if the transactions
|
||||
// are to be displayed a second time.
|
||||
// Cleanup the data handlers that might be present on some objects.
|
||||
|
||||
clear_transaction_data xact_cleanup;
|
||||
walk_entries(journal->entries, xact_cleanup);
|
||||
|
||||
clear_account_data acct_cleanup;
|
||||
walk_accounts(journal->master, acct_cleanup);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -114,19 +114,11 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
|||
break;
|
||||
|
||||
case VALUE_EXPR:
|
||||
#ifdef DO_CLEANUP
|
||||
assert(format_t::value_expr.get());
|
||||
#else
|
||||
assert(format_t::value_expr);
|
||||
#endif
|
||||
format_t::value_expr->compute(result, details);
|
||||
break;
|
||||
case TOTAL_EXPR:
|
||||
#ifdef DO_CLEANUP
|
||||
assert(format_t::total_expr.get());
|
||||
#else
|
||||
assert(format_t::total_expr);
|
||||
#endif
|
||||
format_t::total_expr->compute(result, details);
|
||||
break;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue