Further improvements to handling temporaries

This commit is contained in:
John Wiegley 2009-10-28 01:18:27 -04:00
parent cc532c31aa
commit aa45d2d38c
6 changed files with 10 additions and 31 deletions

View file

@ -686,6 +686,7 @@ void transfer_details::operator()(post_t& post)
xact.payee = expr.calc(bound_scope).to_string();
break;
case SET_ACCOUNT:
temp.account->remove_post(&temp);
temp.account = master->find_account(expr.calc(bound_scope).to_string());
temp.account->add_post(&temp);
break;

View file

@ -108,24 +108,19 @@ void posts_commodities_iterator::reset(journal_t& journal)
if (i != xacts_by_commodity.end()) {
xact = (*i).second;
} else {
xact_temps.push_back(new xact_t);
xact = xact_temps.back();
xact = &temps.create_xact();
xact_temps.push_back(xact);
xact->payee = symbol;
xact->_date = hpair.first.date();
xacts_by_commodity.insert
(std::pair<string, xact_t *>(symbol, xact));
}
post_temps.push_back(post_t(account));
post_t& temp = post_temps.back();
post_t& temp = temps.create_post(*xact, account);
temp._date = hpair.first.date();
temp.xact = xact;
temp.amount = hpair.second;
temp.set_flags(ITEM_GENERATED | ITEM_TEMP);
temp.xdata().datetime = hpair.first;
xact->add_post(&temp);
}
}
}

View file

@ -49,6 +49,7 @@
#include "xact.h"
#include "post.h"
#include "account.h"
#include "temps.h"
namespace ledger {
@ -172,9 +173,7 @@ protected:
journal_posts_iterator journal_posts;
xacts_iterator xacts;
xact_posts_iterator posts;
std::list<post_t> post_temps;
std::list<account_t> acct_temps;
temporaries_t temps;
xacts_list xact_temps;
public:
@ -187,8 +186,6 @@ public:
}
virtual ~posts_commodities_iterator() throw() {
TRACE_DTOR(posts_commodities_iterator);
foreach (xact_t * xact, xact_temps)
checked_delete(xact);
}
void reset(journal_t& journal);

View file

@ -31,6 +31,9 @@
#include <system.hh>
#include "xact.h"
#include "post.h"
#include "account.h"
#include "temps.h"
namespace ledger {

View file

@ -46,10 +46,6 @@
#ifndef _TEMPS_H
#define _TEMPS_H
#include "xact.h"
#include "post.h"
#include "account.h"
namespace ledger {
class temporaries_t

View file

@ -1014,21 +1014,8 @@ post_t * instance_t::parse_post(char * line,
if (! diff.is_zero()) {
if (! post->amount.is_null()) {
diff -= post->amount;
if (! diff.is_zero()) {
#if 1
if (! diff.is_zero())
throw_(parse_error, _("Balance assertion off by %1") << diff);
#else
// This code, rather than issuing an error if a balance assignment
// fails, creates a balancing transaction that causes the
// assertion to be true.
post_t * temp = new post_t(post->account, diff,
ITEM_GENERATED | POST_CALCULATED);
xact->add_post(temp);
DEBUG("textual.parse", "line " << linenum << ": "
<< "Created balancing posting");
#endif
}
} else {
post->amount = diff;
DEBUG("textual.parse", "line " << linenum << ": "