00001 // Value.cpp 00002 00003 #include <cassert> 00004 00005 #include "Value.h" 00006 00007 using namespace Yosokumo; 00008 00009 00010 Value::Value(Type type, int64_t ival) : valueType(type), int_value(ival) 00011 {} 00012 00013 Value::Value(Type type, uint64_t uval) : valueType(type), uint_value(uval) 00014 {} 00015 00016 Value::Value(Type type, double dval) : valueType(type), double_value(dval) 00017 {} 00018 00019 Value::Value() : valueType(EMPTY), uint_value(0) 00020 {} 00021 00022 Value::Type Value::getType() const 00023 { 00024 return valueType; 00025 } 00026 00027 void *Value::getEmptyValue() const 00028 { 00029 assert(getType() == EMPTY); 00030 return NULL; 00031 } 00032 00033 uint64_t Value::getNaturalValue() const 00034 { 00035 assert(getType() == NATURAL); 00036 return uint_value; 00037 } 00038 00039 uint64_t Value::getSpecialValue() const 00040 { 00041 assert(getType() == SPECIAL); 00042 return uint_value; 00043 } 00044 00045 int64_t Value::getIntegerValue() const 00046 { 00047 assert(getType() == INTEGER); 00048 return int_value; 00049 } 00050 00051 double Value::getRealValue() const 00052 { 00053 assert(getType() == REAL); 00054 return double_value; 00055 } 00056 00057 // Equality operators 00058 00059 bool Value::operator==(const Value &rhs) const 00060 { 00061 if (getType() != rhs.getType()) 00062 return false; 00063 00064 bool equal; 00065 00066 switch (getType()) 00067 { 00068 case EMPTY: equal = (getEmptyValue() == rhs.getEmptyValue()); break; 00069 case NATURAL: equal = (getNaturalValue() == rhs.getNaturalValue()); break; 00070 case INTEGER: equal = (getIntegerValue() == rhs.getIntegerValue()); break; 00071 case REAL: equal = (getRealValue() == rhs.getRealValue()); break; 00072 case SPECIAL: equal = (getSpecialValue() == rhs.getSpecialValue()); break; 00073 default: assert(false); break; 00074 } 00075 00076 return equal; 00077 } 00078 00079 bool Value::operator!=(const Value &rhs) const 00080 { 00081 return !(*this == rhs); 00082 } 00083 00084 std::string Value::toString() const 00085 { 00086 return "Value::toString was called, and it probably should not have been"; 00087 } 00088 00089 // end Value.cpp