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 src/python/py_utils.cc
libledger_la_SOURCES += $(Python_SRC) libledger_la_SOURCES += $(Python_SRC)
libledger_la_CPPFLAGS += -I$(srcdir)/src/python
endif endif
if HAVE_LIBOFX if HAVE_LIBOFX

View file

@ -15,5 +15,6 @@ setup(name = "Ledger",
url = "http://johnwiegley.com/", url = "http://johnwiegley.com/",
ext_modules = [ ext_modules = [
Extension("ledger", 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)]) define_macros = defines, libraries = libs)])

View file

@ -229,7 +229,7 @@ bool entry_base_t::finalize()
const balance_t * bal = NULL; const balance_t * bal = NULL;
switch (balance.type()) { switch (balance.type()) {
case value_t::BALANCE_PAIR: case value_t::BALANCE_PAIR:
bal = &balance.as_balance_pair().quantity; bal = &balance.as_balance_pair().quantity();
// fall through... // fall through...
case value_t::BALANCE: 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()); DEBUG("ledger.cache", "using_cache " << cache_file->string());
cache_dirty = true; cache_dirty = true;
if (exists(*cache_file)) { if (exists(*cache_file)) {
scoped_variable<optional<path> > push_variable<optional<path> >
save_price_db(journal->price_db, price_db); save_price_db(journal->price_db, price_db);
entry_count += read_journal(*cache_file, builder); entry_count += read_journal(*cache_file, builder);

View file

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

View file

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

View file

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

View file

@ -83,17 +83,6 @@ class balance_pair_t
*/ */
optional<balance_t> cost; 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 value_t;
friend class entry_base_t; friend class entry_base_t;
@ -225,6 +214,17 @@ public:
return quantity() == amt; 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 // unary negation
void in_place_negate() { void in_place_negate() {
#if 0 #if 0

View file

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