summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-14 05:05:56 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-14 05:05:56 -0400
commitbd72c0cf908492abb99a1419f7f8136729747061 (patch)
tree2ee9bfbf02c94fa9fdf4cd344901e4cc48e65a0a
parenta013b520ba151b9da3adec97d124676a96741b04 (diff)
downloadfork-ledger-bd72c0cf908492abb99a1419f7f8136729747061.tar.gz
fork-ledger-bd72c0cf908492abb99a1419f7f8136729747061.tar.bz2
fork-ledger-bd72c0cf908492abb99a1419f7f8136729747061.zip
added more math operators for value_t types
-rw-r--r--python.cc11
-rw-r--r--value.cc20
-rw-r--r--value.h17
3 files changed, 38 insertions, 10 deletions
diff --git a/python.cc b/python.cc
index 9699873c..288825aa 100644
--- a/python.cc
+++ b/python.cc
@@ -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
diff --git a/value.cc b/value.cc
index 2a211fd1..4a273abc 100644
--- a/value.cc
+++ b/value.cc
@@ -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>())
diff --git a/value.h b/value.h
index 617b5fb7..819f985f 100644
--- a/value.h
+++ b/value.h
@@ -250,6 +250,23 @@ class value_t
};
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
{
switch (type) {