Changeset 1722 for code/branches/core3/src/util/MultiType.h
- Timestamp:
- Sep 6, 2008, 7:34:49 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/util/MultiType.h
r1720 r1722 77 77 struct _UtilExport MT_ValueBase 78 78 { 79 MT_ValueBase(MT_Type type) : type_(type) {} 79 80 virtual ~MT_ValueBase() {} 80 81 81 82 virtual MT_ValueBase* clone() const = 0; 83 84 const MT_Type& getType() const { return this->type_; } 82 85 83 86 virtual void setValue(const char& value) = 0; … … 130 133 131 134 virtual void toString(std::ostream& outstream) const = 0; 135 136 MT_Type type_; 132 137 }; 133 138 134 139 public: 135 inline MultiType() : value_(0), type_(MT_null) {} 136 inline MultiType(const char& value) : value_(0), type_(MT_null) { this->assignValue(value); } 137 inline MultiType(const unsigned char& value) : value_(0), type_(MT_null) { this->assignValue(value); } 138 inline MultiType(const short& value) : value_(0), type_(MT_null) { this->assignValue(value); } 139 inline MultiType(const unsigned short& value) : value_(0), type_(MT_null) { this->assignValue(value); } 140 inline MultiType(const int& value) : value_(0), type_(MT_null) { this->assignValue(value); } 141 inline MultiType(const unsigned int& value) : value_(0), type_(MT_null) { this->assignValue(value); } 142 inline MultiType(const long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 143 inline MultiType(const unsigned long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 144 inline MultiType(const long long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 145 inline MultiType(const unsigned long long& value) : value_(0), type_(MT_null) { this->assignValue(value); } 146 inline MultiType(const float& value) : value_(0), type_(MT_null) { this->assignValue(value); } 147 inline MultiType(const double& value) : value_(0), type_(MT_null) { this->assignValue(value); } 148 inline MultiType(const long double& value) : value_(0), type_(MT_null) { this->assignValue(value); } 149 inline MultiType(const bool& value) : value_(0), type_(MT_null) { this->assignValue(value); } 150 inline MultiType( void* const& value) : value_(0), type_(MT_null) { this->assignValue(value); } 151 inline MultiType(const std::string& value) : value_(0), type_(MT_null) { this->assignValue(value); } 152 inline MultiType(const orxonox::Vector2& value) : value_(0), type_(MT_null) { this->assignValue(value); } 153 inline MultiType(const orxonox::Vector3& value) : value_(0), type_(MT_null) { this->assignValue(value); } 154 inline MultiType(const orxonox::Vector4& value) : value_(0), type_(MT_null) { this->assignValue(value); } 155 inline MultiType(const orxonox::ColourValue& value) : value_(0), type_(MT_null) { this->assignValue(value); } 156 inline MultiType(const orxonox::Quaternion& value) : value_(0), type_(MT_null) { this->assignValue(value); } 157 inline MultiType(const orxonox::Radian& value) : value_(0), type_(MT_null) { this->assignValue(value); } 158 inline MultiType(const orxonox::Degree& value) : value_(0), type_(MT_null) { this->assignValue(value); } 159 inline MultiType(const MultiType& other) : value_(0), type_(MT_null) { this->setValue(other); } 160 inline MultiType(MT_Type type) : value_(0), type_(MT_null) { this->setType(type); } 161 ~MultiType() { if (this->value_) { delete this->value_; } } 162 163 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 164 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 165 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 140 inline MultiType() : value_(0) {} 141 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } 142 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } 143 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } 144 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } 145 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } 146 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } 147 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } 148 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } 149 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } 150 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } 151 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } 152 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } 153 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } 154 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } 155 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } 156 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } 157 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } 158 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } 159 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } 160 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } 161 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } 162 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } 163 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } 164 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } 165 inline MultiType(MT_Type type) : value_(0) { this->setType(type); } 166 167 inline ~MultiType() { if (this->value_) { delete this->value_; } } 168 169 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } 170 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } 171 inline MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } 166 172 167 173 inline void setValue(const char& value); … … 188 194 inline void setValue(const orxonox::Radian& value); 189 195 inline void setValue(const orxonox::Degree& value); 190 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } } 196 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else { this->assignValue((void*)value); } } 197 inline void setValue(const MultiType& other) { this->value_ = (other.value_) ? other.value_->clone() : 0; } 198 template <typename T, typename V> inline void setValue(const V& value) { this->assignValue((T)value); } 191 199 inline void setValue(const char* value); 192 inline void setValue(const MultiType& other) { this->type_ = other.type_; this->value_ = (other.value_) ? other.value_->clone() : 0; }193 template <typename T, typename V> inline void setValue(const V& value) { this->assignValue((T)value); }194 200 195 201 template <typename T> inline void convert() { this->setValue<T>((T)(*this)); } 196 202 197 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } this->type_ = MT_null;}198 199 template <typename T> inline void setType() { this->assignValue(T()); }200 inline void setType(const MultiType& other) { this->setType(other. type_); }203 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; } } 204 205 template <typename T> inline void setType() { this->assignValue(T()); } 206 inline void setType(const MultiType& other) { this->setType(other.getType()); } 201 207 void setType(MT_Type type); 202 208 … … 250 256 inline void getValue(orxonox::Degree* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree(); } } 251 257 252 inline MT_Type getType() const { return this->type_; }253 inline bool isType(MT_Type type) const { return (this-> type_ == type); }258 inline MT_Type getType() const { return (this->value_) ? this->value_->type_ : MT_null; } 259 inline bool isType(MT_Type type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_null); } 254 260 template <typename T> inline bool isType() const { return false; } 255 261 std::string getTypename() const; … … 258 264 259 265 private: 260 inline void assignValue(const char& value) { if (this->value_ && this-> type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value); this->type_ = MT_char;} }261 inline void assignValue(const unsigned char& value) { if (this->value_ && this-> type_ == MT_uchar) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); this->type_ = MT_uchar;} }262 inline void assignValue(const short& value) { if (this->value_ && this-> type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value); this->type_ = MT_short;} }263 inline void assignValue(const unsigned short& value) { if (this->value_ && this-> type_ == MT_ushort) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); this->type_ = MT_ushort;} }264 inline void assignValue(const int& value) { if (this->value_ && this-> type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value); this->type_ = MT_int;} }265 inline void assignValue(const unsigned int& value) { if (this->value_ && this-> type_ == MT_uint) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); this->type_ = MT_uint;} }266 inline void assignValue(const long& value) { if (this->value_ && this-> type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value); this->type_ = MT_long;} }267 inline void assignValue(const unsigned long& value) { if (this->value_ && this-> type_ == MT_ulong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); this->type_ = MT_ulong;} }268 inline void assignValue(const long long& value) { if (this->value_ && this-> type_ == MT_longlong) { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); this->type_ = MT_longlong;} }269 inline void assignValue(const unsigned long long& value) { if (this->value_ && this-> type_ == MT_ulonglong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); this->type_ = MT_ulonglong; } }270 inline void assignValue(const float& value) { if (this->value_ && this-> type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value); this->type_ = MT_float;} }271 inline void assignValue(const double& value) { if (this->value_ && this-> type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value); this->type_ = MT_double;} }272 inline void assignValue(const long double& value) { if (this->value_ && this-> type_ == MT_longdouble) { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); this->type_ = MT_longdouble;} }273 inline void assignValue(const bool& value) { if (this->value_ && this-> type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); this->type_ = MT_bool;} }274 inline void assignValue( void* const& value) { if (this->value_ && this-> type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); this->type_ = MT_void;} }275 inline void assignValue(const std::string& value) { if (this->value_ && this-> type_ == MT_string) { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); this->type_ = MT_string;} }276 inline void assignValue(const orxonox::Vector2& value) { if (this->value_ && this-> type_ == MT_vector2) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); this->type_ = MT_vector2; } }277 inline void assignValue(const orxonox::Vector3& value) { if (this->value_ && this-> type_ == MT_vector3) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); this->type_ = MT_vector3; } }278 inline void assignValue(const orxonox::Vector4& value) { if (this->value_ && this-> type_ == MT_vector4) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); this->type_ = MT_vector4; } }279 inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this-> type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); this->type_ = MT_colourvalue; } }280 inline void assignValue(const orxonox::Quaternion& value) { if (this->value_ && this-> type_ == MT_quaternion) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); this->type_ = MT_quaternion; } }281 inline void assignValue(const orxonox::Radian& value) { if (this->value_ && this-> type_ == MT_radian) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); this->type_ = MT_radian; } }282 inline void assignValue(const orxonox::Degree& value) { if (this->value_ && this-> type_ == MT_degree) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); this->type_ = MT_degree; } }266 inline void assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value); } } 267 inline void assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_uchar) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); } } 268 inline void assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value); } } 269 inline void assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_ushort) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); } } 270 inline void assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value); } } 271 inline void assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_uint) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); } } 272 inline void assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value); } } 273 inline void assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_ulong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); } } 274 inline void assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_longlong) { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); } } 275 inline void assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_ulonglong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); } } 276 inline void assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value); } } 277 inline void assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value); } } 278 inline void assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_longdouble) { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); } } 279 inline void assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); } } 280 inline void assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); } } 281 inline void assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_string) { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); } } 282 inline void assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_vector2) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); } } 283 inline void assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_vector3) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); } } 284 inline void assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_vector4) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); } } 285 inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); } } 286 inline void assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_quaternion) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); } } 287 inline void assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_radian) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); } } 288 inline void assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_degree) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); } } 283 289 284 290 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } … … 286 292 287 293 MT_ValueBase* value_; 288 MT_Type type_;289 294 }; 290 295 291 296 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 292 297 293 template <> inline bool MultiType::isType<char>() const { return (this-> type_ == MT_char); }294 template <> inline bool MultiType::isType<unsigned char>() const { return (this-> type_ == MT_uchar); }295 template <> inline bool MultiType::isType<short>() const { return (this-> type_ == MT_short); }296 template <> inline bool MultiType::isType<unsigned short>() const { return (this-> type_ == MT_ushort); }297 template <> inline bool MultiType::isType<int>() const { return (this-> type_ == MT_int); }298 template <> inline bool MultiType::isType<unsigned int>() const { return (this-> type_ == MT_uint); }299 template <> inline bool MultiType::isType<long>() const { return (this-> type_ == MT_long); }300 template <> inline bool MultiType::isType<unsigned long>() const { return (this-> type_ == MT_ulong); }301 template <> inline bool MultiType::isType<long long>() const { return (this-> type_ == MT_longlong); }302 template <> inline bool MultiType::isType<unsigned long long>() const { return (this-> type_ == MT_ulonglong); }303 template <> inline bool MultiType::isType<float>() const { return (this-> type_ == MT_float); }304 template <> inline bool MultiType::isType<double>() const { return (this-> type_ == MT_double); }305 template <> inline bool MultiType::isType<long double>() const { return (this-> type_ == MT_longdouble); }306 template <> inline bool MultiType::isType<bool>() const { return (this-> type_ == MT_bool); }307 template <> inline bool MultiType::isType<void*>() const { return (this-> type_ == MT_void); }308 template <> inline bool MultiType::isType<std::string>() const { return (this-> type_ == MT_string); }309 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this-> type_ == MT_vector2); }310 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this-> type_ == MT_vector3); }311 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this-> type_ == MT_vector4); }312 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this-> type_ == MT_colourvalue); }313 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this-> type_ == MT_quaternion); }314 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this-> type_ == MT_radian); }315 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this-> type_ == MT_degree); }298 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_char); } 299 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_uchar); } 300 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_short); } 301 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_ushort); } 302 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_int); } 303 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_uint); } 304 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_long); } 305 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_ulong); } 306 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_longlong); } 307 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_ulonglong); } 308 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_float); } 309 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_double); } 310 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_longdouble); } 311 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_bool); } 312 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_void); } 313 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_string); } 314 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_vector2); } 315 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_vector3); } 316 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_vector4); } 317 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_colourvalue); } 318 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_quaternion); } 319 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_radian); } 320 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_degree); } 316 321 317 322 template <> inline void MultiType::convert<std::string>() { this->setValue<std::string> (this->operator std::string()); } … … 379 384 inline void MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 380 385 inline void MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { this->value_->setValue(value); } else { this->assignValue(value); } } 381 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } } 386 387 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else { this->assignValue(std::string(value)); } } 382 388 383 389
Note: See TracChangeset
for help on using the changeset viewer.