summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-07 08:16:02 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-07 08:32:13 -0400
commita4d4f9979486eb82c05bd032e1452c2fd400249f (patch)
tree7451a16c967f4dbe32122bd20f96dc5e6b4ad231 /src
parent8bd362b5d17782cf8fa5317017a1c5d73d76f1b7 (diff)
downloadfork-ledger-a4d4f9979486eb82c05bd032e1452c2fd400249f.tar.gz
fork-ledger-a4d4f9979486eb82c05bd032e1452c2fd400249f.tar.bz2
fork-ledger-a4d4f9979486eb82c05bd032e1452c2fd400249f.zip
amount_t::print and value_t::print now use flags
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc2
-rw-r--r--src/amount.h8
-rw-r--r--src/balance.cc17
-rw-r--r--src/balance.h9
-rw-r--r--src/print.cc7
-rw-r--r--src/report.cc13
-rw-r--r--src/value.cc30
-rw-r--r--src/value.h10
8 files changed, 52 insertions, 44 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 7eb94442..f68917f3 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -1216,7 +1216,7 @@ void amount_t::parse_conversion(const string& larger_str,
smaller.commodity().set_larger(larger);
}
-void amount_t::print(std::ostream& _out) const
+void amount_t::print(std::ostream& _out, const uint_least8_t) const
{
VERIFY(valid());
diff --git a/src/amount.h b/src/amount.h
index 49f33417..faea8b8e 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -677,7 +677,13 @@ public:
true, the full internal precision of the amount is displayed, regardless
of its commodity's display precision.
*/
- void print(std::ostream& out) const;
+#define AMOUNT_PRINT_NO_FLAGS 0x00
+#define AMOUNT_PRINT_RIGHT_JUSTIFY 0x01
+#define AMOUNT_PRINT_COLORIZE 0x02
+#define AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS 0x04
+
+ void print(std::ostream& out,
+ const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
/*@}*/
diff --git a/src/balance.cc b/src/balance.cc
index 9b39a49a..bfcd4a35 100644
--- a/src/balance.cc
+++ b/src/balance.cc
@@ -252,11 +252,10 @@ balance_t::strip_annotations(const keep_details_t& what_to_keep) const
return temp;
}
-void balance_t::print(std::ostream& out,
- const int first_width,
- const int latter_width,
- const bool right_justify,
- const bool colorize) const
+void balance_t::print(std::ostream& out,
+ const int first_width,
+ const int latter_width,
+ const uint_least8_t flags) const
{
bool first = true;
int lwidth = latter_width;
@@ -285,14 +284,14 @@ void balance_t::print(std::ostream& out,
}
std::ostringstream buf;
- buf << *amount;
- justify(out, buf.str(), width, right_justify,
- colorize && amount->sign() < 0);
+ amount->print(buf, flags);
+ justify(out, buf.str(), width, flags & AMOUNT_PRINT_RIGHT_JUSTIFY,
+ flags & AMOUNT_PRINT_COLORIZE && amount->sign() < 0);
}
if (first) {
out.width(first_width);
- if (right_justify)
+ if (flags & AMOUNT_PRINT_RIGHT_JUSTIFY)
out << std::right;
else
out << std::left;
diff --git a/src/balance.h b/src/balance.h
index 5c00c55a..496b53b7 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -530,11 +530,10 @@ public:
* relative amounts of those commodities. There is no option to
* change this behavior.
*/
- void print(std::ostream& out,
- const int first_width = -1,
- const int latter_width = -1,
- const bool right_justify = false,
- const bool colorize = false) const;
+ void print(std::ostream& out,
+ const int first_width = -1,
+ const int latter_width = -1,
+ const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
/**
* Debugging methods. There are two methods defined to help with
diff --git a/src/print.cc b/src/print.cc
index 703e885c..5a72b03e 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -172,13 +172,14 @@ namespace {
if (post->amount_expr) {
amt = post->amount_expr->text();
} else {
- std::size_t amount_width =
+ int amount_width =
(report.HANDLER(amount_width_).specified ?
- report.HANDLER(amount_width_).value.to_long() : 12);
+ report.HANDLER(amount_width_).value.to_int() : 12);
std::ostringstream amt_str;
report.scrub(post->amount)
- .print(amt_str, static_cast<int>(amount_width), -1, true);
+ .print(amt_str, amount_width, -1, AMOUNT_PRINT_RIGHT_JUSTIFY |
+ AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
amt = amt_str.str();
}
diff --git a/src/report.cc b/src/report.cc
index 7b9dc956..2ce0ae73 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -597,12 +597,17 @@ value_t report_t::fn_truncated(call_scope_t& scope)
value_t report_t::fn_justify(call_scope_t& scope)
{
interactive_t args(scope, "vl&lbb");
+
+ uint_least8_t flags(AMOUNT_PRINT_NO_FLAGS);
+
+ if (args.has(3) && args.get<bool>(3))
+ flags |= AMOUNT_PRINT_RIGHT_JUSTIFY;
+ if (args.has(4) && args.get<bool>(4))
+ flags |= AMOUNT_PRINT_COLORIZE;
+
std::ostringstream out;
args.value_at(0)
- .print(out, args.get<int>(1),
- args.has(2) ? args.get<int>(2) : -1,
- args.has(3) ? args.get<bool>(3) : false,
- args.has(4) ? args.get<bool>(4) : false);
+ .print(out, args.get<int>(1), args.has(2) ? args.get<int>(2) : -1, flags);
return string_value(out.str());
}
diff --git a/src/value.cc b/src/value.cc
index e9313f0c..7af2fd1e 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -1681,18 +1681,17 @@ value_t value_t::strip_annotations(const keep_details_t& what_to_keep) const
return NULL_VALUE;
}
-void value_t::print(std::ostream& out,
- const int first_width,
- const int latter_width,
- const bool right_justify,
- const bool colorize) const
+void value_t::print(std::ostream& out,
+ const int first_width,
+ const int latter_width,
+ const uint_least8_t flags) const
{
if (first_width > 0 &&
(! is_amount() || as_amount().is_zero()) &&
! is_balance() && ! is_string()) {
out.width(first_width);
- if (right_justify)
+ if (flags & AMOUNT_PRINT_RIGHT_JUSTIFY)
out << std::right;
else
out << std::left;
@@ -1716,8 +1715,9 @@ void value_t::print(std::ostream& out,
break;
case INTEGER:
- if (colorize && as_long() < 0)
- justify(out, to_string(), first_width, right_justify, true);
+ if (flags & AMOUNT_PRINT_COLORIZE && as_long() < 0)
+ justify(out, to_string(), first_width,
+ flags & AMOUNT_PRINT_RIGHT_JUSTIFY, true);
else
out << as_long();
break;
@@ -1727,21 +1727,20 @@ void value_t::print(std::ostream& out,
out << 0;
} else {
std::ostringstream buf;
- buf << as_amount();
- justify(out, buf.str(), first_width, right_justify,
- colorize && as_amount().sign() < 0);
+ as_amount().print(buf, flags & AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS);
+ justify(out, buf.str(), first_width, flags & AMOUNT_PRINT_RIGHT_JUSTIFY,
+ flags & AMOUNT_PRINT_COLORIZE && as_amount().sign() < 0);
}
break;
}
case BALANCE:
- as_balance().print(out, first_width, latter_width, right_justify,
- colorize);
+ as_balance().print(out, first_width, latter_width, flags);
break;
case STRING:
if (first_width > 0)
- justify(out, as_string(), first_width, right_justify);
+ justify(out, as_string(), first_width, flags & AMOUNT_PRINT_RIGHT_JUSTIFY);
else
out << as_string();
break;
@@ -1759,8 +1758,7 @@ void value_t::print(std::ostream& out,
else
out << ", ";
- value.print(out, first_width, latter_width, right_justify,
- colorize);
+ value.print(out, first_width, latter_width, flags);
}
out << ')';
break;
diff --git a/src/value.h b/src/value.h
index 2e3998f3..cffd6dee 100644
--- a/src/value.h
+++ b/src/value.h
@@ -942,11 +942,11 @@ public:
/**
* Printing methods.
*/
- void print(std::ostream& out,
- const int first_width = -1,
- const int latter_width = -1,
- const bool right_justify = false,
- const bool colorize = false) const;
+ void print(std::ostream& out,
+ const int first_width = -1,
+ const int latter_width = -1,
+ const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
+
void dump(std::ostream& out, const bool relaxed = true) const;
/**