added more math operators for value_t types

This commit is contained in:
John Wiegley 2004-09-14 05:05:56 -04:00
parent a013b520ba
commit bd72c0cf90
3 changed files with 38 additions and 10 deletions

View file

@ -63,16 +63,7 @@ void init_python()
Py_Initialize();
python_interpretor = new python_support;
#if 1
boost::python::detail::init_module("ledger", &init_module);
#else
object m_obj(python_interpretor->main_module);
scope current_module(m_obj);
python_interpretor->main_namespace.attr("bar") = 10;
handle_exception(init_module_main);
#endif
detail::init_module("ledger", &init_module);
}
} // namespace ledger

View file

@ -642,6 +642,26 @@ void export_value()
.def(self / other<amount_t>())
.def(self / int())
.def(other<balance_pair_t>() + self)
.def(other<balance_t>() + self)
.def(other<amount_t>() + self)
.def(int() + self)
.def(other<balance_pair_t>() - self)
.def(other<balance_t>() - self)
.def(other<amount_t>() - self)
.def(int() - self)
.def(other<balance_pair_t>() * self)
.def(other<balance_t>() * self)
.def(other<amount_t>() * self)
.def(int() * self)
.def(other<balance_pair_t>() / self)
.def(other<balance_t>() / self)
.def(other<amount_t>() / self)
.def(int() / self)
.def(self += self)
.def(self += other<balance_pair_t>())
.def(self += other<balance_t>())

17
value.h
View file

@ -249,6 +249,23 @@ class value_t
value_t cost() const;
};
template <typename T>
value_t operator+(const T& value, const value_t& obj) {
return value_t(value) + obj;
}
template <typename T>
value_t operator-(const T& value, const value_t& obj) {
return value_t(value) - obj;
}
template <typename T>
value_t operator*(const T& value, const value_t& obj) {
return value_t(value) * obj;
}
template <typename T>
value_t operator/(const T& value, const value_t& obj) {
return value_t(value) / obj;
}
template <typename T>
value_t::operator T() const
{