Getting things to compile again.

This commit is contained in:
John Wiegley 2007-05-21 20:45:46 +00:00
parent d23ed020ab
commit ce4ed2b25c
9 changed files with 52 additions and 45 deletions

View file

@ -67,6 +67,7 @@ Python_SRC = \
src/python/py_utils.cc
libledger_la_SOURCES += $(Python_SRC)
libledger_la_CPPFLAGS += -I$(srcdir)/src/python
endif
if HAVE_LIBOFX

View file

@ -15,5 +15,6 @@ setup(name = "Ledger",
url = "http://johnwiegley.com/",
ext_modules = [
Extension("ledger",
[os.path.join(os.environ['SRCDIR'], "src", "pyledger.cc")],
[os.path.join(os.environ['SRCDIR'],
"src", "python", "pyledger.cc")],
define_macros = defines, libraries = libs)])

View file

@ -229,7 +229,7 @@ bool entry_base_t::finalize()
const balance_t * bal = NULL;
switch (balance.type()) {
case value_t::BALANCE_PAIR:
bal = &balance.as_balance_pair().quantity;
bal = &balance.as_balance_pair().quantity();
// fall through...
case value_t::BALANCE:

View file

@ -178,7 +178,7 @@ std::size_t session_t::read_data(xml::builder_t& builder,
DEBUG("ledger.cache", "using_cache " << cache_file->string());
cache_dirty = true;
if (exists(*cache_file)) {
scoped_variable<optional<path> >
push_variable<optional<path> >
save_price_db(journal->price_db, price_db);
entry_count += read_journal(*cache_file, builder);

View file

@ -45,7 +45,6 @@
#include <balance.h>
#include <value.h>
#include <xpath.h>
#include <format.h>
#include <session.h>
#include <journal.h>
#include <parser.h>

View file

@ -586,35 +586,40 @@ amount_t& amount_t::in_place_negate()
return *this;
}
amount_t amount_t::round(const optional<precision_t>& prec) const
amount_t amount_t::round() const
{
if (! quantity)
throw_(amount_error, "Cannot round an uninitialized amount");
if (! prec) {
if (! has_commodity())
return *this;
return round(commodity().precision());
} else {
amount_t t(*this);
if (! has_commodity())
return *this;
if (quantity->prec <= *prec) {
if (quantity && quantity->has_flags(BIGINT_KEEP_PREC)) {
t._dup();
t.quantity->drop_flags(BIGINT_KEEP_PREC);
}
return t;
return round(commodity().precision());
}
amount_t amount_t::round(precision_t prec) const
{
if (! quantity)
throw_(amount_error, "Cannot round an uninitialized amount");
amount_t t(*this);
if (quantity->prec <= prec) {
if (quantity && quantity->has_flags(BIGINT_KEEP_PREC)) {
t._dup();
t.quantity->drop_flags(BIGINT_KEEP_PREC);
}
t._dup();
mpz_round(MPZ(t.quantity), MPZ(t.quantity), t.quantity->prec, *prec);
t.quantity->prec = *prec;
t.quantity->drop_flags(BIGINT_KEEP_PREC);
return t;
}
t._dup();
mpz_round(MPZ(t.quantity), MPZ(t.quantity), t.quantity->prec, prec);
t.quantity->prec = prec;
t.quantity->drop_flags(BIGINT_KEEP_PREC);
return t;
}
amount_t amount_t::unround() const

View file

@ -294,8 +294,8 @@ public:
* abs() returns the absolute value of an amount. It is equivalent
* to: `(x < 0) ? - x : x'.
*
* round(optional<precision_t>) rounds an amount's internal value to
* the given precision, or to the commodity's current display
* round(precision_t) and round() round an amount's internal value
* to the given precision, or to the commodity's current display
* precision if no precision value is given. This method changes
* the internal value of the amount, if it's internal precision was
* greater than the rounding precision.
@ -347,7 +347,8 @@ public:
return *this;
}
amount_t round(const optional<precision_t>& prec = none) const;
amount_t round() const;
amount_t round(precision_t prec) const;
amount_t unround() const;
amount_t reduce() const {

View file

@ -83,17 +83,6 @@ class balance_pair_t
*/
optional<balance_t> cost;
/**
* The `quantity' method provides direct access to the balance_t
* base-class part of the balance pair.
*/
balance_t& quantity() {
return *this;
}
const balance_t& quantity() const {
return *this;
}
friend class value_t;
friend class entry_base_t;
@ -225,6 +214,17 @@ public:
return quantity() == amt;
}
/**
* The `quantity' method provides direct access to the balance_t
* base-class part of the balance pair.
*/
balance_t& quantity() {
return *this;
}
const balance_t& quantity() const {
return *this;
}
// unary negation
void in_place_negate() {
#if 0

View file

@ -1053,7 +1053,7 @@ void value_t::in_place_cast(type_t cast_type)
case BALANCE_PAIR:
switch (cast_type) {
case AMOUNT: {
const balance_t& temp(as_balance_pair().quantity);
const balance_t& temp(as_balance_pair().quantity());
if (temp.amounts.size() == 1) {
set_amount((*temp.amounts.begin()).second);
return;
@ -1069,7 +1069,7 @@ void value_t::in_place_cast(type_t cast_type)
break;
}
case BALANCE:
set_balance(as_balance_pair().quantity);
set_balance(as_balance_pair().quantity());
return;
default:
break;
@ -1184,7 +1184,7 @@ value_t value_t::value(const optional<moment_t>& moment) const
}
case BALANCE_PAIR: {
if (optional<balance_t> bal_pair =
as_balance_pair().quantity.value(moment))
as_balance_pair().quantity().value(moment))
return *bal_pair;
return false;
}
@ -1353,8 +1353,8 @@ value_t value_t::strip_annotations(const bool keep_price,
case BALANCE:
return as_balance().strip_annotations(keep_price, keep_date, keep_tag);
case BALANCE_PAIR:
return as_balance_pair().quantity.strip_annotations(keep_price,
keep_date, keep_tag);
return as_balance_pair().quantity().strip_annotations(keep_price, keep_date,
keep_tag);
default:
assert(false);
@ -1377,7 +1377,7 @@ value_t value_t::cost() const
if (as_balance_pair().cost)
return *(as_balance_pair().cost);
else
return as_balance_pair().quantity;
return as_balance_pair().quantity();
case XML_NODE:
return as_xml_node()->to_value().cost();