Removed used of src_idx.

This commit is contained in:
John Wiegley 2009-02-03 18:46:19 -04:00
parent 8948e161cd
commit 2ce7ae376c
7 changed files with 42 additions and 61 deletions

View file

@ -36,14 +36,8 @@ 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; out << "\"" << entry.pathname << "\" "
foreach (const path& path, entry.journal->sources) << (static_cast<std::size_t>(entry.beg_line) + 1) << " ";
if (! idx--) {
out << "\"" << path << "\" ";
break;
}
out << (static_cast<std::size_t>(entry.beg_line) + 1) << " ";
tm when = gregorian::to_tm(*entry.date()); tm when = gregorian::to_tm(*entry.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local? std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?

View file

@ -37,7 +37,8 @@
namespace ledger { namespace ledger {
entry_base_t::entry_base_t(const entry_base_t& e) : item_t() entry_base_t::entry_base_t(const entry_base_t& e)
: item_t(), journal(NULL)
{ {
TRACE_CTOR(entry_base_t, "copy"); TRACE_CTOR(entry_base_t, "copy");
#if 0 #if 0
@ -79,14 +80,12 @@ item_t::state_t entry_base_t::state() const
void entry_base_t::add_xact(xact_t * xact) void entry_base_t::add_xact(xact_t * xact)
{ {
xacts.push_back(xact); xacts.push_back(xact);
xact->journal = journal;
} }
bool entry_base_t::remove_xact(xact_t * xact) bool entry_base_t::remove_xact(xact_t * xact)
{ {
xacts.remove(xact); xacts.remove(xact);
xact->entry = NULL; xact->entry = NULL;
xact->journal = NULL;
return true; return true;
} }

View file

@ -61,9 +61,11 @@ class journal_t;
class entry_base_t : public item_t class entry_base_t : public item_t
{ {
public: public:
journal_t * journal;
xacts_list xacts; xacts_list xacts;
entry_base_t() { entry_base_t() : item_t(), journal(NULL) {
TRACE_CTOR(entry_base_t, ""); TRACE_CTOR(entry_base_t, "");
} }
entry_base_t(const entry_base_t& e); entry_base_t(const entry_base_t& e);

View file

@ -310,44 +310,38 @@ bool item_t::valid() const
string item_context(const item_t& item) string item_context(const item_t& item)
{ {
unsigned short x = 0; std::size_t len = item.end_pos - item.beg_pos;
foreach (const path& path, item.journal->sources) { assert(len > 0);
if (x++ == item.src_idx) { assert(len < 2048);
std::size_t len = item.end_pos - item.beg_pos;
assert(len > 0); ifstream in(item.pathname);
assert(len < 2048); in.seekg(item.beg_pos, std::ios::beg);
ifstream in(path);
in.seekg(item.beg_pos, std::ios::beg);
scoped_array<char> buf(new char[len + 1]); scoped_array<char> buf(new char[len + 1]);
in.read(buf.get(), len); in.read(buf.get(), len);
std::ostringstream out; std::ostringstream out;
out << "While balancing item from \"" << path.string() out << "While balancing item from \"" << item.pathname.string()
<< "\""; << "\"";
if (item.beg_line != (item.end_line - 1)) if (item.beg_line != (item.end_line - 1))
out << ", lines " << item.beg_line << "-" out << ", lines " << item.beg_line << "-"
<< (item.end_line - 1) << ":\n"; << (item.end_line - 1) << ":\n";
else else
out << ", line " << item.beg_line << ":\n"; out << ", line " << item.beg_line << ":\n";
bool first = true; bool first = true;
for (char * p = std::strtok(buf.get(), "\n"); for (char * p = std::strtok(buf.get(), "\n");
p; p;
p = std::strtok(NULL, "\n")) { p = std::strtok(NULL, "\n")) {
if (first) if (first)
first = false; first = false;
else else
out << '\n'; out << '\n';
out << "> " << p; out << "> " << p;
}
return out.str();
}
} }
assert(false); return out.str();
return empty_string;
} }
} // namespace ledger } // namespace ledger

View file

@ -51,8 +51,6 @@
namespace ledger { namespace ledger {
class journal_t;
/** /**
* @brief Brief * @brief Brief
* *
@ -62,9 +60,9 @@ class item_t : public supports_flags<>, public scope_t
{ {
public: public:
#define ITEM_NORMAL 0x00 // no flags at all, a basic transaction #define ITEM_NORMAL 0x00 // no flags at all, a basic transaction
#define ITEM_IN_CACHE 0x01 // transaction allocated by the binary cache #define ITEM_IN_CACHE 0x01 // transaction allocated by the binary cache
#define ITEM_GENERATED 0x02 // transaction was not found in a journal #define ITEM_GENERATED 0x02 // transaction was not found in a journal
#define ITEM_TEMP 0x04 // transaction is a temporary object #define ITEM_TEMP 0x04 // transaction is a temporary object
enum state_t { UNCLEARED = 0, CLEARED, PENDING }; enum state_t { UNCLEARED = 0, CLEARED, PENDING };
@ -77,9 +75,7 @@ public:
typedef std::map<string, optional<string> > string_map; typedef std::map<string, optional<string> > string_map;
optional<string_map> metadata; optional<string_map> metadata;
journal_t * journal; path pathname;
unsigned short src_idx;
istream_pos_type beg_pos; istream_pos_type beg_pos;
std::size_t beg_line; std::size_t beg_line;
istream_pos_type end_pos; istream_pos_type end_pos;
@ -88,8 +84,7 @@ public:
static bool use_effective_date; static bool use_effective_date;
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none) item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
: supports_flags<>(_flags), : supports_flags<>(_flags), _state(UNCLEARED), note(_note),
_state(UNCLEARED), note(_note), journal(NULL), src_idx(0),
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(item_t, "flags_t, const string&"); TRACE_CTOR(item_t, "flags_t, const string&");
@ -113,8 +108,7 @@ public:
note = item.note; note = item.note;
journal = item.journal; pathname = item.pathname;
src_idx = item.src_idx;
beg_pos = item.beg_pos; beg_pos = item.beg_pos;
beg_line = item.beg_line; beg_line = item.beg_line;
end_pos = item.end_pos; end_pos = item.end_pos;

View file

@ -155,7 +155,6 @@ textual_parser_t::instance_t::instance_t
account_stack.push_front(master); account_stack.push_front(master);
pathname = journal.sources.back(); pathname = journal.sources.back();
src_idx = journal.sources.size() - 1;
linenum = 1; linenum = 1;
beg_pos = in.tellg(); beg_pos = in.tellg();
beg_line = linenum; beg_line = linenum;
@ -472,7 +471,7 @@ void textual_parser_t::instance_t::automated_entry_directive(char * line)
if (parse_xacts(in, account_stack.front(), *ae, "automated", if (parse_xacts(in, account_stack.front(), *ae, "automated",
end_pos)) { end_pos)) {
journal.auto_entries.push_back(ae); journal.auto_entries.push_back(ae);
ae->src_idx = src_idx; ae->pathname = pathname;
ae->beg_pos = beg_pos; ae->beg_pos = beg_pos;
ae->beg_line = beg_line; ae->beg_line = beg_line;
ae->end_pos = end_pos; ae->end_pos = end_pos;
@ -491,7 +490,7 @@ void textual_parser_t::instance_t::period_entry_directive(char * line)
if (pe->finalize()) { if (pe->finalize()) {
extend_entry_base(&journal, *pe, true); extend_entry_base(&journal, *pe, true);
journal.period_entries.push_back(pe); journal.period_entries.push_back(pe);
pe->src_idx = src_idx; pe->pathname = pathname;
pe->beg_pos = beg_pos; pe->beg_pos = beg_pos;
pe->beg_line = beg_line; pe->beg_line = beg_line;
pe->end_pos = end_pos; pe->end_pos = end_pos;
@ -514,7 +513,7 @@ void textual_parser_t::instance_t::entry_directive(char * line)
// would cause us to leak without this guard. // would cause us to leak without this guard.
std::auto_ptr<entry_t> entry_ptr(entry); std::auto_ptr<entry_t> entry_ptr(entry);
entry->src_idx = src_idx; entry->pathname = pathname;
entry->beg_pos = beg_pos; entry->beg_pos = beg_pos;
entry->beg_line = beg_line; entry->beg_line = beg_line;
entry->end_pos = pos; entry->end_pos = pos;

View file

@ -94,7 +94,6 @@ protected:
path pathname; path pathname;
std::size_t linenum; std::size_t linenum;
std::size_t src_idx;
istream_pos_type beg_pos; istream_pos_type beg_pos;
std::size_t beg_line; std::size_t beg_line;
istream_pos_type end_pos; istream_pos_type end_pos;