Changeset 1052 for code/trunk/src/util/MultiTypePrimitive.cc
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/util/MultiTypePrimitive.cc
r871 r1052 34 34 this->type_ = type; 35 35 36 if (type == MT_int) 36 if (type == MT_void) 37 this->value_.void_ = 0; 38 else if (type == MT_int) 37 39 this->value_.int_ = 0; 38 40 else if (type == MT_uint) … … 59 61 this->value_.bool_ = false; 60 62 else 61 this->value_. int_ = 0;63 this->value_.void_ = 0; 62 64 } 63 65 … … 66 68 if (this->type_ == mtp.type_) 67 69 { 68 if (this->type_ == MT_int) 70 if (this->type_ == MT_void) 71 return (this->value_.void_ == mtp.value_.void_); 72 else if (this->type_ == MT_int) 69 73 return (this->value_.int_ == mtp.value_.int_); 70 74 else if (this->type_ == MT_uint) … … 99 103 if (this->type_ == mtp.type_) 100 104 { 101 if (this->type_ == MT_int) 105 if (this->type_ == MT_void) 106 return (this->value_.void_ != mtp.value_.void_); 107 else if (this->type_ == MT_int) 102 108 return (this->value_.int_ != mtp.value_.int_); 103 109 else if (this->type_ == MT_uint) … … 128 134 } 129 135 136 MultiTypePrimitive::operator void*() const 137 { return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypePrimitive, void*>(*this, 0); } 130 138 MultiTypePrimitive::operator int() const 131 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); }139 { return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypePrimitive, int>(*this, 0); } 132 140 MultiTypePrimitive::operator unsigned int() const 133 { return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this); }141 { return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypePrimitive, unsigned int>(*this, 0); } 134 142 MultiTypePrimitive::operator char() const 135 { return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this); }143 { return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypePrimitive, char>(*this, 0); } 136 144 MultiTypePrimitive::operator unsigned char() const 137 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this); }145 { return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypePrimitive, unsigned char>(*this, 0); } 138 146 MultiTypePrimitive::operator short() const 139 { return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this); }147 { return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypePrimitive, short>(*this, 0); } 140 148 MultiTypePrimitive::operator unsigned short() const 141 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this); }149 { return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypePrimitive, unsigned short>(*this, 0); } 142 150 MultiTypePrimitive::operator long() const 143 { return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this); }151 { return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypePrimitive, long>(*this, 0); } 144 152 MultiTypePrimitive::operator unsigned long() const 145 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this); }153 { return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypePrimitive, unsigned long>(*this, 0); } 146 154 MultiTypePrimitive::operator float() const 147 { return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this); }155 { return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypePrimitive, float>(*this, 0); } 148 156 MultiTypePrimitive::operator double() const 149 { return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this); }157 { return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypePrimitive, double>(*this, 0); } 150 158 MultiTypePrimitive::operator long double() const 151 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this); }159 { return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypePrimitive, long double>(*this, 0); } 152 160 MultiTypePrimitive::operator bool() const 153 { return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this); }161 { return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypePrimitive, bool>(*this, 0); } 154 162 155 163 void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) … … 159 167 } 160 168 169 std::string MultiTypePrimitive::getTypename() const 170 { 171 if (this->type_ == MT_void) 172 return "pointer"; 173 else if (this->type_ == MT_int) 174 return "int"; 175 else if (this->type_ == MT_uint) 176 return "unsigned int"; 177 else if (this->type_ == MT_char) 178 return "char"; 179 else if (this->type_ == MT_uchar) 180 return "unsigned char"; 181 else if (this->type_ == MT_short) 182 return "short"; 183 else if (this->type_ == MT_ushort) 184 return "unsigned short"; 185 else if (this->type_ == MT_long) 186 return "long"; 187 else if (this->type_ == MT_ulong) 188 return "unsigned long"; 189 else if (this->type_ == MT_float) 190 return "float"; 191 else if (this->type_ == MT_double) 192 return "double"; 193 else if (this->type_ == MT_longdouble) 194 return "long double"; 195 else if (this->type_ == MT_bool) 196 return "bool"; 197 else 198 return "unknown"; 199 } 200 161 201 std::string MultiTypePrimitive::toString() const 162 202 { 163 203 std::string output; 164 204 165 if (this->type_ == MT_int) 205 if (this->type_ == MT_void) 206 ConvertValue(&output, this->value_.void_); 207 else if (this->type_ == MT_int) 166 208 ConvertValue(&output, this->value_.int_); 167 209 else if (this->type_ == MT_uint) … … 193 235 bool MultiTypePrimitive::fromString(const std::string value) 194 236 { 195 if (this->type_ == MT_int) 237 if (this->type_ == MT_void) 238 return ConvertValue(&this->value_.void_, value, (void*)0); 239 else if (this->type_ == MT_int) 196 240 return ConvertValue(&this->value_.int_, value, (int)0); 197 241 else if (this->type_ == MT_uint)
Note: See TracChangeset
for help on using the changeset viewer.