summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-11 16:03:50 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-11 17:02:25 -0400
commitdea2aed0b509734ec4e1cd163ac2a4f013000da2 (patch)
tree7908da76c67ae5172882306a319bf26df81b73b4 /src/value.cc
parentd580079df892c30d023b3211d6c4611c17b11f8f (diff)
downloadfork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.tar.gz
fork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.tar.bz2
fork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.zip
Untabified all source files
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc360
1 files changed, 180 insertions, 180 deletions
diff --git a/src/value.cc b/src/value.cc
index 74dd843d..63e48333 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -35,7 +35,7 @@
#include "commodity.h"
#include "annotate.h"
#include "pool.h"
-#include "unistring.h" // for justify()
+#include "unistring.h" // for justify()
#include "op.h"
namespace ledger {
@@ -65,11 +65,11 @@ value_t::storage_t& value_t::storage_t::operator=(const value_t::storage_t& rhs)
void value_t::initialize()
{
- true_value = new storage_t;
+ true_value = new storage_t;
true_value->type = BOOLEAN;
true_value->data = true;
- false_value = new storage_t;
+ false_value = new storage_t;
false_value->type = BOOLEAN;
false_value->data = false;
}
@@ -103,14 +103,14 @@ value_t::operator bool() const
std::ostringstream out;
out << *this;
throw_(value_error,
- _("Cannot determine truth of %1 (did you mean 'account =~ %2'?)")
- << label() << out.str());
+ _("Cannot determine truth of %1 (did you mean 'account =~ %2'?)")
+ << label() << out.str());
}
case SEQUENCE:
if (! as_sequence().empty()) {
foreach (const value_t& value, as_sequence()) {
- if (value)
- return true;
+ if (value)
+ return true;
}
}
return false;
@@ -281,7 +281,7 @@ void value_t::in_place_simplify()
DEBUG_("as an amount it looks like: " << *this);
}
-#ifdef REDUCE_TO_INTEGER // this is off by default
+#ifdef REDUCE_TO_INTEGER // this is off by default
if (is_amount() && ! as_amount().has_commodity() &&
as_amount().fits_in_long()) {
DEBUG_("Reducing amount to integer");
@@ -307,7 +307,7 @@ value_t value_t::number() const
if (! as_sequence().empty()) {
value_t temp;
foreach (const value_t& value, as_sequence())
- temp += value.number();
+ temp += value.number();
return temp;
}
break;
@@ -333,14 +333,14 @@ value_t& value_t::operator+=(const value_t& val)
else if (is_sequence()) {
if (val.is_sequence()) {
if (size() == val.size()) {
- sequence_t::iterator i = begin();
- sequence_t::const_iterator j = val.begin();
+ sequence_t::iterator i = begin();
+ sequence_t::const_iterator j = val.begin();
- for (; i != end(); i++, j++)
- *i += *j;
+ for (; i != end(); i++, j++)
+ *i += *j;
} else {
- add_error_context(_("While adding %1 to %2:") << *this << val);
- throw_(value_error, _("Cannot add sequences of different lengths"));
+ add_error_context(_("While adding %1 to %2:") << *this << val);
+ throw_(value_error, _("Cannot add sequences of different lengths"));
}
} else {
as_sequence_lval().push_back(new value_t(val));
@@ -353,12 +353,12 @@ value_t& value_t::operator+=(const value_t& val)
switch (val.type()) {
case INTEGER:
as_datetime_lval() +=
- time_duration_t(0, 0, static_cast<time_duration_t::sec_type>(val.as_long()));
+ time_duration_t(0, 0, static_cast<time_duration_t::sec_type>(val.as_long()));
return *this;
case AMOUNT:
as_datetime_lval() +=
- time_duration_t(0, 0, static_cast<time_duration_t::sec_type>
- (val.as_amount().to_long()));
+ time_duration_t(0, 0, static_cast<time_duration_t::sec_type>
+ (val.as_amount().to_long()));
return *this;
default:
break;
@@ -385,8 +385,8 @@ value_t& value_t::operator+=(const value_t& val)
return *this;
case AMOUNT:
if (val.as_amount().has_commodity()) {
- in_place_cast(BALANCE);
- return *this += val;
+ in_place_cast(BALANCE);
+ return *this += val;
}
in_place_cast(AMOUNT);
as_amount_lval() += val.as_amount();
@@ -404,21 +404,21 @@ value_t& value_t::operator+=(const value_t& val)
switch (val.type()) {
case INTEGER:
if (as_amount().has_commodity()) {
- in_place_cast(BALANCE);
- return *this += val;
+ in_place_cast(BALANCE);
+ return *this += val;
} else {
- as_amount_lval() += val.as_long();
- return *this;
+ as_amount_lval() += val.as_long();
+ return *this;
}
break;
case AMOUNT:
if (as_amount().commodity() != val.as_amount().commodity()) {
- in_place_cast(BALANCE);
- return *this += val;
+ in_place_cast(BALANCE);
+ return *this += val;
} else {
- as_amount_lval() += val.as_amount();
- return *this;
+ as_amount_lval() += val.as_amount();
+ return *this;
}
break;
@@ -465,19 +465,19 @@ value_t& value_t::operator-=(const value_t& val)
if (val.is_sequence()) {
if (size() == val.size()) {
- sequence_t::iterator i = begin();
- sequence_t::const_iterator j = val.begin();
+ sequence_t::iterator i = begin();
+ sequence_t::const_iterator j = val.begin();
- for (; i != end(); i++, j++)
- *i -= *j;
+ for (; i != end(); i++, j++)
+ *i -= *j;
} else {
- add_error_context(_("While subtracting %1 to %2:") << *this << val);
- throw_(value_error, _("Cannot subtract sequences of different lengths"));
+ add_error_context(_("While subtracting %1 to %2:") << *this << val);
+ throw_(value_error, _("Cannot subtract sequences of different lengths"));
}
} else {
sequence_t::iterator i = std::find(seq.begin(), seq.end(), val);
if (i != seq.end())
- seq.erase(i);
+ seq.erase(i);
}
return *this;
}
@@ -487,12 +487,12 @@ value_t& value_t::operator-=(const value_t& val)
switch (val.type()) {
case INTEGER:
as_datetime_lval() -=
- time_duration_t(0, 0, static_cast<time_duration_t::sec_type>(val.as_long()));
+ time_duration_t(0, 0, static_cast<time_duration_t::sec_type>(val.as_long()));
return *this;
case AMOUNT:
as_datetime_lval() -=
- time_duration_t(0, 0, static_cast<time_duration_t::sec_type>
- (val.as_amount().to_long()));
+ time_duration_t(0, 0, static_cast<time_duration_t::sec_type>
+ (val.as_amount().to_long()));
return *this;
default:
break;
@@ -536,27 +536,27 @@ value_t& value_t::operator-=(const value_t& val)
switch (val.type()) {
case INTEGER:
if (as_amount().has_commodity()) {
- in_place_cast(BALANCE);
- *this -= val;
- in_place_simplify();
- return *this;
+ in_place_cast(BALANCE);
+ *this -= val;
+ in_place_simplify();
+ return *this;
} else {
- as_amount_lval() -= val.as_long();
- in_place_simplify();
- return *this;
+ as_amount_lval() -= val.as_long();
+ in_place_simplify();
+ return *this;
}
break;
case AMOUNT:
if (as_amount().commodity() != val.as_amount().commodity()) {
- in_place_cast(BALANCE);
- *this -= val;
- in_place_simplify();
- return *this;
+ in_place_cast(BALANCE);
+ *this -= val;
+ in_place_simplify();
+ return *this;
} else {
- as_amount_lval() -= val.as_amount();
- in_place_simplify();
- return *this;
+ as_amount_lval() -= val.as_amount();
+ in_place_simplify();
+ return *this;
}
break;
@@ -642,8 +642,8 @@ value_t& value_t::operator*=(const value_t& val)
return *this;
case BALANCE:
if (val.as_balance().single_amount()) {
- as_amount_lval() *= val.simplified().as_amount();
- return *this;
+ as_amount_lval() *= val.simplified().as_amount();
+ return *this;
}
break;
default:
@@ -658,13 +658,13 @@ value_t& value_t::operator*=(const value_t& val)
return *this;
case AMOUNT:
if (as_balance().single_amount()) {
- in_place_simplify();
- as_amount_lval() *= val.as_amount();
- return *this;
+ in_place_simplify();
+ as_amount_lval() *= val.as_amount();
+ return *this;
}
else if (! val.as_amount().has_commodity()) {
- as_balance_lval() *= val.as_amount();
- return *this;
+ as_balance_lval() *= val.as_amount();
+ return *this;
}
break;
default:
@@ -709,19 +709,19 @@ value_t& value_t::operator/=(const value_t& val)
return *this;
case BALANCE:
if (val.as_balance().single_amount()) {
- value_t simpler(val.simplified());
- switch (simpler.type()) {
- case INTEGER:
- as_amount_lval() /= simpler.as_long();
- break;
- case AMOUNT:
- as_amount_lval() /= simpler.as_amount();
- break;
- default:
- assert(false);
- break;
- }
- return *this;
+ value_t simpler(val.simplified());
+ switch (simpler.type()) {
+ case INTEGER:
+ as_amount_lval() /= simpler.as_long();
+ break;
+ case AMOUNT:
+ as_amount_lval() /= simpler.as_amount();
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ return *this;
}
break;
default:
@@ -736,13 +736,13 @@ value_t& value_t::operator/=(const value_t& val)
return *this;
case AMOUNT:
if (as_balance().single_amount()) {
- in_place_simplify();
- as_amount_lval() /= val.as_amount();
- return *this;
+ in_place_simplify();
+ as_amount_lval() /= val.as_amount();
+ return *this;
}
else if (! val.as_amount().has_commodity()) {
- as_balance_lval() /= val.as_amount();
- return *this;
+ as_balance_lval() /= val.as_amount();
+ return *this;
}
break;
default:
@@ -852,16 +852,16 @@ bool value_t::is_less_than(const value_t& val) const
case BOOLEAN:
if (val.is_boolean()) {
if (as_boolean()) {
- if (! val.as_boolean())
- return false;
- else
- return false;
+ if (! val.as_boolean())
+ return false;
+ else
+ return false;
}
else if (! as_boolean()) {
- if (! val.as_boolean())
- return false;
- else
- return true;
+ if (! val.as_boolean())
+ return false;
+ else
+ return true;
}
}
break;
@@ -893,11 +893,11 @@ bool value_t::is_less_than(const value_t& val) const
return as_amount() < val.as_long();
case AMOUNT:
if (as_amount().commodity() == val.as_amount().commodity() ||
- ! as_amount().has_commodity() ||
- ! val.as_amount().has_commodity())
- return as_amount() < val.as_amount();
+ ! as_amount().has_commodity() ||
+ ! val.as_amount().has_commodity())
+ return as_amount() < val.as_amount();
else
- return commodity_t::compare_by_commodity()(&as_amount(), &val.as_amount());
+ return commodity_t::compare_by_commodity()(&as_amount(), &val.as_amount());
default:
break;
}
@@ -908,14 +908,14 @@ bool value_t::is_less_than(const value_t& val) const
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
- break;
+ break;
bool no_amounts = true;
foreach (const balance_t::amounts_map::value_type& pair,
- as_balance().amounts) {
- if (pair.second >= 0L)
- return false;
- no_amounts = false;
+ as_balance().amounts) {
+ if (pair.second >= 0L)
+ return false;
+ no_amounts = false;
}
return ! no_amounts;
}
@@ -934,13 +934,13 @@ bool value_t::is_less_than(const value_t& val) const
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
- break;
+ break;
bool no_amounts = true;
foreach (const value_t& value, as_sequence()) {
- if (value >= 0L)
- return false;
- no_amounts = false;
+ if (value >= 0L)
+ return false;
+ no_amounts = false;
}
return ! no_amounts;
}
@@ -948,14 +948,14 @@ bool value_t::is_less_than(const value_t& val) const
sequence_t::const_iterator i = as_sequence().begin();
sequence_t::const_iterator j = val.as_sequence().begin();
for (; (i != as_sequence().end() &&
- j != val.as_sequence().end()); i++, j++) {
- if (! ((*i) < (*j)))
- return false;
+ j != val.as_sequence().end()); i++, j++) {
+ if (! ((*i) < (*j)))
+ return false;
}
if (i == as_sequence().end())
- return true;
+ return true;
else
- return false;
+ return false;
break;
}
default:
@@ -968,7 +968,7 @@ bool value_t::is_less_than(const value_t& val) const
}
add_error_context(_("While comparing if %1 is less than %2:")
- << *this << val);
+ << *this << val);
throw_(value_error, _("Cannot compare %1 to %2") << label() << val.label());
return *this;
@@ -979,16 +979,16 @@ bool value_t::is_greater_than(const value_t& val) const
switch (type()) {
if (val.is_boolean()) {
if (as_boolean()) {
- if (! val.as_boolean())
- return true;
- else
- return false;
+ if (! val.as_boolean())
+ return true;
+ else
+ return false;
}
else if (! as_boolean()) {
- if (! val.as_boolean())
- return false;
- else
- return false;
+ if (! val.as_boolean())
+ return false;
+ else
+ return false;
}
}
break;
@@ -1030,14 +1030,14 @@ bool value_t::is_greater_than(const value_t& val) const
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
- break;
+ break;
bool no_amounts = true;
foreach (const balance_t::amounts_map::value_type& pair,
- as_balance().amounts) {
- if (pair.second <= 0L)
- return false;
- no_amounts = false;
+ as_balance().amounts) {
+ if (pair.second <= 0L)
+ return false;
+ no_amounts = false;
}
return ! no_amounts;
}
@@ -1056,13 +1056,13 @@ bool value_t::is_greater_than(const value_t& val) const
case INTEGER:
case AMOUNT: {
if (val.is_nonzero())
- break;
+ break;
bool no_amounts = true;
foreach (const value_t& value, as_sequence()) {
- if (value <= 0L)
- return false;
- no_amounts = false;
+ if (value <= 0L)
+ return false;
+ no_amounts = false;
}
return ! no_amounts;
}
@@ -1070,14 +1070,14 @@ bool value_t::is_greater_than(const value_t& val) const
sequence_t::const_iterator i = as_sequence().begin();
sequence_t::const_iterator j = val.as_sequence().begin();
for (; (i != as_sequence().end() &&
- j != val.as_sequence().end()); i++, j++) {
- if (! ((*i) > (*j)))
- return false;
+ j != val.as_sequence().end()); i++, j++) {
+ if (! ((*i) > (*j)))
+ return false;
}
if (i == as_sequence().end())
- return false;
+ return false;
else
- return true;
+ return true;
break;
}
default:
@@ -1090,7 +1090,7 @@ bool value_t::is_greater_than(const value_t& val) const
}
add_error_context(_("While comparing if %1 is greater than %2:")
- << *this << val);
+ << *this << val);
throw_(value_error, _("Cannot compare %1 to %2") << label() << val.label());
return *this;
@@ -1194,21 +1194,21 @@ void value_t::in_place_cast(type_t cast_type)
switch (cast_type) {
case INTEGER:
if (amt.is_null())
- set_long(0L);
+ set_long(0L);
else
- set_long(as_amount().to_long());
+ set_long(as_amount().to_long());
return;
case BALANCE:
if (amt.is_null())
- set_balance(balance_t());
+ set_balance(balance_t());
else
- set_balance(as_amount());
+ set_balance(as_amount());
return;
case STRING:
if (amt.is_null())
- set_string("");
+ set_string("");
else
- set_string(as_amount().to_string());
+ set_string(as_amount().to_string());
return;
default:
break;
@@ -1221,28 +1221,28 @@ void value_t::in_place_cast(type_t cast_type)
switch (cast_type) {
case AMOUNT: {
if (bal.amounts.size() == 1) {
- // Because we are changing the current balance value to an amount
- // value, and because set_amount takes a reference (and that memory is
- // about to be repurposed), we must pass in a copy.
- set_amount(amount_t((*bal.amounts.begin()).second));
- return;
+ // Because we are changing the current balance value to an amount
+ // value, and because set_amount takes a reference (and that memory is
+ // about to be repurposed), we must pass in a copy.
+ set_amount(amount_t((*bal.amounts.begin()).second));
+ return;
}
else if (bal.amounts.size() == 0) {
- set_amount(0L);
- return;
+ set_amount(0L);
+ return;
}
else {
- add_error_context(_("While converting %1 to an amount:") << *this);
- throw_(value_error, _("Cannot convert %1 with multiple commodities to %2")
- << label() << label(cast_type));
+ add_error_context(_("While converting %1 to an amount:") << *this);
+ throw_(value_error, _("Cannot convert %1 with multiple commodities to %2")
+ << label() << label(cast_type));
}
break;
}
case STRING:
if (bal.is_empty())
- set_string("");
+ set_string("");
else
- set_string(as_balance().to_string());
+ set_string(as_balance().to_string());
return;
default:
break;
@@ -1254,8 +1254,8 @@ void value_t::in_place_cast(type_t cast_type)
switch (cast_type) {
case INTEGER: {
if (all(as_string(), is_digit())) {
- set_long(lexical_cast<long>(as_string()));
- return;
+ set_long(lexical_cast<long>(as_string()));
+ return;
}
break;
}
@@ -1282,7 +1282,7 @@ void value_t::in_place_cast(type_t cast_type)
add_error_context(_("While converting %1:") << *this);
throw_(value_error,
- _("Cannot convert %1 to %2") << label() << label(cast_type));
+ _("Cannot convert %1 to %2") << label() << label(cast_type));
}
void value_t::in_place_negate()
@@ -1421,7 +1421,7 @@ bool value_t::is_zero() const
}
value_t value_t::value(const optional<datetime_t>& moment,
- const optional<commodity_t&>& in_terms_of) const
+ const optional<commodity_t&>& in_terms_of) const
{
switch (type()) {
case INTEGER:
@@ -1429,13 +1429,13 @@ value_t value_t::value(const optional<datetime_t>& moment,
case AMOUNT:
if (optional<amount_t> val =
- as_amount().value(moment, in_terms_of))
+ as_amount().value(moment, in_terms_of))
return *val;
return NULL_VALUE;
case BALANCE:
if (optional<balance_t> bal =
- as_balance().value(moment, in_terms_of))
+ as_balance().value(moment, in_terms_of))
return *bal;
return NULL_VALUE;
@@ -1460,9 +1460,9 @@ value_t value_t::price() const
}
}
-value_t value_t::exchange_commodities(const std::string& commodities,
- const bool add_prices,
- const optional<datetime_t>& moment)
+value_t value_t::exchange_commodities(const std::string& commodities,
+ const bool add_prices,
+ const optional<datetime_t>& moment)
{
scoped_array<char> buf(new char[commodities.length() + 1]);
@@ -1472,11 +1472,11 @@ value_t value_t::exchange_commodities(const std::string& commodities,
p;
p = std::strtok(NULL, ",")) {
if (commodity_t * commodity =
- commodity_pool_t::current_pool->parse_price_expression(p, add_prices,
- moment)) {
+ commodity_pool_t::current_pool->parse_price_expression(p, add_prices,
+ moment)) {
value_t result = value(moment, *commodity);
if (! result.is_null())
- return result;
+ return result;
}
}
return *this;
@@ -1657,7 +1657,7 @@ bool value_t::has_annotation() const
} else {
add_error_context(_("While checking if %1 has annotations:") << *this);
throw_(value_error,
- _("Cannot determine whether %1 is annotated") << label());
+ _("Cannot determine whether %1 is annotated") << label());
}
return false;
}
@@ -1711,9 +1711,9 @@ value_t value_t::strip_annotations(const keep_details_t& what_to_keep) const
}
void value_t::print(std::ostream& out,
- const int first_width,
- const int latter_width,
- const uint_least8_t flags) const
+ const int first_width,
+ const int latter_width,
+ const uint_least8_t flags) const
{
if (first_width > 0 &&
(! is_amount() || as_amount().is_zero()) &&
@@ -1746,7 +1746,7 @@ void value_t::print(std::ostream& out,
case INTEGER:
if (flags & AMOUNT_PRINT_COLORIZE && as_long() < 0)
justify(out, to_string(), first_width,
- flags & AMOUNT_PRINT_RIGHT_JUSTIFY, true);
+ flags & AMOUNT_PRINT_RIGHT_JUSTIFY, true);
else
out << as_long();
break;
@@ -1758,7 +1758,7 @@ void value_t::print(std::ostream& out,
std::ostringstream buf;
as_amount().print(buf, flags);
justify(out, buf.str(), first_width, flags & AMOUNT_PRINT_RIGHT_JUSTIFY,
- flags & AMOUNT_PRINT_COLORIZE && as_amount().sign() < 0);
+ flags & AMOUNT_PRINT_COLORIZE && as_amount().sign() < 0);
}
break;
}
@@ -1783,9 +1783,9 @@ void value_t::print(std::ostream& out,
bool first = true;
foreach (const value_t& value, as_sequence()) {
if (first)
- first = false;
+ first = false;
else
- out << ", ";
+ out << ", ";
value.print(out, first_width, latter_width, flags);
}
@@ -1853,14 +1853,14 @@ void value_t::dump(std::ostream& out, const bool relaxed) const
foreach (const char& ch, as_string()) {
switch (ch) {
case '"':
- out << "\\\"";
- break;
+ out << "\\\"";
+ break;
case '\\':
- out << "\\\\";
- break;
+ out << "\\\\";
+ break;
default:
- out << ch;
- break;
+ out << ch;
+ break;
}
}
out << '"';
@@ -1885,9 +1885,9 @@ void value_t::dump(std::ostream& out, const bool relaxed) const
bool first = true;
foreach (const value_t& value, as_sequence()) {
if (first)
- first = false;
+ first = false;
else
- out << ", ";
+ out << ", ";
value.dump(out, relaxed);
}
@@ -1915,7 +1915,7 @@ bool value_t::valid() const
}
bool sort_value_is_less_than(const std::list<sort_value_t>& left_values,
- const std::list<sort_value_t>& right_values)
+ const std::list<sort_value_t>& right_values)
{
std::list<sort_value_t>::const_iterator left_iter = left_values.begin();
std::list<sort_value_t>::const_iterator right_iter = right_values.begin();
@@ -1923,16 +1923,16 @@ bool sort_value_is_less_than(const std::list<sort_value_t>& left_values,
while (left_iter != left_values.end() && right_iter != right_values.end()) {
// Don't even try to sort balance values
if (! (*left_iter).value.is_balance() &&
- ! (*right_iter).value.is_balance()) {
+ ! (*right_iter).value.is_balance()) {
DEBUG("value.sort",
- " Comparing " << (*left_iter).value << " < " << (*right_iter).value);
+ " Comparing " << (*left_iter).value << " < " << (*right_iter).value);
if ((*left_iter).value < (*right_iter).value) {
- DEBUG("value.sort", " is less");
- return ! (*left_iter).inverted;
+ DEBUG("value.sort", " is less");
+ return ! (*left_iter).inverted;
}
else if ((*left_iter).value > (*right_iter).value) {
- DEBUG("value.sort", " is greater");
- return (*left_iter).inverted;
+ DEBUG("value.sort", " is greater");
+ return (*left_iter).inverted;
}
}
left_iter++; right_iter++;