summaryrefslogtreecommitdiff
path: root/src/cache.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-08-17 03:40:21 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-08-17 03:40:21 -0400
commit752eb99445d078d2549711e714972a617f7d9d31 (patch)
tree5a3b44a43af6aa1814e73205dd19999d82b9a912 /src/cache.cc
parent891d7b87c8bd9c2387a945a22b41f9b8f94f3327 (diff)
downloadfork-ledger-752eb99445d078d2549711e714972a617f7d9d31.tar.gz
fork-ledger-752eb99445d078d2549711e714972a617f7d9d31.tar.bz2
fork-ledger-752eb99445d078d2549711e714972a617f7d9d31.zip
Removed all pending todos from the amount_t code.
Diffstat (limited to 'src/cache.cc')
-rw-r--r--src/cache.cc44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/cache.cc b/src/cache.cc
index d9ee7549..0501cee6 100644
--- a/src/cache.cc
+++ b/src/cache.cc
@@ -83,6 +83,12 @@ void read_xact(const char *& data, xact_t * xact)
expr_t::compute_amount(xact->amount_expr.get(), xact->amount, xact);
}
+void write_amount(std::ostream& out, amount_t& amt)
+{
+ amt.write(out, ++bigints_index);
+ bigints_count++;
+}
+
void write_xact(std::ostream& out, xact_t * xact,
bool ignore_calculated)
{
@@ -92,7 +98,8 @@ void write_xact(std::ostream& out, xact_t * xact,
if (ignore_calculated && xact->has_flags(XACT_CALCULATED)) {
write_number<unsigned char>(out, 0);
- amount_t().write(out);
+ amount_t temp;
+ write_amount(out, temp);
}
else if (xact->amount_expr) {
write_number<unsigned char>(out, 2);
@@ -101,18 +108,18 @@ void write_xact(std::ostream& out, xact_t * xact,
}
else if (! xact->amount_expr->text().empty()) {
write_number<unsigned char>(out, 1);
- xact->amount.write(out);
+ write_amount(out, xact->amount);
write_string(out, xact->amount_expr->text());
}
else {
write_number<unsigned char>(out, 0);
- xact->amount.write(out);
+ write_amount(out, xact->amount);
}
if (xact->cost &&
(! (ignore_calculated && xact->has_flags(XACT_CALCULATED)))) {
write_bool(out, true);
- xact->cost->write(out);
+ write_amount(out, *xact->cost);
// jww (2008-07-30): What if there is no cost expression?
xact->cost_expr->write(out);
} else {
@@ -319,21 +326,21 @@ void write_commodity_base_extra(std::ostream& out,
foreach (commodity_t::history_map::value_type& pair,
commodity->history->prices) {
write_number(out, pair.first);
- pair.second.write(out);
+ write_amount(out, pair.second);
}
write_number(out, commodity->history->last_lookup);
}
if (commodity->smaller) {
write_bool(out, true);
- commodity->smaller->write(out);
+ write_amount(out, *commodity->smaller);
} else {
write_bool(out, false);
}
if (commodity->larger) {
write_bool(out, true);
- commodity->larger->write(out);
+ write_amount(out, *commodity->larger);
} else {
write_bool(out, false);
}
@@ -418,9 +425,26 @@ void write_commodity_annotated(std::ostream& out,
// jww (2008-04-22): No longer needed?
//write_long(out, ann_comm->base->ident);
// jww (2008-04-22): Make a write_annotation_details function; and optional!
- ann_comm->details.price->write(out);
- ann_comm->details.date->write(out);
- ann_comm->details.tag->write(out);
+ if (ann_comm->details.price) {
+ write_bool(out, true);
+ write_amount(out, *ann_comm->details.price);
+ } else {
+ write_bool(out, false);
+ }
+
+ if (ann_comm->details.date) {
+ write_bool(out, true);
+ ann_comm->details.date->write(out);
+ } else {
+ write_bool(out, false);
+ }
+
+ if (ann_comm->details.tag) {
+ write_bool(out, true);
+ ann_comm->details.tag->write(out);
+ } else {
+ write_bool(out, false);
+ }
}
inline