00001 // Value.h 00002 00003 #ifndef VALUE_H 00004 #define VALUE_H 00005 00006 #include <stdint.h> 00007 #include <string> 00008 00009 namespace Yosokumo 00010 { 00011 00012 /** 00013 * A base class for value classes which store specific primitive data types, 00014 * e.g., <code>IntegerValue</code> and <code>RealValue</code>. Note that 00015 * all storage is in the base class itself. 00016 */ 00017 class Value 00018 { 00019 public: 00020 /** 00021 * Indicates the data type stored in the <code>Value</code>, e.g., 00022 * integer or real. 00023 */ 00024 enum Type 00025 { 00026 /** 00027 * empty value. 00028 */ 00029 EMPTY, 00030 /** 00031 * an unsigned integer. 00032 */ 00033 NATURAL, 00034 /** 00035 * a signed integer. 00036 */ 00037 INTEGER, 00038 /** 00039 * real, i.e., floating-point. 00040 */ 00041 REAL, 00042 /** 00043 * special value (represented as an unsigned integer). 00044 */ 00045 SPECIAL 00046 }; 00047 00048 protected: 00049 00050 Type valueType; 00051 00052 union 00053 { 00054 int64_t int_value; 00055 uint64_t uint_value; 00056 double double_value; 00057 }; 00058 00059 Value(Type type, int64_t ival); 00060 00061 Value(Type type, uint64_t uval); 00062 00063 Value(Type type, double dval); 00064 00065 public: 00066 00067 /** 00068 * Default constructor for Value. 00069 */ 00070 Value(); 00071 00072 /** 00073 * Return the type of the value. 00074 * 00075 * @return the type of the value. 00076 */ 00077 Type getType() const; 00078 00079 /** 00080 * Return an empty value. The type of the Value must be EMPTY. 00081 * 00082 * @return an empty value. 00083 */ 00084 void *getEmptyValue() const; 00085 00086 /** 00087 * Return a natural value. The type of the Value must be NATURAL. 00088 * 00089 * @return a natural value. 00090 */ 00091 uint64_t getNaturalValue() const; 00092 00093 /** 00094 * Return a special value. The type of the Value must be SPECIAL. 00095 * 00096 * @return a special value. 00097 */ 00098 uint64_t getSpecialValue() const; 00099 00100 /** 00101 * Return an integer value. The type of the Value must be INTEGER. 00102 * 00103 * @return an integer value. 00104 */ 00105 int64_t getIntegerValue() const; 00106 00107 /** 00108 * Return a real value. The type of the Value must be REAL. 00109 * 00110 * @return a real value. 00111 */ 00112 double getRealValue() const; 00113 00114 // Equality operators 00115 00116 /** 00117 * Equality operator - compare two <code>Values</code> for equality. 00118 * 00119 * @param rhs the righthand side of the equality. 00120 * 00121 * @return <code>true</code> if and only if <code>this</code> 00122 * <code>Values</code> and the righthand side 00123 * <code>Values</code> are identically equal. 00124 */ 00125 bool operator==(const Value &rhs) const; 00126 00127 /** 00128 * Inequality operator - compare two <code>Values</code> for inequality. 00129 * 00130 * @param rhs the righthand side of the inequality. 00131 * 00132 * @return <code>true</code> if and only if <code>this</code> 00133 * <code>Values</code> and the righthand side 00134 * <code>Values</code> are not identically equal. 00135 */ 00136 bool operator!=(const Value &rhs) const; 00137 00138 /** 00139 * Return the value as a string. 00140 * 00141 * @return the value as a string. 00142 */ 00143 virtual std::string toString() const; 00144 00145 }; // end class Value 00146 00147 } // end namespace Yosokumo 00148 00149 #endif // VALUE_H 00150 00151 // end Value.h