- Timestamp:
- Jul 21, 2009, 12:54:15 PM (15 years ago)
- Location:
- code/trunk/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/Identifier.h
r3325 r3332 62 62 63 63 #include "util/Debug.h" 64 #include "util/TypeTraits.h" 64 65 #include "MetaObjectList.h" 65 66 #include "ObjectList.h" … … 483 484 // ### orxonox_cast ### 484 485 // ############################### 485 //! Helper struct to have orxonox_cast<T*> instead of orxonox_cast<T>486 template <class T, class U>487 struct OrxonoxCaster488 {489 static T* cast(U* source)490 {491 // If you see this function in a compiler error description, it means492 // you were misusing orxonox_cast. You must always cast to a pointer type!493 *****T();494 }495 };496 497 //! Helper struct to have orxonox_cast<T*> instead of orxonox_cast<T*>498 template <class T, class U>499 struct OrxonoxCaster<T*, U>500 {501 FORCEINLINE static T* cast(U* source)502 {503 #ifdef ORXONOX_COMPILER_MSVC504 return source->template getDerivedPointer<T>(ClassIdentifier<T>::getIdentifier()->getClassID());505 #else506 return dynamic_cast<T*>(source);507 #endif508 }509 };510 511 486 /** 512 487 @brief … … 523 498 FORCEINLINE T orxonox_cast(U* source) 524 499 { 525 return OrxonoxCaster<T, U>::cast(source); 500 #ifdef ORXONOX_COMPILER_MSVC 501 typedef Loki::TypeTraits<T>::PointeeType ClassType; 502 return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID()); 503 #else 504 return dynamic_cast<T>(source); 505 #endif 526 506 } 527 507 -
code/trunk/src/network/synchronisable/SynchronisableVariable.h
r3304 r3332 36 36 #include <cstring> 37 37 #include "util/Serialise.h" 38 #include "util/T emplateUtils.h"38 #include "util/TypeTraits.h" 39 39 #include "core/GameMode.h" 40 40 #include "network/synchronisable/NetworkCallbackManager.h" … … 79 79 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 80 80 virtual inline uint32_t getSize(uint8_t mode); 81 virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->variable_)); }81 virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); } 82 82 protected: 83 83 … … 182 182 { 183 183 this->varReference_++; 184 memcpy(static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->varBuffer_)), &this->variable_, sizeof(this->variable_));184 memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(this->variable_)); 185 185 } 186 186 } … … 215 215 { 216 216 mem += sizeof(varReference_); 217 memcpy(static_cast<void*>(const_cast<typename TypeStripper<T>::RawType*>(&this->varBuffer_)), &this->variable_, sizeof(T));217 memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(T)); 218 218 if ( this->callback_ != 0 ) 219 219 callback = true; -
code/trunk/src/util/MultiType.h
r3301 r3332 77 77 #include <OgreColourValue.h> 78 78 79 #include "T emplateUtils.h"79 #include "TypeTraits.h" 80 80 81 81 namespace orxonox … … 303 303 inline bool setValue(const char* value); 304 304 /** @brief Assigns a pointer. */ 305 template <typename V> inline bool setValue(V* value) { if (this->value_) { return this->value_->setValue(static_cast<void*>(const_cast<typename TypeStripper<V>::RawType*>(value))); } else { return this->assignValue(static_cast<void*>(const_cast<typename TypeStripper<V>::RawType*>(value))); } } 305 template <typename V> inline bool setValue(V* value) 306 { 307 if (this->value_) 308 return this->value_->setValue(static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 309 else 310 return this->assignValue (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 311 } 306 312 /** @brief Assigns the value of the other MultiType and converts it to the current type. */ 307 313 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } … … 322 328 inline void resetValue() { if (this->value_) this->value_->reset(); } 323 329 324 template <typename T> inline void setType() { this->assignValue(typename TypeStripper<T>::RawType()); } /** @brief Resets the value and changes the internal type to T. */325 inline void setType(const MultiType& other) { this->setType(other.getType()); } /** @brief Resets the value and changes the internal type to the type of the other MultiType. */326 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */330 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } /** @brief Resets the value and changes the internal type to T. */ 331 inline void setType(const MultiType& other) { this->setType(other.getType()); } /** @brief Resets the value and changes the internal type to the type of the other MultiType. */ 332 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */ 327 333 328 334 /** @brief Returns the current type. */ -
code/trunk/src/util/TemplateUtils.h
r3233 r3332 39 39 namespace orxonox 40 40 { 41 /**42 @brief43 Use TypeStripper to get rid of the const and the reference of type T44 @note45 Main use of this is when trying to instantiate type T as T().46 */47 template <class T> struct TypeStripper48 { typedef T RawType; };49 template <class T> struct TypeStripper<const T>50 { typedef T RawType; };51 template <class T> struct TypeStripper<const T&>52 { typedef T RawType; };53 54 55 41 /////////////////////////////////////////////////// 56 42 // Static detection of implicit type conversions //
Note: See TracChangeset
for help on using the changeset viewer.