summaryrefslogtreecommitdiff
path: root/value.h
diff options
context:
space:
mode:
Diffstat (limited to 'value.h')
-rw-r--r--value.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/value.h b/value.h
index 10775b1e..617b5fb7 100644
--- a/value.h
+++ b/value.h
@@ -46,6 +46,10 @@ class value_t
*((unsigned int *) data) = value;
type = INTEGER;
}
+ value_t(const int value) {
+ *((unsigned int *) data) = (unsigned int) value;
+ type = INTEGER;
+ }
value_t(const double value) {
new((amount_t *) data) amount_t(value);
type = AMOUNT;
@@ -92,6 +96,9 @@ class value_t
}
return *this;
}
+ value_t& operator=(const int value) {
+ return *this = (unsigned int) value;
+ }
value_t& operator=(const double value) {
return *this = amount_t(value);
}
@@ -143,6 +150,61 @@ class value_t
value_t& operator*=(const value_t& value);
value_t& operator/=(const value_t& value);
+ template <typename T>
+ value_t& operator+=(const T& value) {
+ return *this += value_t(value);
+ }
+ template <typename T>
+ value_t& operator-=(const T& value) {
+ return *this -= value_t(value);
+ }
+ template <typename T>
+ value_t& operator*=(const T& value) {
+ return *this *= value_t(value);
+ }
+ template <typename T>
+ value_t& operator/=(const T& value) {
+ return *this /= value_t(value);
+ }
+
+ value_t operator+(const value_t& value) {
+ value_t temp(*this);
+ temp += value;
+ return temp;
+ }
+ value_t operator-(const value_t& value) {
+ value_t temp(*this);
+ temp -= value;
+ return temp;
+ }
+ value_t operator*(const value_t& value) {
+ value_t temp(*this);
+ temp *= value;
+ return temp;
+ }
+ value_t operator/(const value_t& value) {
+ value_t temp(*this);
+ temp /= value;
+ return temp;
+ }
+
+ template <typename T>
+ value_t operator+(const T& value) {
+ return *this + value_t(value);
+ }
+ template <typename T>
+ value_t operator-(const T& value) {
+ return *this - value_t(value);
+ }
+ template <typename T>
+ value_t operator*(const T& value) {
+ return *this * value_t(value);
+ }
+ template <typename T>
+ value_t operator/(const T& value) {
+ return *this / value_t(value);
+ }
+
bool operator<(const value_t& value);
bool operator<=(const value_t& value);
bool operator>(const value_t& value);
@@ -153,6 +215,31 @@ class value_t
}
template <typename T>
+ bool operator<(const T& value) {
+ return *this < value_t(value);
+ }
+ template <typename T>
+ bool operator<=(const T& value) {
+ return *this <= value_t(value);
+ }
+ template <typename T>
+ bool operator>(const T& value) {
+ return *this > value_t(value);
+ }
+ template <typename T>
+ bool operator>=(const T& value) {
+ return *this >= value_t(value);
+ }
+ template <typename T>
+ bool operator==(const T& value) {
+ return *this == value_t(value);
+ }
+ template <typename T>
+ bool operator!=(const value_t& value) {
+ return ! (*this == value);
+ }
+
+ template <typename T>
operator T() const;
void cast(type_t cast_type);
@@ -185,6 +272,37 @@ value_t::operator T() const
return 0;
}
+inline value_t abs(const value_t& value) {
+ value_t temp(value);
+ temp.abs();
+ return temp;
+}
+
+inline std::ostream& operator<<(std::ostream& out, const value_t& value) {
+ switch (value.type) {
+ case value_t::BOOLEAN:
+ out << *((bool *) value.data);
+ break;
+ case value_t::INTEGER:
+ out << *((unsigned int *) value.data);
+ break;
+ case value_t::AMOUNT:
+ out << *((amount_t *) value.data);
+ break;
+ case value_t::BALANCE:
+ out << *((balance_t *) value.data);
+ break;
+ case value_t::BALANCE_PAIR:
+ out << *((balance_pair_t *) value.data);
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+ return out;
+}
+
class value_error : public std::exception {
std::string reason;
public: