Change many uses of for+iterator to use Boost.Foreach.
This commit is contained in:
parent
99313ebc6c
commit
e5048ec71b
26 changed files with 369 additions and 578 deletions
14
account.cc
14
account.cc
|
|
@ -37,10 +37,8 @@ account_t::~account_t()
|
||||||
{
|
{
|
||||||
TRACE_DTOR(account_t);
|
TRACE_DTOR(account_t);
|
||||||
|
|
||||||
for (accounts_map::iterator i = accounts.begin();
|
foreach (accounts_map::value_type& pair, accounts)
|
||||||
i != accounts.end();
|
checked_delete(pair.second);
|
||||||
i++)
|
|
||||||
checked_delete((*i).second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
account_t * account_t::find_account(const string& name,
|
account_t * account_t::find_account(const string& name,
|
||||||
|
|
@ -130,15 +128,13 @@ bool account_t::valid() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (accounts_map::const_iterator i = accounts.begin();
|
foreach (const accounts_map::value_type& pair, accounts) {
|
||||||
i != accounts.end();
|
if (this == pair.second) {
|
||||||
i++) {
|
|
||||||
if (this == (*i).second) {
|
|
||||||
DEBUG("ledger.validate", "account_t: parent refers to itself!");
|
DEBUG("ledger.validate", "account_t: parent refers to itself!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! (*i).second->valid()) {
|
if (! pair.second->valid()) {
|
||||||
DEBUG("ledger.validate", "account_t: child not valid");
|
DEBUG("ledger.validate", "account_t: child not valid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
balance.cc
50
balance.cc
|
|
@ -35,10 +35,8 @@ namespace ledger {
|
||||||
|
|
||||||
balance_t& balance_t::operator+=(const balance_t& bal)
|
balance_t& balance_t::operator+=(const balance_t& bal)
|
||||||
{
|
{
|
||||||
for (amounts_map::const_iterator i = bal.amounts.begin();
|
foreach (const amounts_map::value_type& pair, bal.amounts)
|
||||||
i != bal.amounts.end();
|
*this += pair.second;
|
||||||
i++)
|
|
||||||
*this += i->second;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,10 +60,8 @@ balance_t& balance_t::operator+=(const amount_t& amt)
|
||||||
|
|
||||||
balance_t& balance_t::operator-=(const balance_t& bal)
|
balance_t& balance_t::operator-=(const balance_t& bal)
|
||||||
{
|
{
|
||||||
for (amounts_map::const_iterator i = bal.amounts.begin();
|
foreach (const amounts_map::value_type& pair, bal.amounts)
|
||||||
i != bal.amounts.end();
|
*this -= pair.second;
|
||||||
i++)
|
|
||||||
*this -= i->second;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,10 +100,8 @@ balance_t& balance_t::operator*=(const amount_t& amt)
|
||||||
else if (! amt.commodity()) {
|
else if (! amt.commodity()) {
|
||||||
// Multiplying by an amount with no commodity causes all the
|
// Multiplying by an amount with no commodity causes all the
|
||||||
// component amounts to be increased by the same factor.
|
// component amounts to be increased by the same factor.
|
||||||
for (amounts_map::iterator i = amounts.begin();
|
foreach (amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
pair.second *= amt;
|
||||||
i++)
|
|
||||||
i->second *= amt;
|
|
||||||
}
|
}
|
||||||
else if (amounts.size() == 1) {
|
else if (amounts.size() == 1) {
|
||||||
// Multiplying by a commoditized amount is only valid if the sole
|
// Multiplying by a commoditized amount is only valid if the sole
|
||||||
|
|
@ -142,10 +136,8 @@ balance_t& balance_t::operator/=(const amount_t& amt)
|
||||||
else if (! amt.commodity()) {
|
else if (! amt.commodity()) {
|
||||||
// Dividing by an amount with no commodity causes all the
|
// Dividing by an amount with no commodity causes all the
|
||||||
// component amounts to be divided by the same factor.
|
// component amounts to be divided by the same factor.
|
||||||
for (amounts_map::iterator i = amounts.begin();
|
foreach (amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
pair.second /= amt;
|
||||||
i++)
|
|
||||||
i->second /= amt;
|
|
||||||
}
|
}
|
||||||
else if (amounts.size() == 1) {
|
else if (amounts.size() == 1) {
|
||||||
// Dividing by a commoditized amount is only valid if the sole
|
// Dividing by a commoditized amount is only valid if the sole
|
||||||
|
|
@ -170,10 +162,8 @@ balance_t::value(const optional<datetime_t>& moment) const
|
||||||
{
|
{
|
||||||
optional<balance_t> temp;
|
optional<balance_t> temp;
|
||||||
|
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (optional<amount_t> val = pair.second.value(moment)) {
|
||||||
i++)
|
|
||||||
if (optional<amount_t> val = i->second.value(moment)) {
|
|
||||||
if (! temp)
|
if (! temp)
|
||||||
temp = balance_t();
|
temp = balance_t();
|
||||||
*temp += *val;
|
*temp += *val;
|
||||||
|
|
@ -215,10 +205,8 @@ balance_t balance_t::strip_annotations(const bool keep_price,
|
||||||
{
|
{
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
|
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.strip_annotations(keep_price, keep_date, keep_tag);
|
||||||
i++)
|
|
||||||
temp += i->second.strip_annotations(keep_price, keep_date, keep_tag);
|
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
@ -236,17 +224,13 @@ void balance_t::print(std::ostream& out,
|
||||||
typedef std::vector<const amount_t *> amounts_array;
|
typedef std::vector<const amount_t *> amounts_array;
|
||||||
amounts_array sorted;
|
amounts_array sorted;
|
||||||
|
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (pair.second)
|
||||||
i++)
|
sorted.push_back(&pair.second);
|
||||||
if (i->second)
|
|
||||||
sorted.push_back(&i->second);
|
|
||||||
|
|
||||||
std::stable_sort(sorted.begin(), sorted.end(), compare_amount_commodities());
|
std::stable_sort(sorted.begin(), sorted.end(), compare_amount_commodities());
|
||||||
|
|
||||||
for (amounts_array::const_iterator i = sorted.begin();
|
foreach (const amount_t * amount, sorted) {
|
||||||
i != sorted.end();
|
|
||||||
i++) {
|
|
||||||
int width;
|
int width;
|
||||||
if (! first) {
|
if (! first) {
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
|
|
@ -258,7 +242,7 @@ void balance_t::print(std::ostream& out,
|
||||||
|
|
||||||
out.width(width);
|
out.width(width);
|
||||||
out.fill(' ');
|
out.fill(' ');
|
||||||
out << std::right << **i;
|
out << std::right << *amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
|
|
|
||||||
72
balance.h
72
balance.h
|
|
@ -301,10 +301,8 @@ public:
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
virtual balance_t& in_place_negate() {
|
virtual balance_t& in_place_negate() {
|
||||||
for (amounts_map::iterator i = amounts.begin();
|
foreach (amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
pair.second.in_place_negate();
|
||||||
i++)
|
|
||||||
i->second.in_place_negate();
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
balance_t operator-() const {
|
balance_t operator-() const {
|
||||||
|
|
@ -313,35 +311,27 @@ public:
|
||||||
|
|
||||||
balance_t abs() const {
|
balance_t abs() const {
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.abs();
|
||||||
i++)
|
|
||||||
temp += i->second.abs();
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
balance_t round() const {
|
balance_t round() const {
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.round();
|
||||||
i++)
|
|
||||||
temp += i->second.round();
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
balance_t round(amount_t::precision_t prec) const {
|
balance_t round(amount_t::precision_t prec) const {
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.round(prec);
|
||||||
i++)
|
|
||||||
temp += i->second.round(prec);
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
balance_t unround() const {
|
balance_t unround() const {
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.unround();
|
||||||
i++)
|
|
||||||
temp += i->second.unround();
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,10 +344,8 @@ public:
|
||||||
// A temporary must be used here because reduction may cause
|
// A temporary must be used here because reduction may cause
|
||||||
// multiple component amounts to collapse to the same commodity.
|
// multiple component amounts to collapse to the same commodity.
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.reduce();
|
||||||
i++)
|
|
||||||
temp += i->second.reduce();
|
|
||||||
return *this = temp;
|
return *this = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,10 +358,8 @@ public:
|
||||||
// A temporary must be used here because unreduction may cause
|
// A temporary must be used here because unreduction may cause
|
||||||
// multiple component amounts to collapse to the same commodity.
|
// multiple component amounts to collapse to the same commodity.
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.unreduce();
|
||||||
i++)
|
|
||||||
temp += i->second.unreduce();
|
|
||||||
return *this = temp;
|
return *this = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -398,10 +384,8 @@ public:
|
||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (pair.second.is_nonzero())
|
||||||
i++)
|
|
||||||
if (i->second.is_nonzero())
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -410,10 +394,8 @@ public:
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (! pair.second.is_zero())
|
||||||
i++)
|
|
||||||
if (! i->second.is_zero())
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -422,10 +404,8 @@ public:
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (! pair.second.is_realzero())
|
||||||
i++)
|
|
||||||
if (! i->second.is_realzero())
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -518,23 +498,19 @@ public:
|
||||||
void dump(std::ostream& out) const {
|
void dump(std::ostream& out) const {
|
||||||
out << "BALANCE(";
|
out << "BALANCE(";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts) {
|
||||||
i != amounts.end();
|
|
||||||
i++) {
|
|
||||||
if (first)
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else
|
||||||
out << ", ";
|
out << ", ";
|
||||||
i->second.print(out);
|
pair.second.print(out);
|
||||||
}
|
}
|
||||||
out << ")";
|
out << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool valid() const {
|
virtual bool valid() const {
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
if (! pair.second.valid())
|
||||||
i++)
|
|
||||||
if (! i->second.valid())
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
balpair.h
36
balpair.h
|
|
@ -246,17 +246,13 @@ public:
|
||||||
*/
|
*/
|
||||||
balance_pair_t abs() const {
|
balance_pair_t abs() const {
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.abs();
|
||||||
i++)
|
|
||||||
temp += i->second.abs();
|
|
||||||
|
|
||||||
if (cost) {
|
if (cost) {
|
||||||
balance_t cost_temp;
|
balance_t cost_temp;
|
||||||
for (amounts_map::const_iterator i = cost->amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != cost->amounts.end();
|
cost_temp += pair.second.abs();
|
||||||
i++)
|
|
||||||
cost_temp += i->second.abs();
|
|
||||||
return balance_pair_t(temp, cost_temp);
|
return balance_pair_t(temp, cost_temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
|
|
@ -273,17 +269,13 @@ public:
|
||||||
// A temporary must be used here because reduction may cause
|
// A temporary must be used here because reduction may cause
|
||||||
// multiple component amounts to collapse to the same commodity.
|
// multiple component amounts to collapse to the same commodity.
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.reduce();
|
||||||
i++)
|
|
||||||
temp += i->second.reduce();
|
|
||||||
|
|
||||||
if (cost) {
|
if (cost) {
|
||||||
balance_t cost_temp;
|
balance_t cost_temp;
|
||||||
for (amounts_map::const_iterator i = cost->amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != cost->amounts.end();
|
cost_temp += pair.second.reduce();
|
||||||
i++)
|
|
||||||
cost_temp += i->second.reduce();
|
|
||||||
return *this = balance_pair_t(temp, cost_temp);
|
return *this = balance_pair_t(temp, cost_temp);
|
||||||
}
|
}
|
||||||
return *this = temp;
|
return *this = temp;
|
||||||
|
|
@ -293,17 +285,13 @@ public:
|
||||||
// A temporary must be used here because unreduction may cause
|
// A temporary must be used here because unreduction may cause
|
||||||
// multiple component amounts to collapse to the same commodity.
|
// multiple component amounts to collapse to the same commodity.
|
||||||
balance_t temp;
|
balance_t temp;
|
||||||
for (amounts_map::const_iterator i = amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != amounts.end();
|
temp += pair.second.unreduce();
|
||||||
i++)
|
|
||||||
temp += i->second.unreduce();
|
|
||||||
|
|
||||||
if (cost) {
|
if (cost) {
|
||||||
balance_t cost_temp;
|
balance_t cost_temp;
|
||||||
for (amounts_map::const_iterator i = cost->amounts.begin();
|
foreach (const amounts_map::value_type& pair, amounts)
|
||||||
i != cost->amounts.end();
|
cost_temp += pair.second.unreduce();
|
||||||
i++)
|
|
||||||
cost_temp += i->second.unreduce();
|
|
||||||
return *this = balance_pair_t(temp, cost_temp);
|
return *this = balance_pair_t(temp, cost_temp);
|
||||||
}
|
}
|
||||||
return *this = temp;
|
return *this = temp;
|
||||||
|
|
|
||||||
105
cache.cc
105
cache.cc
|
|
@ -133,6 +133,7 @@ void read_entry_base(const char *& data, entry_base_t * entry,
|
||||||
xact_t *& xact_pool, bool& finalize)
|
xact_t *& xact_pool, bool& finalize)
|
||||||
{
|
{
|
||||||
read_long(data, entry->src_idx);
|
read_long(data, entry->src_idx);
|
||||||
|
// jww (2008-07-31): Use istream_pos_type
|
||||||
entry->beg_pos = read_long<unsigned long>(data);
|
entry->beg_pos = read_long<unsigned long>(data);
|
||||||
read_long(data, entry->beg_line);
|
read_long(data, entry->beg_line);
|
||||||
entry->end_pos = read_long<unsigned long>(data);
|
entry->end_pos = read_long<unsigned long>(data);
|
||||||
|
|
@ -140,7 +141,7 @@ void read_entry_base(const char *& data, entry_base_t * entry,
|
||||||
|
|
||||||
bool ignore_calculated = read_bool(data);
|
bool ignore_calculated = read_bool(data);
|
||||||
|
|
||||||
for (unsigned long i = 0, count = read_long<unsigned long>(data);
|
for (std::size_t i = 0, count = read_long<std::size_t>(data);
|
||||||
i < count;
|
i < count;
|
||||||
i++) {
|
i++) {
|
||||||
new(xact_pool) xact_t;
|
new(xact_pool) xact_t;
|
||||||
|
|
@ -160,10 +161,8 @@ void write_entry_base(std::ostream& out, entry_base_t * entry)
|
||||||
write_long(out, entry->end_line);
|
write_long(out, entry->end_line);
|
||||||
|
|
||||||
bool ignore_calculated = false;
|
bool ignore_calculated = false;
|
||||||
for (xacts_list::const_iterator i = entry->xacts.begin();
|
foreach (transaction_t * xact, entry->xacts)
|
||||||
i != entry->xacts.end();
|
if (xact->amount_expr) {
|
||||||
i++)
|
|
||||||
if ((*i)->amount_expr) {
|
|
||||||
ignore_calculated = true;
|
ignore_calculated = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -171,10 +170,8 @@ void write_entry_base(std::ostream& out, entry_base_t * entry)
|
||||||
write_bool(out, ignore_calculated);
|
write_bool(out, ignore_calculated);
|
||||||
|
|
||||||
write_long(out, entry->xacts.size());
|
write_long(out, entry->xacts.size());
|
||||||
for (xacts_list::const_iterator i = entry->xacts.begin();
|
foreach (transaction_t * xact, entry->xacts)
|
||||||
i != entry->xacts.end();
|
write_xact(out, xact, ignore_calculated);
|
||||||
i++)
|
|
||||||
write_xact(out, *i, ignore_calculated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_entry(const char *& data, entry_t * entry,
|
void read_entry(const char *& data, entry_t * entry,
|
||||||
|
|
@ -271,7 +268,10 @@ void read_commodity_base_extra(const char *& data,
|
||||||
commodity_t::base_t * commodity = base_commodities[ident];
|
commodity_t::base_t * commodity = base_commodities[ident];
|
||||||
|
|
||||||
bool read_history = false;
|
bool read_history = false;
|
||||||
for (unsigned long i = 0, count = read_long<unsigned long>(data);
|
// jww (2008-07-31): create a function read_size which does
|
||||||
|
// read_long<std::size_t>. Don't use read_number<std::size_t>, but it
|
||||||
|
// wastes too much space.
|
||||||
|
for (std::size_t i = 0, count = read_long<std::size_t>(data);
|
||||||
i < count;
|
i < count;
|
||||||
i++) {
|
i++) {
|
||||||
datetime_t when;
|
datetime_t when;
|
||||||
|
|
@ -316,12 +316,10 @@ void write_commodity_base_extra(std::ostream& out,
|
||||||
write_long<unsigned long>(out, 0);
|
write_long<unsigned long>(out, 0);
|
||||||
} else {
|
} else {
|
||||||
write_long<unsigned long>(out, commodity->history->prices.size());
|
write_long<unsigned long>(out, commodity->history->prices.size());
|
||||||
for (commodity_t::history_map::const_iterator
|
foreach (commodity_t::history_map::value_type& pair,
|
||||||
i = commodity->history->prices.begin();
|
commodity->history->prices) {
|
||||||
i != commodity->history->prices.end();
|
write_number(out, pair.first);
|
||||||
i++) {
|
pair.second.write(out);
|
||||||
write_number(out, (*i).first);
|
|
||||||
(*i).second.write(out);
|
|
||||||
}
|
}
|
||||||
write_number(out, commodity->history->last_lookup);
|
write_number(out, commodity->history->last_lookup);
|
||||||
}
|
}
|
||||||
|
|
@ -452,8 +450,7 @@ account_t * read_account(const char *& data, account_t * master = NULL)
|
||||||
acct = master;
|
acct = master;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (account_t::ident_t i = 0,
|
for (std::size_t i = 0, count = read_long<std::size_t>(data);
|
||||||
count = read_long<account_t::ident_t>(data);
|
|
||||||
i < count;
|
i < count;
|
||||||
i++) {
|
i++) {
|
||||||
account_t * child = read_account(data);
|
account_t * child = read_account(data);
|
||||||
|
|
@ -470,10 +467,8 @@ namespace {
|
||||||
{
|
{
|
||||||
account_t::ident_t count = 1;
|
account_t::ident_t count = 1;
|
||||||
|
|
||||||
for (accounts_map::iterator i = account->accounts.begin();
|
foreach (accounts_map::value_type& pair, account->accounts)
|
||||||
i != account->accounts.end();
|
count += count_accounts(pair.second);
|
||||||
i++)
|
|
||||||
count += count_accounts((*i).second);
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
@ -494,10 +489,8 @@ void write_account(std::ostream& out, account_t * account)
|
||||||
|
|
||||||
write_number<std::size_t>(out, account->accounts.size());
|
write_number<std::size_t>(out, account->accounts.size());
|
||||||
|
|
||||||
for (accounts_map::iterator i = account->accounts.begin();
|
foreach (accounts_map::value_type& pair, account->accounts)
|
||||||
i != account->accounts.end();
|
write_account(out, pair.second);
|
||||||
i++)
|
|
||||||
write_account(out, (*i).second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int read_journal(std::istream& in,
|
unsigned int read_journal(std::istream& in,
|
||||||
|
|
@ -511,8 +504,7 @@ unsigned int read_journal(std::istream& in,
|
||||||
// can be checked for changes on reading.
|
// can be checked for changes on reading.
|
||||||
|
|
||||||
if (! file.empty()) {
|
if (! file.empty()) {
|
||||||
for (unsigned short i = 0,
|
for (unsigned short i = 0, count = read_number<unsigned short>(in);
|
||||||
count = read_number<unsigned short>(in);
|
|
||||||
i < count;
|
i < count;
|
||||||
i++) {
|
i++) {
|
||||||
path pathname = read_string(in);
|
path pathname = read_string(in);
|
||||||
|
|
@ -590,12 +582,10 @@ write_journal(std::ostream& out, const journal_t& journal)
|
||||||
write_number<unsigned short>(out, 0);
|
write_number<unsigned short>(out, 0);
|
||||||
} else {
|
} else {
|
||||||
write_number<unsigned short>(out, sources.size());
|
write_number<unsigned short>(out, sources.size());
|
||||||
for (paths_list::const_iterator i = sources.begin();
|
foreach (const path& path, sources) {
|
||||||
i != sources.end();
|
write_string(out, path.string());
|
||||||
i++) {
|
|
||||||
write_string(out, (*i).string());
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
stat((*i).string().c_str(), &info);
|
stat(path.string().c_str(), &info);
|
||||||
write_number(out, std::time_t(info.st_mtime));
|
write_number(out, std::time_t(info.st_mtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -623,31 +613,25 @@ write_journal(std::ostream& out, const journal_t& journal)
|
||||||
std::size_t this_entry_count = 0;
|
std::size_t this_entry_count = 0;
|
||||||
std::size_t this_xact_count = 0;
|
std::size_t this_xact_count = 0;
|
||||||
|
|
||||||
for (entries_list::const_iterator i = entries.begin();
|
foreach (entry_t * entry, entries) {
|
||||||
i != entries.end();
|
write_entry(out, entry);
|
||||||
i++) {
|
|
||||||
write_entry(out, *i);
|
|
||||||
|
|
||||||
this_entry_count++;
|
this_entry_count++;
|
||||||
this_xact_count += (*i)->xacts.size();
|
this_xact_count += entry->xacts.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto_entries_list::const_iterator i = auto_entries.begin();
|
foreach (auto_entry_t * entry, auto_entries) {
|
||||||
i != auto_entries.end();
|
write_auto_entry(out, entry);
|
||||||
i++) {
|
|
||||||
write_auto_entry(out, *i);
|
|
||||||
|
|
||||||
this_entry_count++;
|
this_entry_count++;
|
||||||
this_xact_count += (*i)->xacts.size();
|
this_xact_count += entry->xacts.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (period_entries_list::const_iterator i = period_entries.begin();
|
foreach (period_entry_t * entry, period_entries) {
|
||||||
i != period_entries.end();
|
write_period_entry(out, entry);
|
||||||
i++) {
|
|
||||||
write_period_entry(out, *i);
|
|
||||||
|
|
||||||
this_entry_count++;
|
this_entry_count++;
|
||||||
this_xact_count += (*i)->xacts.size();
|
this_xact_count += entry->xacts.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::pair<std::size_t, std::size_t>(this_entry_count,
|
return std::pair<std::size_t, std::size_t>(this_entry_count,
|
||||||
|
|
@ -834,31 +818,24 @@ void write_session(std::ostream& out, session_t& session)
|
||||||
write_number<std::size_t>(out, session.commodity_pool->commodities.size());
|
write_number<std::size_t>(out, session.commodity_pool->commodities.size());
|
||||||
write_number<std::size_t>(out, session.commodity_pool->commodities.size());
|
write_number<std::size_t>(out, session.commodity_pool->commodities.size());
|
||||||
|
|
||||||
for (base_commodities_map::const_iterator i =
|
for (base_commodities_map::value_type pair, commodity_t::base_t::commodities)
|
||||||
commodity_t::base_t::commodities.begin();
|
write_commodity_base(out, pair.second);
|
||||||
i != commodity_t::base_t::commodities.end();
|
|
||||||
i++)
|
|
||||||
write_commodity_base(out, (*i).second);
|
|
||||||
|
|
||||||
write_number<commodity_t::ident_t>
|
write_number<commodity_t::ident_t>
|
||||||
(out, commodity_t::commodities.size());
|
(out, commodity_t::commodities.size());
|
||||||
|
|
||||||
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
|
for (commodities_map::value_type pair, commodity_t::commodities) {
|
||||||
i != commodity_t::commodities.end();
|
if (! pair.second->annotated) {
|
||||||
i++) {
|
|
||||||
if (! (*i).second->annotated) {
|
|
||||||
write_bool(out, false);
|
write_bool(out, false);
|
||||||
write_commodity(out, (*i).second);
|
write_commodity(out, pair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (commodities_map::const_iterator i = commodity_t::commodities.begin();
|
for (commodities_map::value_type pair, commodity_t::commodities) {
|
||||||
i != commodity_t::commodities.end();
|
if (pair.second->annotated) {
|
||||||
i++) {
|
|
||||||
if ((*i).second->annotated) {
|
|
||||||
write_bool(out, true);
|
write_bool(out, true);
|
||||||
write_string(out, (*i).first); // the mapping key
|
write_string(out, pair.first); // the mapping key
|
||||||
write_commodity_annotated(out, (*i).second);
|
write_commodity_annotated(out, pair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,8 @@ commodity_t::operator bool() const
|
||||||
|
|
||||||
bool commodity_t::symbol_needs_quotes(const string& symbol)
|
bool commodity_t::symbol_needs_quotes(const string& symbol)
|
||||||
{
|
{
|
||||||
for (const char * p = symbol.c_str(); *p; p++)
|
foreach (char ch, symbol)
|
||||||
if (std::isspace(*p) || std::isdigit(*p) || *p == '-' || *p == '.')
|
if (std::isspace(ch) || std::isdigit(ch) || ch == '-' || ch == '.')
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
6
csv.cc
6
csv.cc
|
|
@ -6,12 +6,12 @@ namespace {
|
||||||
inline void write_escaped_string(std::ostream& out, const string& xact)
|
inline void write_escaped_string(std::ostream& out, const string& xact)
|
||||||
{
|
{
|
||||||
out << "\"";
|
out << "\"";
|
||||||
for (string::const_iterator i = xact.begin(); i != xact.end(); i++)
|
foreach (char ch, xact)
|
||||||
if (*i == '"') {
|
if (ch == '"') {
|
||||||
out << "\\";
|
out << "\\";
|
||||||
out << "\"";
|
out << "\"";
|
||||||
} else {
|
} else {
|
||||||
out << *i;
|
out << ch;
|
||||||
}
|
}
|
||||||
out << "\"";
|
out << "\"";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
derive.cc
17
derive.cc
|
|
@ -96,10 +96,8 @@ entry_t * derive_new_entry(report_t& report,
|
||||||
// to see the same xact as last time.
|
// to see the same xact as last time.
|
||||||
added->code = matching->code;
|
added->code = matching->code;
|
||||||
|
|
||||||
for (xacts_list::iterator k = matching->xacts.begin();
|
foreach (xact_t * xact, matching->xacts)
|
||||||
k != matching->xacts.end();
|
added->add_xact(new xact_t(*xact));
|
||||||
k++)
|
|
||||||
added->add_xact(new xact_t(**k));
|
|
||||||
}
|
}
|
||||||
else if ((*i)[0] == '-' || std::isdigit((*i)[0])) {
|
else if ((*i)[0] == '-' || std::isdigit((*i)[0])) {
|
||||||
xact_t * m_xact, * xact, * first;
|
xact_t * m_xact, * xact, * first;
|
||||||
|
|
@ -137,13 +135,10 @@ entry_t * derive_new_entry(report_t& report,
|
||||||
for (; j != matching->journal->entries.rend(); j++)
|
for (; j != matching->journal->entries.rend(); j++)
|
||||||
if (regexp.match((*j)->payee)) {
|
if (regexp.match((*j)->payee)) {
|
||||||
entry_t * entry = *j;
|
entry_t * entry = *j;
|
||||||
for (xacts_list::const_iterator x =
|
foreach (xact_t * xact, entry->xacts)
|
||||||
entry->xacts.begin();
|
if (acct_regex.match(xact->account->fullname())) {
|
||||||
x != entry->xacts.end();
|
acct = xact->account;
|
||||||
x++)
|
amt = &xact->amount;
|
||||||
if (acct_regex.match((*x)->account->fullname())) {
|
|
||||||
acct = (*x)->account;
|
|
||||||
amt = &(*x)->amount;
|
|
||||||
matching = entry;
|
matching = entry;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
emacs.cc
6
emacs.cc
|
|
@ -5,11 +5,9 @@ namespace ledger {
|
||||||
void format_emacs_xacts::write_entry(entry_t& entry)
|
void format_emacs_xacts::write_entry(entry_t& entry)
|
||||||
{
|
{
|
||||||
int idx = entry.src_idx;
|
int idx = entry.src_idx;
|
||||||
for (paths_list::const_iterator i = entry.journal->sources.begin();
|
foreach (const path& path, entry.journal->sources)
|
||||||
i != entry.journal->sources.end();
|
|
||||||
i++)
|
|
||||||
if (! idx--) {
|
if (! idx--) {
|
||||||
out << "\"" << *i << "\" ";
|
out << "\"" << path << "\" ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
146
entry.cc
146
entry.cc
|
|
@ -40,29 +40,24 @@ entry_base_t::entry_base_t(const entry_base_t& e)
|
||||||
beg_pos(0), beg_line(0), end_pos(0), end_line(0)
|
beg_pos(0), beg_line(0), end_pos(0), end_line(0)
|
||||||
{
|
{
|
||||||
TRACE_CTOR(entry_base_t, "copy");
|
TRACE_CTOR(entry_base_t, "copy");
|
||||||
|
xacts.insert(xacts.end(), e.xacts.begin(), e.xacts.end());
|
||||||
for (xacts_list::const_iterator i = e.xacts.begin();
|
|
||||||
i != e.xacts.end();
|
|
||||||
i++)
|
|
||||||
xacts.push_back(new xact_t(**i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_base_t::~entry_base_t()
|
entry_base_t::~entry_base_t()
|
||||||
{
|
{
|
||||||
TRACE_DTOR(entry_base_t);
|
TRACE_DTOR(entry_base_t);
|
||||||
|
|
||||||
for (xacts_list::iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
i != xacts.end();
|
|
||||||
i++)
|
|
||||||
// If the transaction is a temporary, it will be destructed when the
|
// If the transaction is a temporary, it will be destructed when the
|
||||||
// temporary is. If it's from a binary cache, we can safely destruct it
|
// temporary is. If it's from a binary cache, we can safely destruct it
|
||||||
// but its memory will be deallocated with the cache.
|
// but its memory will be deallocated with the cache.
|
||||||
if (! (*i)->has_flags(XACT_TEMP)) {
|
if (! xact->has_flags(XACT_TEMP)) {
|
||||||
if (! (*i)->has_flags(XACT_IN_CACHE))
|
if (! xact->has_flags(XACT_IN_CACHE))
|
||||||
checked_delete(*i);
|
checked_delete(xact);
|
||||||
else
|
else
|
||||||
(*i)->~xact_t();
|
xact->~xact_t();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry_base_t::add_xact(xact_t * xact)
|
void entry_base_t::add_xact(xact_t * xact)
|
||||||
|
|
@ -85,7 +80,7 @@ bool entry_base_t::finalize()
|
||||||
// (let ((balance 0)
|
// (let ((balance 0)
|
||||||
// null-xact)
|
// null-xact)
|
||||||
|
|
||||||
value_t balance;
|
value_t balance;
|
||||||
xact_t * null_xact = NULL;
|
xact_t * null_xact = NULL;
|
||||||
|
|
||||||
// (do-xacts (xact entry)
|
// (do-xacts (xact entry)
|
||||||
|
|
@ -101,11 +96,9 @@ bool entry_base_t::finalize()
|
||||||
// (setf null-xact xact))))))
|
// (setf null-xact xact))))))
|
||||||
//
|
//
|
||||||
|
|
||||||
for (xacts_list::const_iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
x != xacts.end();
|
if (xact->must_balance()) {
|
||||||
x++) {
|
amount_t& p(xact->cost ? *xact->cost : xact->amount);
|
||||||
if ((*x)->must_balance()) {
|
|
||||||
amount_t& p((*x)->cost ? *(*x)->cost : (*x)->amount);
|
|
||||||
if (! p.is_null()) {
|
if (! p.is_null()) {
|
||||||
if (balance.is_null())
|
if (balance.is_null())
|
||||||
balance = p;
|
balance = p;
|
||||||
|
|
@ -116,7 +109,7 @@ bool entry_base_t::finalize()
|
||||||
throw_(std::logic_error,
|
throw_(std::logic_error,
|
||||||
"Only one xact with null amount allowed per entry");
|
"Only one xact with null amount allowed per entry");
|
||||||
else
|
else
|
||||||
null_xact = *x;
|
null_xact = xact;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,16 +165,13 @@ bool entry_base_t::finalize()
|
||||||
if (balance.is_balance()) {
|
if (balance.is_balance()) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
const balance_t& bal(balance.as_balance());
|
const balance_t& bal(balance.as_balance());
|
||||||
for (balance_t::amounts_map::const_iterator i = bal.amounts.begin();
|
foreach (const balance_t::amounts_map::value_type& pair, bal.amounts) {
|
||||||
i != bal.amounts.end();
|
|
||||||
i++) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
null_xact->amount = (*i).second.negate();
|
null_xact->amount = pair.second.negate();
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
add_xact(new xact_t(null_xact->account,
|
add_xact(new xact_t(null_xact->account, pair.second.negate(),
|
||||||
(*i).second.negate(),
|
XACT_GENERATED));
|
||||||
XACT_GENERATED));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -226,13 +216,11 @@ bool entry_base_t::finalize()
|
||||||
|
|
||||||
commodity_t& comm(x.commodity());
|
commodity_t& comm(x.commodity());
|
||||||
|
|
||||||
for (xacts_list::const_iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
x != xacts.end();
|
const amount_t& x_amt(xact->amount);
|
||||||
x++) {
|
|
||||||
const amount_t& x_amt((*x)->amount);
|
|
||||||
|
|
||||||
if (! ((*x)->cost ||
|
if (! (xact->cost ||
|
||||||
! (*x)->must_balance() ||
|
! xact->must_balance() ||
|
||||||
x_amt.commodity() == comm)) {
|
x_amt.commodity() == comm)) {
|
||||||
DEBUG("ledger.journal.finalize", "before operation 1 = " << balance);
|
DEBUG("ledger.journal.finalize", "before operation 1 = " << balance);
|
||||||
balance -= x_amt;
|
balance -= x_amt;
|
||||||
|
|
@ -240,10 +228,10 @@ bool entry_base_t::finalize()
|
||||||
DEBUG("ledger.journal.finalize", "x_amt = " << x_amt);
|
DEBUG("ledger.journal.finalize", "x_amt = " << x_amt);
|
||||||
DEBUG("ledger.journal.finalize", "per_unit_cost = " << per_unit_cost);
|
DEBUG("ledger.journal.finalize", "per_unit_cost = " << per_unit_cost);
|
||||||
|
|
||||||
(*x)->cost = per_unit_cost * x_amt;
|
xact->cost = per_unit_cost * x_amt;
|
||||||
DEBUG("ledger.journal.finalize", "*(*x)->cost = " << *(*x)->cost);
|
DEBUG("ledger.journal.finalize", "*xact->cost = " << *xact->cost);
|
||||||
|
|
||||||
balance += *(*x)->cost;
|
balance += *xact->cost;
|
||||||
DEBUG("ledger.journal.finalize", "after operation 2 = " << balance);
|
DEBUG("ledger.journal.finalize", "after operation 2 = " << balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,13 +262,11 @@ bool entry_base_t::finalize()
|
||||||
// (add balance (subtract basis-cost total-cost))))
|
// (add balance (subtract basis-cost total-cost))))
|
||||||
// (setf (xact-amount* xact) annotated-amount))))))
|
// (setf (xact-amount* xact) annotated-amount))))))
|
||||||
|
|
||||||
for (xacts_list::const_iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
x != xacts.end();
|
if (xact->cost) {
|
||||||
x++) {
|
const amount_t& x_amt(xact->amount);
|
||||||
if ((*x)->cost) {
|
|
||||||
const amount_t& x_amt((*x)->amount);
|
|
||||||
|
|
||||||
assert(x_amt.commodity() != (*x)->cost->commodity());
|
assert(x_amt.commodity() != xact->cost->commodity());
|
||||||
|
|
||||||
entry_t * entry = dynamic_cast<entry_t *>(this);
|
entry_t * entry = dynamic_cast<entry_t *>(this);
|
||||||
|
|
||||||
|
|
@ -290,10 +276,10 @@ bool entry_base_t::finalize()
|
||||||
amount_t basis_cost;
|
amount_t basis_cost;
|
||||||
amount_t ann_amount =
|
amount_t ann_amount =
|
||||||
commodity_t::exchange(x_amt, final_cost, basis_cost,
|
commodity_t::exchange(x_amt, final_cost, basis_cost,
|
||||||
(*x)->cost, none, (*x)->actual_date(),
|
xact->cost, none, xact->actual_date(),
|
||||||
entry ? entry->code : optional<string>());
|
entry ? entry->code : optional<string>());
|
||||||
|
|
||||||
if ((*x)->amount.annotated()) {
|
if (xact->amount.annotated()) {
|
||||||
if (ann_amount.annotation().price) {
|
if (ann_amount.annotation().price) {
|
||||||
if (balance.is_null())
|
if (balance.is_null())
|
||||||
balance = basis_cost - final_cost;
|
balance = basis_cost - final_cost;
|
||||||
|
|
@ -301,7 +287,7 @@ bool entry_base_t::finalize()
|
||||||
balance += basis_cost - final_cost;
|
balance += basis_cost - final_cost;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(*x)->amount = ann_amount;
|
xact->amount = ann_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -340,10 +326,8 @@ entry_t::entry_t(const entry_t& e)
|
||||||
{
|
{
|
||||||
TRACE_CTOR(entry_t, "copy");
|
TRACE_CTOR(entry_t, "copy");
|
||||||
|
|
||||||
for (xacts_list::const_iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts)
|
||||||
i != xacts.end();
|
xact->entry = this;
|
||||||
i++)
|
|
||||||
(*i)->entry = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool entry_t::get_state(xact_t::state_t * state) const
|
bool entry_t::get_state(xact_t::state_t * state) const
|
||||||
|
|
@ -351,14 +335,12 @@ bool entry_t::get_state(xact_t::state_t * state) const
|
||||||
bool first = true;
|
bool first = true;
|
||||||
bool hetero = false;
|
bool hetero = false;
|
||||||
|
|
||||||
for (xacts_list::const_iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
i != xacts.end();
|
|
||||||
i++) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
*state = (*i)->state;
|
*state = xact->state;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
else if (*state != (*i)->state) {
|
else if (*state != xact->state) {
|
||||||
hetero = true;
|
hetero = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -416,10 +398,8 @@ bool entry_t::valid() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (xacts_list::const_iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts)
|
||||||
i != xacts.end();
|
if (xact->entry != this || ! xact->valid()) {
|
||||||
i++)
|
|
||||||
if ((*i)->entry != this || ! (*i)->valid()) {
|
|
||||||
DEBUG("ledger.validate", "entry_t: xact not valid");
|
DEBUG("ledger.validate", "entry_t: xact not valid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -442,47 +422,43 @@ void auto_entry_t::extend_entry(entry_base_t& entry, bool post)
|
||||||
xacts_list initial_xacts(entry.xacts.begin(),
|
xacts_list initial_xacts(entry.xacts.begin(),
|
||||||
entry.xacts.end());
|
entry.xacts.end());
|
||||||
|
|
||||||
for (xacts_list::iterator i = initial_xacts.begin();
|
foreach (xact_t * initial_xact, initial_xacts) {
|
||||||
i != initial_xacts.end();
|
if (predicate(*initial_xact)) {
|
||||||
i++) {
|
foreach (xact_t * xact, xacts) {
|
||||||
if (predicate(**i)) {
|
|
||||||
for (xacts_list::iterator t = xacts.begin();
|
|
||||||
t != xacts.end();
|
|
||||||
t++) {
|
|
||||||
amount_t amt;
|
amount_t amt;
|
||||||
assert((*t)->amount);
|
assert(xact->amount);
|
||||||
if (! (*t)->amount.commodity()) {
|
if (! xact->amount.commodity()) {
|
||||||
if (! post)
|
if (! post)
|
||||||
continue;
|
continue;
|
||||||
assert((*i)->amount);
|
assert(initial_xact->amount);
|
||||||
amt = (*i)->amount * (*t)->amount;
|
amt = initial_xact->amount * xact->amount;
|
||||||
} else {
|
} else {
|
||||||
if (post)
|
if (post)
|
||||||
continue;
|
continue;
|
||||||
amt = (*t)->amount;
|
amt = xact->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
account_t * account = (*t)->account;
|
account_t * account = xact->account;
|
||||||
string fullname = account->fullname();
|
string fullname = account->fullname();
|
||||||
assert(! fullname.empty());
|
assert(! fullname.empty());
|
||||||
if (fullname == "$account" || fullname == "@account")
|
if (fullname == "$account" || fullname == "@account")
|
||||||
account = (*i)->account;
|
account = initial_xact->account;
|
||||||
|
|
||||||
xact_t * xact
|
xact_t * new_xact
|
||||||
= new xact_t(account, amt, (*t)->flags() | XACT_AUTO);
|
= new xact_t(account, amt, xact->flags() | XACT_AUTO);
|
||||||
|
|
||||||
// Copy over details so that the resulting xact is a mirror of
|
// Copy over details so that the resulting xact is a mirror of
|
||||||
// the automated entry's one.
|
// the automated entry's one.
|
||||||
xact->state = (*t)->state;
|
new_xact->state = xact->state;
|
||||||
xact->_date = (*t)->_date;
|
new_xact->_date = xact->_date;
|
||||||
xact->_date_eff = (*t)->_date_eff;
|
new_xact->_date_eff = xact->_date_eff;
|
||||||
xact->note = (*t)->note;
|
new_xact->note = xact->note;
|
||||||
xact->beg_pos = (*t)->beg_pos;
|
new_xact->beg_pos = xact->beg_pos;
|
||||||
xact->beg_line = (*t)->beg_line;
|
new_xact->beg_line = xact->beg_line;
|
||||||
xact->end_pos = (*t)->end_pos;
|
new_xact->end_pos = xact->end_pos;
|
||||||
xact->end_line = (*t)->end_line;
|
new_xact->end_line = xact->end_line;
|
||||||
|
|
||||||
entry.add_xact(xact);
|
entry.add_xact(new_xact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -490,10 +466,8 @@ void auto_entry_t::extend_entry(entry_base_t& entry, bool post)
|
||||||
|
|
||||||
void extend_entry_base(journal_t * journal, entry_base_t& entry, bool post)
|
void extend_entry_base(journal_t * journal, entry_base_t& entry, bool post)
|
||||||
{
|
{
|
||||||
for (auto_entries_list::iterator i = journal->auto_entries.begin();
|
foreach (auto_entry_t * entry, journal->auto_entries)
|
||||||
i != journal->auto_entries.end();
|
entry->extend_entry(*entry, post);
|
||||||
i++)
|
|
||||||
(*i)->extend_entry(entry, post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
4
entry.h
4
entry.h
|
|
@ -225,10 +225,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<entry_t *> entries_list;
|
|
||||||
typedef std::list<auto_entry_t *> auto_entries_list;
|
|
||||||
typedef std::list<period_entry_t *> period_entries_list;
|
|
||||||
|
|
||||||
void extend_entry_base(journal_t * journal, entry_base_t& entry, bool post);
|
void extend_entry_base(journal_t * journal, entry_base_t& entry, bool post);
|
||||||
|
|
||||||
inline bool auto_entry_finalizer_t::operator()(entry_t& entry, bool post) {
|
inline bool auto_entry_finalizer_t::operator()(entry_t& entry, bool post) {
|
||||||
|
|
|
||||||
56
format.cc
56
format.cc
|
|
@ -504,17 +504,15 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
||||||
xact_t * first = NULL;
|
xact_t * first = NULL;
|
||||||
xact_t * last = NULL;
|
xact_t * last = NULL;
|
||||||
|
|
||||||
for (xacts_list::const_iterator i
|
foreach (const transaction_t * xact, details.entry->xacts) {
|
||||||
= details.entry->xacts.begin();
|
if (xact_has_xdata(*xact) &&
|
||||||
i != details.entry->xacts.end();
|
xact_xdata_(*xact).dflags & XACT_TO_DISPLAY) {
|
||||||
i++)
|
|
||||||
if (xact_has_xdata(**i) &&
|
|
||||||
xact_xdata_(**i).dflags & XACT_TO_DISPLAY) {
|
|
||||||
xacts_count++;
|
xacts_count++;
|
||||||
if (! first)
|
if (! first)
|
||||||
first = *i;
|
first = xact;
|
||||||
last = *i;
|
last = xact;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use_disp = (xacts_count == 2 && details.xact == last &&
|
use_disp = (xacts_count == 2 && details.xact == last &&
|
||||||
first->amount == - last->amount);
|
first->amount == - last->amount);
|
||||||
|
|
@ -534,11 +532,9 @@ void format_t::format(std::ostream& out_str, scope_t& scope) const
|
||||||
case element_t::SOURCE:
|
case element_t::SOURCE:
|
||||||
if (details.entry && details.entry->journal) {
|
if (details.entry && details.entry->journal) {
|
||||||
int idx = details.entry->src_idx;
|
int idx = details.entry->src_idx;
|
||||||
for (paths_list::const_iterator i = details.entry->journal->sources.begin();
|
foreach (const path& path, details.entry->journal->sources)
|
||||||
i != details.entry->journal->sources.end();
|
|
||||||
i++)
|
|
||||||
if (! idx--) {
|
if (! idx--) {
|
||||||
out << *i;
|
out << path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -808,18 +804,16 @@ void format_entries::format_last_entry()
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (xacts_list::const_iterator i = last_entry->xacts.begin();
|
foreach (const transaction_t * xact, last_entry->xacts) {
|
||||||
i != last_entry->xacts.end();
|
if (xact_has_xdata(*xact) &&
|
||||||
i++) {
|
xact_xdata_(*xact).dflags & XACT_TO_DISPLAY) {
|
||||||
if (xact_has_xdata(**i) &&
|
|
||||||
xact_xdata_(**i).dflags & XACT_TO_DISPLAY) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first_line_format.format(output_stream, details_t(**i));
|
first_line_format.format(output_stream, details_t(*xact));
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
next_lines_format.format(output_stream, details_t(**i));
|
next_lines_format.format(output_stream, details_t(*xact));
|
||||||
}
|
}
|
||||||
xact_xdata_(**i).dflags |= XACT_DISPLAYED;
|
xact_xdata_(*xact).dflags |= XACT_DISPLAYED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -885,13 +879,11 @@ bool disp_subaccounts_p(const account_t& account,
|
||||||
to_show = NULL;
|
to_show = NULL;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
for (accounts_map::const_iterator i = account.accounts.begin();
|
for (accounts_map::value_type pair, account.accounts) {
|
||||||
i != account.accounts.end();
|
if (disp_pred && ! (*disp_pred)(*pair.second))
|
||||||
i++) {
|
|
||||||
if (disp_pred && ! (*disp_pred)(*(*i).second))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
compute_total(result, details_t(*(*i).second));
|
compute_total(result, details_t(*pair.second));
|
||||||
if (! computed) {
|
if (! computed) {
|
||||||
compute_total(acct_total, details_t(account));
|
compute_total(acct_total, details_t(account));
|
||||||
computed = true;
|
computed = true;
|
||||||
|
|
@ -901,7 +893,7 @@ bool disp_subaccounts_p(const account_t& account,
|
||||||
display = matches;
|
display = matches;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
to_show = (*i).second;
|
to_show = pair.second;
|
||||||
counted++;
|
counted++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -986,10 +978,8 @@ void format_equity::flush()
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
for (balance_t::amounts_map::const_iterator i = bal->amounts.begin();
|
for (balance_t::amounts_map::value_type pair, bal->amounts) {
|
||||||
i != bal->amounts.end();
|
xdata.value = pair.second;
|
||||||
i++) {
|
|
||||||
xdata.value = (*i).second;
|
|
||||||
xdata.value.negate();
|
xdata.value.negate();
|
||||||
next_lines_format.format(output_stream, details_t(summary));
|
next_lines_format.format(output_stream, details_t(summary));
|
||||||
}
|
}
|
||||||
|
|
@ -1016,10 +1006,8 @@ void format_equity::operator()(account_t& account)
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
for (balance_t::amounts_map::const_iterator i = bal->amounts.begin();
|
for (balance_t::amounts_map::value_type pair, bal->amounts) {
|
||||||
i != bal->amounts.end();
|
account_xdata_(account).value = pair.second;
|
||||||
i++) {
|
|
||||||
account_xdata_(account).value = (*i).second;
|
|
||||||
next_lines_format.format(output_stream, details_t(account));
|
next_lines_format.format(output_stream, details_t(account));
|
||||||
}
|
}
|
||||||
account_xdata_(account).value = val;
|
account_xdata_(account).value = val;
|
||||||
|
|
|
||||||
25
hooks.h
25
hooks.h
|
|
@ -32,10 +32,14 @@
|
||||||
#ifndef _HOOKS_H
|
#ifndef _HOOKS_H
|
||||||
#define _HOOKS_H
|
#define _HOOKS_H
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Data>
|
||||||
class hooks_t : public boost::noncopyable
|
class hooks_t : public boost::noncopyable
|
||||||
{
|
{
|
||||||
std::list<T> list;
|
public:
|
||||||
|
typedef boost::function<bool (Data&, bool)> function_t;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::list<T *> list;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
hooks_t() {
|
hooks_t() {
|
||||||
|
|
@ -45,23 +49,20 @@ public:
|
||||||
TRACE_DTOR(hooks_t);
|
TRACE_DTOR(hooks_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_hook(T obj, const bool prepend = false) {
|
void add_hook(T * func, const bool prepend = false) {
|
||||||
if (prepend)
|
if (prepend)
|
||||||
list.push_front(obj);
|
list.push_front(func);
|
||||||
else
|
else
|
||||||
list.push_back(obj);
|
list.push_back(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_hook(T obj) {
|
void remove_hook(T * func) {
|
||||||
list.remove(obj);
|
list.remove(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
|
||||||
bool run_hooks(Data& item, bool post) {
|
bool run_hooks(Data& item, bool post) {
|
||||||
for (typename std::list<T>::const_iterator i = list.begin();
|
foreach (T * func, list)
|
||||||
i != list.end();
|
if (! (*func)(item, post))
|
||||||
i++)
|
|
||||||
if (! (*(*i))(item, post))
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
48
journal.cc
48
journal.cc
|
|
@ -50,29 +50,23 @@ journal_t::~journal_t()
|
||||||
// Don't bother unhooking each entry's xacts from the
|
// Don't bother unhooking each entry's xacts from the
|
||||||
// accounts they refer to, because all accounts are about to
|
// accounts they refer to, because all accounts are about to
|
||||||
// be deleted.
|
// be deleted.
|
||||||
for (entries_list::iterator i = entries.begin();
|
foreach (entry_t * entry, entries)
|
||||||
i != entries.end();
|
if (! entry->has_flags(ENTRY_IN_CACHE))
|
||||||
i++)
|
checked_delete(entry);
|
||||||
if (! (*i)->has_flags(ENTRY_IN_CACHE))
|
|
||||||
checked_delete(*i);
|
|
||||||
else
|
else
|
||||||
(*i)->~entry_t();
|
entry->~entry_t();
|
||||||
|
|
||||||
for (auto_entries_list::iterator i = auto_entries.begin();
|
foreach (auto_entry_t * entry, auto_entries)
|
||||||
i != auto_entries.end();
|
if (! entry->has_flags(ENTRY_IN_CACHE))
|
||||||
i++)
|
checked_delete(entry);
|
||||||
if (! (*i)->has_flags(ENTRY_IN_CACHE))
|
|
||||||
checked_delete(*i);
|
|
||||||
else
|
else
|
||||||
(*i)->~auto_entry_t();
|
entry->~auto_entry_t();
|
||||||
|
|
||||||
for (period_entries_list::iterator i = period_entries.begin();
|
foreach (period_entry_t * entry, period_entries)
|
||||||
i != period_entries.end();
|
if (! entry->has_flags(ENTRY_IN_CACHE))
|
||||||
i++)
|
checked_delete(entry);
|
||||||
if (! (*i)->has_flags(ENTRY_IN_CACHE))
|
|
||||||
checked_delete(*i);
|
|
||||||
else
|
else
|
||||||
(*i)->~period_entry_t();
|
entry->~period_entry_t();
|
||||||
}
|
}
|
||||||
|
|
||||||
void journal_t::add_account(account_t * acct)
|
void journal_t::add_account(account_t * acct)
|
||||||
|
|
@ -108,13 +102,11 @@ bool journal_t::add_entry(entry_t * entry)
|
||||||
|
|
||||||
entries.push_back(entry);
|
entries.push_back(entry);
|
||||||
|
|
||||||
for (xacts_list::const_iterator i = entry->xacts.begin();
|
foreach (const xact_t * xact, entry->xacts)
|
||||||
i != entry->xacts.end();
|
if (xact->cost) {
|
||||||
i++)
|
assert(xact->amount);
|
||||||
if ((*i)->cost) {
|
xact->amount.commodity().add_price(entry->date(),
|
||||||
assert((*i)->amount);
|
*xact->cost / xact->amount.number());
|
||||||
(*i)->amount.commodity().add_price(entry->date(),
|
|
||||||
*(*i)->cost / (*i)->amount.number());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -145,10 +137,8 @@ bool journal_t::valid() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (entries_list::const_iterator i = entries.begin();
|
foreach (const entry_t * entry, entries)
|
||||||
i != entries.end();
|
if (! entry->valid()) {
|
||||||
i++)
|
|
||||||
if (! (*i)->valid()) {
|
|
||||||
DEBUG("ledger.validate", "journal_t: entry not valid");
|
DEBUG("ledger.validate", "journal_t: entry not valid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ typedef std::list<path> paths_list;
|
||||||
class session_t;
|
class session_t;
|
||||||
class account_t;
|
class account_t;
|
||||||
|
|
||||||
|
typedef std::list<entry_t *> entries_list;
|
||||||
|
typedef std::list<auto_entry_t *> auto_entries_list;
|
||||||
|
typedef std::list<period_entry_t *> period_entries_list;
|
||||||
|
|
||||||
class journal_t : public noncopyable
|
class journal_t : public noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -56,7 +60,7 @@ public:
|
||||||
auto_entries_list auto_entries;
|
auto_entries_list auto_entries;
|
||||||
period_entries_list period_entries;
|
period_entries_list period_entries;
|
||||||
|
|
||||||
hooks_t<entry_finalizer_t *> entry_finalize_hooks;
|
hooks_t<entry_finalizer_t, entry_t> entry_finalize_hooks;
|
||||||
|
|
||||||
journal_t(session_t * _owner);
|
journal_t(session_t * _owner);
|
||||||
~journal_t();
|
~journal_t();
|
||||||
|
|
|
||||||
6
op.cc
6
op.cc
|
|
@ -408,10 +408,8 @@ void expr_t::op_t::compute(value_t& result,
|
||||||
result.cast(value_t::AMOUNT);
|
result.cast(value_t::AMOUNT);
|
||||||
} else {
|
} else {
|
||||||
value_t temp;
|
value_t temp;
|
||||||
for (balance_t::amounts_map::const_iterator i = bal->amounts.begin();
|
for (balance_t::amounts_map::value_type pair, bal->amounts) {
|
||||||
i != bal->amounts.end();
|
amount_t x = pair.second;
|
||||||
i++) {
|
|
||||||
amount_t x = (*i).second;
|
|
||||||
x.clear_commodity();
|
x.clear_commodity();
|
||||||
temp += x;
|
temp += x;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ namespace {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
std::strcpy(buf, "option_");
|
std::strcpy(buf, "option_");
|
||||||
char * p = &buf[7];
|
char * p = &buf[7];
|
||||||
for (const char * q = name.c_str(); *q; q++) {
|
foreach (char ch, name) {
|
||||||
if (*q == '-')
|
if (ch == '-')
|
||||||
*p++ = '_';
|
*p++ = '_';
|
||||||
else
|
else
|
||||||
*p++ = *q;
|
*p++ = ch;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
|
|
|
||||||
16
reconcile.cc
16
reconcile.cc
|
|
@ -40,19 +40,17 @@ void reconcile_xacts::flush()
|
||||||
xact_t * first = NULL;
|
xact_t * first = NULL;
|
||||||
xact_t ** last_ptr = &first;
|
xact_t ** last_ptr = &first;
|
||||||
|
|
||||||
for (xacts_list::iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
x != xacts.end();
|
if (! is_valid(cutoff) || xact->date() < cutoff) {
|
||||||
x++) {
|
switch (xact->state) {
|
||||||
if (! is_valid(cutoff) || (*x)->date() < cutoff) {
|
|
||||||
switch ((*x)->state) {
|
|
||||||
case xact_t::CLEARED:
|
case xact_t::CLEARED:
|
||||||
cleared_balance += (*x)->amount;
|
cleared_balance += xact->amount;
|
||||||
break;
|
break;
|
||||||
case xact_t::UNCLEARED:
|
case xact_t::UNCLEARED:
|
||||||
case xact_t::PENDING:
|
case xact_t::PENDING:
|
||||||
pending_balance += (*x)->amount;
|
pending_balance += xact->amount;
|
||||||
*last_ptr = *x;
|
*last_ptr = xact;
|
||||||
last_ptr = xact_next_ptr(*x);
|
last_ptr = xact_next_ptr(xact);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,10 +222,8 @@ namespace {
|
||||||
if (regexp.match(account->fullname()))
|
if (regexp.match(account->fullname()))
|
||||||
return account;
|
return account;
|
||||||
|
|
||||||
for (accounts_map::iterator i = account->accounts.begin();
|
foreach (accounts_map::value_type& pair, account->accounts)
|
||||||
i != account->accounts.end();
|
if (account_t * a = find_account_re_(pair.second, regexp))
|
||||||
i++)
|
|
||||||
if (account_t * a = find_account_re_((*i).second, regexp))
|
|
||||||
return a;
|
return a;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
49
textual.cc
49
textual.cc
|
|
@ -718,12 +718,9 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
account_stack.front()->find_account(p), n ? n : "");
|
account_stack.front()->find_account(p), n ? n : "");
|
||||||
|
|
||||||
if (! time_entries.empty())
|
if (! time_entries.empty())
|
||||||
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
foreach (time_entry_t& time_entry, time_entries)
|
||||||
i != time_entries.end();
|
if (event.account == time_entry.account)
|
||||||
i++)
|
throw parse_error("Cannot double check-in to the same account");
|
||||||
if (event.account == (*i).account)
|
|
||||||
throw parse_error
|
|
||||||
("Cannot double check-in to the same account");
|
|
||||||
|
|
||||||
time_entries.push_back(event);
|
time_entries.push_back(event);
|
||||||
break;
|
break;
|
||||||
|
|
@ -992,15 +989,12 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
if (! time_entries.empty()) {
|
if (! time_entries.empty()) {
|
||||||
std::list<account_t *> accounts;
|
std::list<account_t *> accounts;
|
||||||
|
|
||||||
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
foreach (time_entry_t& time_entry, time_entries)
|
||||||
i != time_entries.end();
|
accounts.push_back(time_entry.account);
|
||||||
i++)
|
|
||||||
accounts.push_back((*i).account);
|
|
||||||
|
|
||||||
for (std::list<account_t *>::iterator i = accounts.begin();
|
foreach (account_t * account, accounts)
|
||||||
i != accounts.end();
|
clock_out_from_timelog(time_entries, current_moment, account,
|
||||||
i++)
|
NULL, journal);
|
||||||
clock_out_from_timelog(time_entries, current_moment, *i, NULL, journal);
|
|
||||||
|
|
||||||
assert(time_entries.empty());
|
assert(time_entries.empty());
|
||||||
}
|
}
|
||||||
|
|
@ -1035,22 +1029,18 @@ void write_textual_journal(journal_t& journal,
|
||||||
|
|
||||||
::realpath(pathname.string().c_str(), buf1);
|
::realpath(pathname.string().c_str(), buf1);
|
||||||
|
|
||||||
for (paths_list::iterator i = journal.sources.begin();
|
foreach (const path& path, journal.sources) {
|
||||||
i != journal.sources.end();
|
::realpath(path.string().c_str(), buf2);
|
||||||
i++) {
|
|
||||||
::realpath((*i).string().c_str(), buf2);
|
|
||||||
if (std::strcmp(buf1, buf2) == 0) {
|
if (std::strcmp(buf1, buf2) == 0) {
|
||||||
found = *i;
|
found = path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for (paths_list::iterator i = journal.sources.begin();
|
foreach (const path& path, journal.sources) {
|
||||||
i != journal.sources.end();
|
if (pathname == path) {
|
||||||
i++) {
|
found = path;
|
||||||
if (pathname == *i) {
|
|
||||||
found = *i;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
|
@ -1090,13 +1080,12 @@ void write_textual_journal(journal_t& journal,
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
if (base) {
|
if (base) {
|
||||||
for (xacts_list::iterator x = base->xacts.begin();
|
foreach (xact_t * xact, base->xacts) {
|
||||||
x != base->xacts.end();
|
if (! xact->has_flags(XACT_AUTO)) {
|
||||||
x++)
|
xact_xdata(*xact).dflags |= XACT_TO_DISPLAY;
|
||||||
if (! (*x)->has_flags(XACT_AUTO)) {
|
(*formatter)(*xact);
|
||||||
xact_xdata(**x).dflags |= XACT_TO_DISPLAY;
|
|
||||||
(*formatter)(**x);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
formatter->flush();
|
formatter->flush();
|
||||||
|
|
||||||
while (pos < base->end_pos) {
|
while (pos < base->end_pos) {
|
||||||
|
|
|
||||||
42
utils.cc
42
utils.cc
|
|
@ -143,10 +143,8 @@ std::size_t current_memory_size()
|
||||||
{
|
{
|
||||||
std::size_t memory_size = 0;
|
std::size_t memory_size = 0;
|
||||||
|
|
||||||
for (object_count_map::const_iterator i = live_memory_count->begin();
|
foreach (const object_count_map::value_type& pair, *live_memory_count)
|
||||||
i != live_memory_count->end();
|
memory_size += pair.second.second;
|
||||||
i++)
|
|
||||||
memory_size += (*i).second.second;
|
|
||||||
|
|
||||||
return memory_size;
|
return memory_size;
|
||||||
}
|
}
|
||||||
|
|
@ -249,12 +247,10 @@ namespace ledger {
|
||||||
|
|
||||||
inline void report_count_map(std::ostream& out, object_count_map& the_map)
|
inline void report_count_map(std::ostream& out, object_count_map& the_map)
|
||||||
{
|
{
|
||||||
for (object_count_map::iterator i = the_map.begin();
|
foreach (object_count_map::value_type& pair, the_map)
|
||||||
i != the_map.end();
|
out << " " << std::right << std::setw(12) << pair.second.first
|
||||||
i++)
|
<< " " << std::right << std::setw(7) << pair.second.second
|
||||||
out << " " << std::right << std::setw(12) << (*i).second.first
|
<< " " << std::left << pair.first
|
||||||
<< " " << std::right << std::setw(7) << (*i).second.second
|
|
||||||
<< " " << std::left << (*i).first
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,10 +258,8 @@ std::size_t current_objects_size()
|
||||||
{
|
{
|
||||||
std::size_t objects_size = 0;
|
std::size_t objects_size = 0;
|
||||||
|
|
||||||
for (object_count_map::const_iterator i = live_object_count->begin();
|
foreach (const object_count_map::value_type& pair, *live_object_count)
|
||||||
i != live_object_count->end();
|
objects_size += pair.second.second;
|
||||||
i++)
|
|
||||||
objects_size += (*i).second.second;
|
|
||||||
|
|
||||||
return objects_size;
|
return objects_size;
|
||||||
}
|
}
|
||||||
|
|
@ -343,12 +337,10 @@ void report_memory(std::ostream& out, bool report_all)
|
||||||
if (live_memory->size() > 0) {
|
if (live_memory->size() > 0) {
|
||||||
out << "Live memory:" << std::endl;
|
out << "Live memory:" << std::endl;
|
||||||
|
|
||||||
for (live_memory_map::const_iterator i = live_memory->begin();
|
foreach (const live_memory_map::value_type& pair, *live_memory)
|
||||||
i != live_memory->end();
|
out << " " << std::right << std::setw(12) << pair.first
|
||||||
i++)
|
<< " " << std::right << std::setw(7) << pair.second.second
|
||||||
out << " " << std::right << std::setw(12) << (*i).first
|
<< " " << std::left << pair.second.first
|
||||||
<< " " << std::right << std::setw(7) << (*i).second.second
|
|
||||||
<< " " << std::left << (*i).second.first
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,12 +357,10 @@ void report_memory(std::ostream& out, bool report_all)
|
||||||
if (live_objects->size() > 0) {
|
if (live_objects->size() > 0) {
|
||||||
out << "Live objects:" << std::endl;
|
out << "Live objects:" << std::endl;
|
||||||
|
|
||||||
for (live_objects_map::const_iterator i = live_objects->begin();
|
foreach (const live_objects_map::value_type& pair, *live_objects)
|
||||||
i != live_objects->end();
|
out << " " << std::right << std::setw(12) << pair.first
|
||||||
i++)
|
<< " " << std::right << std::setw(7) << pair.second.second
|
||||||
out << " " << std::right << std::setw(12) << (*i).first
|
<< " " << std::left << pair.second.first
|
||||||
<< " " << std::right << std::setw(7) << (*i).second.second
|
|
||||||
<< " " << std::left << (*i).second.first
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
6
value.cc
6
value.cc
|
|
@ -467,10 +467,8 @@ value_t& value_t::operator-=(const value_t& val)
|
||||||
sequence_t& seq(as_sequence_lval());
|
sequence_t& seq(as_sequence_lval());
|
||||||
|
|
||||||
if (val.is_sequence()) {
|
if (val.is_sequence()) {
|
||||||
for (sequence_t::const_iterator i = val.as_sequence().begin();
|
foreach (const value_t& v, val.as_sequence()) {
|
||||||
i != val.as_sequence().end();
|
sequence_t::iterator j = std::find(seq.begin(), seq.end(), v);
|
||||||
i++) {
|
|
||||||
sequence_t::iterator j = std::find(seq.begin(), seq.end(), *i);
|
|
||||||
if (j != seq.end())
|
if (j != seq.end())
|
||||||
seq.erase(j);
|
seq.erase(j);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
142
walk.cc
142
walk.cc
|
|
@ -120,23 +120,19 @@ void truncate_entries::flush()
|
||||||
entry_t * last_entry = (*xacts.begin())->entry;
|
entry_t * last_entry = (*xacts.begin())->entry;
|
||||||
|
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (xacts_list::iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts)
|
||||||
x != xacts.end();
|
if (last_entry != xact->entry) {
|
||||||
x++)
|
|
||||||
if (last_entry != (*x)->entry) {
|
|
||||||
l++;
|
l++;
|
||||||
last_entry = (*x)->entry;
|
last_entry = xact->entry;
|
||||||
}
|
}
|
||||||
l++;
|
l++;
|
||||||
|
|
||||||
last_entry = (*xacts.begin())->entry;
|
last_entry = (*xacts.begin())->entry;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (xacts_list::iterator x = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
x != xacts.end();
|
if (last_entry != xact->entry) {
|
||||||
x++) {
|
last_entry = xact->entry;
|
||||||
if (last_entry != (*x)->entry) {
|
|
||||||
last_entry = (*x)->entry;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +152,7 @@ void truncate_entries::flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (print)
|
if (print)
|
||||||
item_handler<xact_t>::operator()(**x);
|
item_handler<xact_t>::operator()(*xact);
|
||||||
}
|
}
|
||||||
xacts.clear();
|
xacts.clear();
|
||||||
|
|
||||||
|
|
@ -183,11 +179,9 @@ void sort_xacts::post_accumulated_xacts()
|
||||||
std::stable_sort(xacts.begin(), xacts.end(),
|
std::stable_sort(xacts.begin(), xacts.end(),
|
||||||
compare_items<xact_t>(sort_order));
|
compare_items<xact_t>(sort_order));
|
||||||
|
|
||||||
for (xacts_deque::iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
i != xacts.end();
|
xact_xdata(*xact).dflags &= ~XACT_SORT_CALC;
|
||||||
i++) {
|
item_handler<xact_t>::operator()(*xact);
|
||||||
xact_xdata(**i).dflags &= ~XACT_SORT_CALC;
|
|
||||||
item_handler<xact_t>::operator()(**i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xacts.clear();
|
xacts.clear();
|
||||||
|
|
@ -349,31 +343,27 @@ void collapse_xacts::operator()(xact_t& xact)
|
||||||
void related_xacts::flush()
|
void related_xacts::flush()
|
||||||
{
|
{
|
||||||
if (xacts.size() > 0) {
|
if (xacts.size() > 0) {
|
||||||
for (xacts_list::iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts) {
|
||||||
i != xacts.end();
|
if (xact->entry) {
|
||||||
i++) {
|
foreach (xact_t * r_xact, xact->entry->xacts) {
|
||||||
if ((*i)->entry) {
|
xact_xdata_t& xdata = xact_xdata(*r_xact);
|
||||||
for (xacts_list::iterator j = (*i)->entry->xacts.begin();
|
|
||||||
j != (*i)->entry->xacts.end();
|
|
||||||
j++) {
|
|
||||||
xact_xdata_t& xdata = xact_xdata(**j);
|
|
||||||
if (! (xdata.dflags & XACT_HANDLED) &&
|
if (! (xdata.dflags & XACT_HANDLED) &&
|
||||||
(! (xdata.dflags & XACT_RECEIVED) ?
|
(! (xdata.dflags & XACT_RECEIVED) ?
|
||||||
! (*j)->has_flags(XACT_AUTO | XACT_VIRTUAL) :
|
! r_xact->has_flags(XACT_AUTO | XACT_VIRTUAL) :
|
||||||
also_matching)) {
|
also_matching)) {
|
||||||
xdata.dflags |= XACT_HANDLED;
|
xdata.dflags |= XACT_HANDLED;
|
||||||
item_handler<xact_t>::operator()(**j);
|
item_handler<xact_t>::operator()(*r_xact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This code should only be reachable from the "output"
|
// This code should only be reachable from the "output"
|
||||||
// command, since that is the only command which attempts to
|
// command, since that is the only command which attempts to
|
||||||
// output auto or period entries.
|
// output auto or period entries.
|
||||||
xact_xdata_t& xdata = xact_xdata(**i);
|
xact_xdata_t& xdata = xact_xdata(*xact);
|
||||||
if (! (xdata.dflags & XACT_HANDLED) &&
|
if (! (xdata.dflags & XACT_HANDLED) &&
|
||||||
! (*i)->has_flags(XACT_AUTO)) {
|
! xact->has_flags(XACT_AUTO)) {
|
||||||
xdata.dflags |= XACT_HANDLED;
|
xdata.dflags |= XACT_HANDLED;
|
||||||
item_handler<xact_t>::operator()(**i);
|
item_handler<xact_t>::operator()(*xact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -463,11 +453,9 @@ void subtotal_xacts::report_subtotal(const char * spec_fmt)
|
||||||
entry.payee = out_date.str();
|
entry.payee = out_date.str();
|
||||||
entry._date = start;
|
entry._date = start;
|
||||||
|
|
||||||
for (values_map::iterator i = values.begin();
|
foreach (values_map::value_type& pair, values)
|
||||||
i != values.end();
|
handle_value(pair.second.value, pair.second.account, &entry, 0,
|
||||||
i++)
|
xact_temps, *handler, finish, &pair.second.components);
|
||||||
handle_value((*i).second.value, (*i).second.account, &entry, 0,
|
|
||||||
xact_temps, *handler, finish, &(*i).second.components);
|
|
||||||
|
|
||||||
values.clear();
|
values.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -571,18 +559,14 @@ by_payee_xacts::~by_payee_xacts()
|
||||||
{
|
{
|
||||||
TRACE_DTOR(by_payee_xacts);
|
TRACE_DTOR(by_payee_xacts);
|
||||||
|
|
||||||
for (payee_subtotals_map::iterator i = payee_subtotals.begin();
|
foreach (payee_subtotals_map::value_type& pair, payee_subtotals)
|
||||||
i != payee_subtotals.end();
|
checked_delete(pair.second);
|
||||||
i++)
|
|
||||||
checked_delete((*i).second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void by_payee_xacts::flush()
|
void by_payee_xacts::flush()
|
||||||
{
|
{
|
||||||
for (payee_subtotals_map::iterator i = payee_subtotals.begin();
|
foreach (payee_subtotals_map::value_type& pair, payee_subtotals)
|
||||||
i != payee_subtotals.end();
|
pair.second->report_subtotal(pair.first.c_str());
|
||||||
i++)
|
|
||||||
(*i).second->report_subtotal((*i).first.c_str());
|
|
||||||
|
|
||||||
item_handler<xact_t>::flush();
|
item_handler<xact_t>::flush();
|
||||||
|
|
||||||
|
|
@ -663,10 +647,8 @@ void dow_xacts::flush()
|
||||||
#if 0
|
#if 0
|
||||||
start = finish = 0;
|
start = finish = 0;
|
||||||
#endif
|
#endif
|
||||||
for (xacts_list::iterator d = days_of_the_week[i].begin();
|
foreach (xact_t * xact, days_of_the_week[i])
|
||||||
d != days_of_the_week[i].end();
|
subtotal_xacts::operator()(*xact);
|
||||||
d++)
|
|
||||||
subtotal_xacts::operator()(**d);
|
|
||||||
subtotal_xacts::report_subtotal("%As");
|
subtotal_xacts::report_subtotal("%As");
|
||||||
days_of_the_week[i].clear();
|
days_of_the_week[i].clear();
|
||||||
}
|
}
|
||||||
|
|
@ -677,13 +659,9 @@ void dow_xacts::flush()
|
||||||
void generate_xacts::add_period_entries
|
void generate_xacts::add_period_entries
|
||||||
(period_entries_list& period_entries)
|
(period_entries_list& period_entries)
|
||||||
{
|
{
|
||||||
for (period_entries_list::iterator i = period_entries.begin();
|
foreach (period_entry_t * entry, period_entries)
|
||||||
i != period_entries.end();
|
foreach (xact_t * xact, entry->xacts)
|
||||||
i++)
|
add_xact(entry->period, *xact);
|
||||||
for (xacts_list::iterator j = (*i)->xacts.begin();
|
|
||||||
j != (*i)->xacts.end();
|
|
||||||
j++)
|
|
||||||
add_xact((*i)->period, **j);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_xacts::add_xact(const interval_t& period,
|
void generate_xacts::add_xact(const interval_t& period,
|
||||||
|
|
@ -700,18 +678,16 @@ void budget_xacts::report_budget_items(const datetime_t& moment)
|
||||||
bool reported;
|
bool reported;
|
||||||
do {
|
do {
|
||||||
reported = false;
|
reported = false;
|
||||||
for (pending_xacts_list::iterator i = pending_xacts.begin();
|
foreach (pending_xacts_list::value_type& pair, pending_xacts) {
|
||||||
i != pending_xacts.end();
|
datetime_t& begin = pair.first.begin;
|
||||||
i++) {
|
|
||||||
datetime_t& begin = (*i).first.begin;
|
|
||||||
if (! is_valid(begin)) {
|
if (! is_valid(begin)) {
|
||||||
(*i).first.start(moment);
|
pair.first.start(moment);
|
||||||
begin = (*i).first.begin;
|
begin = pair.first.begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin < moment &&
|
if (begin < moment &&
|
||||||
(! is_valid((*i).first.end) || begin < (*i).first.end)) {
|
(! is_valid(pair.first.end) || begin < pair.first.end)) {
|
||||||
xact_t& xact = *(*i).second;
|
xact_t& xact = *pair.second;
|
||||||
|
|
||||||
DEBUG("ledger.walk.budget", "Reporting budget for "
|
DEBUG("ledger.walk.budget", "Reporting budget for "
|
||||||
<< xact_account(xact)->fullname());
|
<< xact_account(xact)->fullname());
|
||||||
|
|
@ -733,7 +709,7 @@ void budget_xacts::report_budget_items(const datetime_t& moment)
|
||||||
temp.amount.negate();
|
temp.amount.negate();
|
||||||
entry.add_xact(&temp);
|
entry.add_xact(&temp);
|
||||||
|
|
||||||
begin = (*i).first.increment(begin);
|
begin = pair.first.increment(begin);
|
||||||
|
|
||||||
item_handler<xact_t>::operator()(temp);
|
item_handler<xact_t>::operator()(temp);
|
||||||
|
|
||||||
|
|
@ -747,13 +723,11 @@ void budget_xacts::operator()(xact_t& xact)
|
||||||
{
|
{
|
||||||
bool xact_in_budget = false;
|
bool xact_in_budget = false;
|
||||||
|
|
||||||
for (pending_xacts_list::iterator i = pending_xacts.begin();
|
foreach (pending_xacts_list::value_type& pair, pending_xacts)
|
||||||
i != pending_xacts.end();
|
|
||||||
i++)
|
|
||||||
for (account_t * acct = xact_account(xact);
|
for (account_t * acct = xact_account(xact);
|
||||||
acct;
|
acct;
|
||||||
acct = acct->parent) {
|
acct = acct->parent) {
|
||||||
if (acct == xact_account(*(*i).second)) {
|
if (acct == xact_account(*pair.second)) {
|
||||||
xact_in_budget = true;
|
xact_in_budget = true;
|
||||||
// Report the xact as if it had occurred in the parent
|
// Report the xact as if it had occurred in the parent
|
||||||
// account.
|
// account.
|
||||||
|
|
@ -773,8 +747,7 @@ void budget_xacts::operator()(xact_t& xact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void forecast_xacts::add_xact(const interval_t& period,
|
void forecast_xacts::add_xact(const interval_t& period, xact_t& xact)
|
||||||
xact_t& xact)
|
|
||||||
{
|
{
|
||||||
generate_xacts::add_xact(period, xact);
|
generate_xacts::add_xact(period, xact);
|
||||||
|
|
||||||
|
|
@ -839,10 +812,8 @@ void forecast_xacts::flush()
|
||||||
passed.clear();
|
passed.clear();
|
||||||
} else {
|
} else {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (xacts_list::iterator i = passed.begin();
|
foreach (xact_t * x, passed)
|
||||||
i != passed.end();
|
if (x == &xact) {
|
||||||
i++)
|
|
||||||
if (*i == &xact) {
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -896,14 +867,12 @@ void sum_accounts(account_t& account)
|
||||||
{
|
{
|
||||||
account_xdata_t& xdata(account_xdata(account));
|
account_xdata_t& xdata(account_xdata(account));
|
||||||
|
|
||||||
for (accounts_map::iterator i = account.accounts.begin();
|
foreach (accounts_map::value_type& pair, account.accounts) {
|
||||||
i != account.accounts.end();
|
sum_accounts(*pair.second);
|
||||||
i++) {
|
|
||||||
sum_accounts(*(*i).second);
|
|
||||||
|
|
||||||
xdata.total += account_xdata_(*(*i).second).total;
|
xdata.total += account_xdata_(*pair.second).total;
|
||||||
xdata.total_count += (account_xdata_(*(*i).second).total_count +
|
xdata.total_count += (account_xdata_(*pair.second).total_count +
|
||||||
account_xdata_(*(*i).second).count);
|
account_xdata_(*pair.second).count);
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t result;
|
value_t result;
|
||||||
|
|
@ -938,10 +907,8 @@ account_t * accounts_iterator::operator()()
|
||||||
void sorted_accounts_iterator::sort_accounts(account_t& account,
|
void sorted_accounts_iterator::sort_accounts(account_t& account,
|
||||||
accounts_deque_t& deque)
|
accounts_deque_t& deque)
|
||||||
{
|
{
|
||||||
for (accounts_map::iterator i = account.accounts.begin();
|
foreach (accounts_map::value_type& pair, account.accounts)
|
||||||
i != account.accounts.end();
|
deque.push_back(pair.second);
|
||||||
i++)
|
|
||||||
deque.push_back((*i).second);
|
|
||||||
|
|
||||||
std::stable_sort(deque.begin(), deque.end(),
|
std::stable_sort(deque.begin(), deque.end(),
|
||||||
compare_items<account_t>(sort_cmp));
|
compare_items<account_t>(sort_cmp));
|
||||||
|
|
@ -988,15 +955,14 @@ void walk_commodities(commodity_pool_t::commodities_by_ident& commodities,
|
||||||
acct_temps.push_back(account_t(NULL, (*i)->symbol()));
|
acct_temps.push_back(account_t(NULL, (*i)->symbol()));
|
||||||
|
|
||||||
if ((*i)->history())
|
if ((*i)->history())
|
||||||
for (commodity_t::history_map::iterator j = (*i)->history()->prices.begin();
|
foreach (const commodity_t::history_map::value_type& pair,
|
||||||
j != (*i)->history()->prices.end();
|
(*i)->history()->prices) {
|
||||||
j++) {
|
entry_temps.back()._date = pair.first;
|
||||||
entry_temps.back()._date = (*j).first;
|
|
||||||
|
|
||||||
xact_temps.push_back(xact_t(&acct_temps.back()));
|
xact_temps.push_back(xact_t(&acct_temps.back()));
|
||||||
xact_t& temp = xact_temps.back();
|
xact_t& temp = xact_temps.back();
|
||||||
temp.entry = &entry_temps.back();
|
temp.entry = &entry_temps.back();
|
||||||
temp.amount = (*j).second;
|
temp.amount = pair.second;
|
||||||
temp.add_flags(XACT_TEMP);
|
temp.add_flags(XACT_TEMP);
|
||||||
entry_temps.back().add_xact(&temp);
|
entry_temps.back().add_xact(&temp);
|
||||||
|
|
||||||
|
|
|
||||||
21
walk.h
21
walk.h
|
|
@ -101,8 +101,7 @@ struct xact_xdata_t : public noncopyable
|
||||||
datetime_t date;
|
datetime_t date;
|
||||||
account_t * account;
|
account_t * account;
|
||||||
void * ptr;
|
void * ptr;
|
||||||
|
xacts_list * component_xacts;
|
||||||
xacts_list * component_xacts;
|
|
||||||
|
|
||||||
xact_xdata_t()
|
xact_xdata_t()
|
||||||
: index(0), dflags(0),
|
: index(0), dflags(0),
|
||||||
|
|
@ -126,17 +125,13 @@ struct xact_xdata_t : public noncopyable
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy_component_xacts(xacts_list& xacts) {
|
void copy_component_xacts(xacts_list& xacts) {
|
||||||
for (xacts_list::const_iterator i = xacts.begin();
|
foreach (xact_t * xact, xacts)
|
||||||
i != xacts.end();
|
remember_xact(*xact);
|
||||||
i++)
|
|
||||||
remember_xact(**i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void walk_component_xacts(item_handler<xact_t>& handler) const {
|
void walk_component_xacts(item_handler<xact_t>& handler) const {
|
||||||
for (xacts_list::const_iterator i = component_xacts->begin();
|
foreach (xact_t * xact, *component_xacts)
|
||||||
i != component_xacts->end();
|
handler(*xact);
|
||||||
i++)
|
|
||||||
handler(**i);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -493,10 +488,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void clear_entries_xacts(std::list<entry_t>& entries_list) {
|
inline void clear_entries_xacts(std::list<entry_t>& entries_list) {
|
||||||
for (std::list<entry_t>::iterator i = entries_list.begin();
|
foreach (entry_t& entry, entries_list)
|
||||||
i != entries_list.end();
|
entry.xacts.clear();
|
||||||
i++)
|
|
||||||
(*i).xacts.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class collapse_xacts : public item_handler<xact_t>
|
class collapse_xacts : public item_handler<xact_t>
|
||||||
|
|
|
||||||
6
xact.cc
6
xact.cc
|
|
@ -169,11 +169,9 @@ xact_context::xact_context(const xact_t& _xact, const string& desc) throw()
|
||||||
{
|
{
|
||||||
const paths_list& sources(xact.entry->journal->sources);
|
const paths_list& sources(xact.entry->journal->sources);
|
||||||
unsigned int x = 0;
|
unsigned int x = 0;
|
||||||
for (paths_list::const_iterator i = sources.begin();
|
foreach (const path& path, sources)
|
||||||
i != sources.end();
|
|
||||||
i++, x++)
|
|
||||||
if (x == xact.entry->src_idx) {
|
if (x == xact.entry->src_idx) {
|
||||||
file = *i;
|
file = path;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line = xact.beg_line;
|
line = xact.beg_line;
|
||||||
|
|
|
||||||
52
xml.cc
52
xml.cc
|
|
@ -318,10 +318,8 @@ void xml_write_value(std::ostream& out, const value_t& value,
|
||||||
for (int i = 0; i < depth + 2; i++) out << ' ';
|
for (int i = 0; i < depth + 2; i++) out << ' ';
|
||||||
out << "<balance>\n";
|
out << "<balance>\n";
|
||||||
|
|
||||||
for (balance_t::amounts_map::const_iterator i = bal->amounts.begin();
|
foreach (const balance_t::amounts_map::value_type& pair, bal->amounts)
|
||||||
i != bal->amounts.end();
|
xml_write_amount(out, pair.second, depth + 4);
|
||||||
i++)
|
|
||||||
xml_write_amount(out, (*i).second, depth + 4);
|
|
||||||
|
|
||||||
for (int i = 0; i < depth + 2; i++) out << ' ';
|
for (int i = 0; i < depth + 2; i++) out << ' ';
|
||||||
out << "</balance>\n";
|
out << "</balance>\n";
|
||||||
|
|
@ -383,11 +381,9 @@ void format_xml_entries::format_last_entry()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (xacts_list::const_iterator i = last_entry->xacts.begin();
|
foreach (const xact_t * xact, last_entry->xacts) {
|
||||||
i != last_entry->xacts.end();
|
if (xact_has_xdata(*xact) &&
|
||||||
i++) {
|
xact_xdata_(*xact).dflags & XACT_TO_DISPLAY) {
|
||||||
if (xact_has_xdata(**i) &&
|
|
||||||
xact_xdata_(**i).dflags & XACT_TO_DISPLAY) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
output_stream << " <en:xacts>\n";
|
output_stream << " <en:xacts>\n";
|
||||||
first = false;
|
first = false;
|
||||||
|
|
@ -397,29 +393,29 @@ void format_xml_entries::format_last_entry()
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// jww (2008-05-08): Need to format these
|
// jww (2008-05-08): Need to format these
|
||||||
if ((*i)->_date)
|
if (xact->_date)
|
||||||
output_stream << " <tr:date>"
|
output_stream << " <tr:date>"
|
||||||
<< (*i)->_date.to_string("%Y/%m/%d")
|
<< xact->_date.to_string("%Y/%m/%d")
|
||||||
<< "</tr:date>\n";
|
<< "</tr:date>\n";
|
||||||
|
|
||||||
if (is_valid((*i)->_date_eff))
|
if (is_valid(xact->_date_eff))
|
||||||
output_stream << " <tr:date_eff>"
|
output_stream << " <tr:date_eff>"
|
||||||
<< (*i)->_date_eff.to_string("%Y/%m/%d")
|
<< xact->_date_eff.to_string("%Y/%m/%d")
|
||||||
<< "</tr:date_eff>\n";
|
<< "</tr:date_eff>\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((*i)->state == xact_t::CLEARED)
|
if (xact->state == xact_t::CLEARED)
|
||||||
output_stream << " <tr:cleared/>\n";
|
output_stream << " <tr:cleared/>\n";
|
||||||
else if ((*i)->state == xact_t::PENDING)
|
else if (xact->state == xact_t::PENDING)
|
||||||
output_stream << " <tr:pending/>\n";
|
output_stream << " <tr:pending/>\n";
|
||||||
|
|
||||||
if ((*i)->has_flags(XACT_VIRTUAL))
|
if (xact->has_flags(XACT_VIRTUAL))
|
||||||
output_stream << " <tr:virtual/>\n";
|
output_stream << " <tr:virtual/>\n";
|
||||||
if ((*i)->has_flags(XACT_AUTO))
|
if (xact->has_flags(XACT_AUTO))
|
||||||
output_stream << " <tr:generated/>\n";
|
output_stream << " <tr:generated/>\n";
|
||||||
|
|
||||||
if ((*i)->account) {
|
if (xact->account) {
|
||||||
string name = (*i)->account->fullname();
|
string name = xact->account->fullname();
|
||||||
if (name == "<Total>")
|
if (name == "<Total>")
|
||||||
name = "[TOTAL]";
|
name = "[TOTAL]";
|
||||||
else if (name == "<Unknown>")
|
else if (name == "<Unknown>")
|
||||||
|
|
@ -431,34 +427,34 @@ void format_xml_entries::format_last_entry()
|
||||||
}
|
}
|
||||||
|
|
||||||
output_stream << " <tr:amount>\n";
|
output_stream << " <tr:amount>\n";
|
||||||
if (xact_xdata_(**i).dflags & XACT_COMPOUND)
|
if (xact_xdata_(*xact).dflags & XACT_COMPOUND)
|
||||||
xml_write_value(output_stream,
|
xml_write_value(output_stream,
|
||||||
xact_xdata_(**i).value, 10);
|
xact_xdata_(*xact).value, 10);
|
||||||
else
|
else
|
||||||
xml_write_value(output_stream, value_t((*i)->amount), 10);
|
xml_write_value(output_stream, value_t(xact->amount), 10);
|
||||||
output_stream << " </tr:amount>\n";
|
output_stream << " </tr:amount>\n";
|
||||||
|
|
||||||
if ((*i)->cost) {
|
if (xact->cost) {
|
||||||
output_stream << " <tr:cost>\n";
|
output_stream << " <tr:cost>\n";
|
||||||
xml_write_value(output_stream, value_t(*(*i)->cost), 10);
|
xml_write_value(output_stream, value_t(*xact->cost), 10);
|
||||||
output_stream << " </tr:cost>\n";
|
output_stream << " </tr:cost>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*i)->note) {
|
if (xact->note) {
|
||||||
output_stream << " <tr:note>";
|
output_stream << " <tr:note>";
|
||||||
output_xml_string(output_stream, *(*i)->note);
|
output_xml_string(output_stream, *xact->note);
|
||||||
output_stream << "</tr:note>\n";
|
output_stream << "</tr:note>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_totals) {
|
if (show_totals) {
|
||||||
output_stream << " <total>\n";
|
output_stream << " <total>\n";
|
||||||
xml_write_value(output_stream, xact_xdata_(**i).total, 10);
|
xml_write_value(output_stream, xact_xdata_(*xact).total, 10);
|
||||||
output_stream << " </total>\n";
|
output_stream << " </total>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
output_stream << " </xact>\n";
|
output_stream << " </xact>\n";
|
||||||
|
|
||||||
xact_xdata_(**i).dflags |= XACT_DISPLAYED;
|
xact_xdata_(*xact).dflags |= XACT_DISPLAYED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue