diff --git a/amounts.py b/amounts.py index f3a58986..aa70086c 100644 --- a/amounts.py +++ b/amounts.py @@ -8,8 +8,11 @@ print x y = Amount ("$1000.45") print x + y -z = Value ("$1000.45") -print y + z +y = Amount ("$1000.45") +print x * y -z += x +z = Value ("$1000.45") +#print z + Value(y) + +z += Value(x) print z diff --git a/value.cc b/value.cc index a811c778..d48426b4 100644 --- a/value.cc +++ b/value.cc @@ -557,6 +557,8 @@ void export_value() .def(init()) .def(init()) .def(init()) + .def(init()) + .def(init()) .def(init()) .def(init()) diff --git a/value.h b/value.h index 39a258b5..10775b1e 100644 --- a/value.h +++ b/value.h @@ -46,6 +46,18 @@ class value_t *((unsigned int *) data) = value; type = INTEGER; } + value_t(const double value) { + new((amount_t *) data) amount_t(value); + type = AMOUNT; + } + value_t(const std::string& value) { + new((amount_t *) data) amount_t(value); + type = AMOUNT; + } + value_t(const char * value) { + new((amount_t *) data) amount_t(value); + type = AMOUNT; + } value_t(const amount_t& value) { new((amount_t *)data) amount_t(value); type = AMOUNT; @@ -80,6 +92,15 @@ class value_t } return *this; } + value_t& operator=(const double value) { + return *this = amount_t(value); + } + value_t& operator=(const std::string& value) { + return *this = amount_t(value); + } + value_t& operator=(const char * value) { + return *this = amount_t(value); + } value_t& operator=(const amount_t& value) { if ((amount_t *) data != &value) { if (! value) {