Got things compiling with boost/operators.hpp
This commit is contained in:
parent
76b2066b8b
commit
9e80a6fbcc
3 changed files with 26 additions and 37 deletions
14
src/amount.h
14
src/amount.h
|
|
@ -73,7 +73,7 @@ DECLARE_EXCEPTION(amount_error);
|
|||
: public ordered_field_operators<amount_t,
|
||||
ordered_field_operators<amount_t, long,
|
||||
ordered_field_operators<amount_t, unsigned long,
|
||||
ordered_field_operators<amount_t, double > > > >
|
||||
ordered_field_operators<amount_t, double> > > >
|
||||
{
|
||||
public:
|
||||
class bigint_t;
|
||||
|
|
@ -137,9 +137,19 @@ public:
|
|||
// comparisons between amounts
|
||||
int compare(const amount_t& amt) const;
|
||||
bool operator==(const amount_t& amt) const;
|
||||
bool operator<(const amount_t& amt) const {
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const T& val) const {
|
||||
return compare(val) == 0;
|
||||
}
|
||||
template <typename T>
|
||||
bool operator<(const T& amt) const {
|
||||
return compare(amt) < 0;
|
||||
}
|
||||
template <typename T>
|
||||
bool operator>(const T& amt) const {
|
||||
return compare(amt) > 0;
|
||||
}
|
||||
|
||||
// in-place arithmetic
|
||||
amount_t& operator+=(const amount_t& amt);
|
||||
|
|
|
|||
|
|
@ -55,21 +55,6 @@ commodity_t * py_find_commodity(const string& symbol)
|
|||
|
||||
EXC_TRANSLATOR(amount_error)
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
amount_t operator+(const amount_t& amt, const T val) {
|
||||
amount_t temp(amt);
|
||||
temp += amount_t(val);
|
||||
return temp;
|
||||
}
|
||||
template <typename T>
|
||||
amount_t operator+(const T val, const amount_t& amt) {
|
||||
amount_t temp(val);
|
||||
temp += amt;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
void export_amount()
|
||||
{
|
||||
scope().attr("AMOUNT_PARSE_NO_MIGRATE") = AMOUNT_PARSE_NO_MIGRATE;
|
||||
|
|
@ -97,80 +82,75 @@ void export_amount()
|
|||
.def(self -= double())
|
||||
|
||||
.def(self - self)
|
||||
#if 0
|
||||
.def(self - long())
|
||||
.def(long() - self)
|
||||
.def(self - double())
|
||||
.def(double() - self)
|
||||
#endif
|
||||
|
||||
.def(self *= self)
|
||||
.def(self *= long())
|
||||
.def(self *= double())
|
||||
|
||||
.def(self * self)
|
||||
#if 0
|
||||
.def(self * long())
|
||||
.def(long() * self)
|
||||
.def(self * double())
|
||||
.def(double() * self)
|
||||
#endif
|
||||
|
||||
.def(self /= self)
|
||||
.def(self /= long())
|
||||
.def(self /= double())
|
||||
|
||||
.def(self / self)
|
||||
#if 0
|
||||
.def(self / long())
|
||||
.def(long() / self)
|
||||
.def(self / double())
|
||||
.def(double() / self)
|
||||
#endif
|
||||
|
||||
.def(- self)
|
||||
|
||||
.def(self < self)
|
||||
#if 0
|
||||
.def(self < long())
|
||||
.def(long() < self)
|
||||
#endif
|
||||
.def(self < double())
|
||||
.def(double() < self)
|
||||
|
||||
.def(self <= self)
|
||||
#if 0
|
||||
.def(self <= long())
|
||||
.def(long() <= self)
|
||||
#endif
|
||||
.def(self <= double())
|
||||
.def(double() <= self)
|
||||
|
||||
.def(self > self)
|
||||
#if 0
|
||||
.def(self > long())
|
||||
.def(long() > self)
|
||||
#endif
|
||||
.def(self > double())
|
||||
.def(double() > self)
|
||||
|
||||
.def(self >= self)
|
||||
#if 0
|
||||
.def(self >= long())
|
||||
.def(long() >= self)
|
||||
#endif
|
||||
.def(self >= double())
|
||||
.def(double() >= self)
|
||||
|
||||
.def(self == self)
|
||||
#if 0
|
||||
.def(self == long())
|
||||
.def(long() == self)
|
||||
#endif
|
||||
.def(self == double())
|
||||
.def(double() == self)
|
||||
|
||||
.def(self != self)
|
||||
#if 0
|
||||
.def(self != long())
|
||||
.def(long() != self)
|
||||
#endif
|
||||
.def(self != double())
|
||||
.def(double() != self)
|
||||
|
||||
.def(! self)
|
||||
|
||||
.def(self_ns::int_(self))
|
||||
.def(self_ns::float_(self))
|
||||
|
||||
.def("__abs__", &amount_t::abs)
|
||||
.def("__str__", &amount_t::to_string)
|
||||
.def("__repr__", &amount_t::to_fullstring)
|
||||
|
||||
|
|
@ -195,7 +175,6 @@ void export_amount()
|
|||
.def("exact", &amount_t::exact)
|
||||
.staticmethod("exact")
|
||||
|
||||
.def("__abs__", &amount_t::abs)
|
||||
.def("compare", &amount_t::compare)
|
||||
.def("date", &amount_t::date)
|
||||
.def("negate", &amount_t::negate)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ void CommodityAmountTestCase::testEquality()
|
|||
amount_t x9 = "123.45€";
|
||||
amount_t x10 = "-123.45€";
|
||||
|
||||
assertTrue(x0.null());
|
||||
assertTrue(x0.is_null());
|
||||
assertTrue(x0.zero());
|
||||
assertTrue(x0.realzero());
|
||||
assertTrue(x0.sign() == 0);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue