some fixes to value_t in python; still more work to go

This commit is contained in:
John Wiegley 2004-09-07 20:03:01 -04:00
parent 6126d48e27
commit a4c5380a7f
3 changed files with 29 additions and 3 deletions

View file

@ -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

View file

@ -557,6 +557,8 @@ void export_value()
.def(init<balance_pair_t>())
.def(init<balance_t>())
.def(init<amount_t>())
.def(init<std::string>())
.def(init<double>())
.def(init<unsigned int>())
.def(init<bool>())

21
value.h
View file

@ -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) {