amount_t::print and value_t::print now use flags
This commit is contained in:
parent
8bd362b5d1
commit
a4d4f99794
9 changed files with 56 additions and 48 deletions
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
30
src/value.cc
30
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;
|
||||
|
|
|
|||
10
src/value.h
10
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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@
|
|||
>>>2
|
||||
While parsing file "$sourcepath/src/amount.h", line 66:
|
||||
Error: No quantity specified for amount
|
||||
While parsing file "$sourcepath/src/amount.h", line 720:
|
||||
Error: Invalid date/time: line amount_t amoun
|
||||
While parsing file "$sourcepath/src/amount.h", line 726:
|
||||
Error: Invalid date/time: line string amount_
|
||||
Error: Invalid date/time: line amount_t amoun
|
||||
While parsing file "$sourcepath/src/amount.h", line 732:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 738:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 744:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 750:
|
||||
Error: Invalid date/time: line std::ostream&
|
||||
While parsing file "$sourcepath/src/amount.h", line 751:
|
||||
While parsing file "$sourcepath/src/amount.h", line 757:
|
||||
Error: Invalid date/time: line std::istream&
|
||||
=== 7
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue