Changeset 848 for code/branches/core/src/util/MultiTypePrimitive.cc
- Timestamp:
- Mar 5, 2008, 1:29:47 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/util/MultiTypePrimitive.cc
r797 r848 28 28 29 29 #include "MultiTypePrimitive.h" 30 #include "Convert.h" 30 31 31 32 MultiTypePrimitive::MultiTypePrimitive(MultiType type) … … 140 141 } 141 142 143 MultiTypePrimitive::operator int() const 144 { 145 return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); 146 } 147 148 MultiTypePrimitive::operator unsigned int() const 149 { 150 return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned int>(*this); 151 } 152 153 MultiTypePrimitive::operator char() const 154 { 155 return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypePrimitive, char>(*this); 156 } 157 158 MultiTypePrimitive::operator unsigned char() const 159 { 160 return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned char>(*this); 161 } 162 163 MultiTypePrimitive::operator short() const 164 { 165 return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypePrimitive, short>(*this); 166 } 167 168 MultiTypePrimitive::operator unsigned short() const 169 { 170 return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned short>(*this); 171 } 172 173 MultiTypePrimitive::operator long() const 174 { 175 return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypePrimitive, long>(*this); 176 } 177 178 MultiTypePrimitive::operator unsigned long() const 179 { 180 return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypePrimitive, unsigned long>(*this); 181 } 182 183 MultiTypePrimitive::operator float() const 184 { 185 return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypePrimitive, float>(*this); 186 } 187 188 MultiTypePrimitive::operator double() const 189 { 190 return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypePrimitive, double>(*this); 191 } 192 193 MultiTypePrimitive::operator long double() const 194 { 195 return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypePrimitive, long double>(*this); 196 } 197 198 MultiTypePrimitive::operator bool() const 199 { 200 return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypePrimitive, bool>(*this); 201 } 202 142 203 void MultiTypePrimitive::setValue(const MultiTypePrimitive& mtp) 143 204 { 144 205 this->type_ = mtp.type_; 145 206 this->value_ = mtp.value_; 207 } 208 209 std::string MultiTypePrimitive::toString() const 210 { 211 std::string output; 212 213 if (this->type_ == MT_int) 214 ConvertValue(&output, this->value_.int_); 215 else if (this->type_ == MT_uint) 216 ConvertValue(&output, this->value_.uint_); 217 else if (this->type_ == MT_char) 218 ConvertValue(&output, this->value_.char_); 219 else if (this->type_ == MT_uchar) 220 ConvertValue(&output, this->value_.uchar_); 221 else if (this->type_ == MT_short) 222 ConvertValue(&output, this->value_.short_); 223 else if (this->type_ == MT_ushort) 224 ConvertValue(&output, this->value_.ushort_); 225 else if (this->type_ == MT_long) 226 ConvertValue(&output, this->value_.long_); 227 else if (this->type_ == MT_ulong) 228 ConvertValue(&output, this->value_.ulong_); 229 else if (this->type_ == MT_float) 230 ConvertValue(&output, this->value_.float_); 231 else if (this->type_ == MT_double) 232 ConvertValue(&output, this->value_.double_); 233 else if (this->type_ == MT_longdouble) 234 ConvertValue(&output, this->value_.longdouble_); 235 else if (this->type_ == MT_bool) 236 ConvertValue(&output, this->value_.bool_); 237 238 return output; 239 } 240 241 bool MultiTypePrimitive::fromString(const std::string value) 242 { 243 if (this->type_ == MT_int) 244 return ConvertValue(&this->value_.int_, value, (int)0); 245 else if (this->type_ == MT_uint) 246 return ConvertValue(&this->value_.uint_, value, (unsigned int)0); 247 else if (this->type_ == MT_char) 248 return ConvertValue(&this->value_.char_, value, (char)0); 249 else if (this->type_ == MT_uchar) 250 return ConvertValue(&this->value_.uchar_, value, (unsigned char)0); 251 else if (this->type_ == MT_short) 252 return ConvertValue(&this->value_.short_, value, (short)0); 253 else if (this->type_ == MT_ushort) 254 return ConvertValue(&this->value_.ushort_, value, (unsigned short)0); 255 else if (this->type_ == MT_long) 256 return ConvertValue(&this->value_.long_, value, (long)0); 257 else if (this->type_ == MT_ulong) 258 return ConvertValue(&this->value_.ulong_, value, (unsigned long)0); 259 else if (this->type_ == MT_float) 260 return ConvertValue(&this->value_.float_, value, (float)0.0); 261 else if (this->type_ == MT_double) 262 return ConvertValue(&this->value_.double_, value, (double)0.0); 263 else if (this->type_ == MT_longdouble) 264 return ConvertValue(&this->value_.longdouble_, value, (long double)0.0); 265 else if (this->type_ == MT_bool) 266 return ConvertValue(&this->value_.bool_, value, false); 267 else 268 return false; 146 269 } 147 270
Note: See TracChangeset
for help on using the changeset viewer.