Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3332 for code/trunk/src/util


Ignore:
Timestamp:
Jul 21, 2009, 12:54:15 PM (15 years ago)
Author:
rgrieder
Message:

Added TypeTraits.h from the Loki library (stripped it a bit though). This should make things a bit less error prone since Andrei Alexandrescu really is the master of templates ;)

Location:
code/trunk/src/util
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/util/MultiType.h

    r3301 r3332  
    7777#include <OgreColourValue.h>
    7878
    79 #include "TemplateUtils.h"
     79#include "TypeTraits.h"
    8080
    8181namespace orxonox
     
    303303            inline bool                                   setValue(const char* value);
    304304            /** @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            }
    306312            /** @brief Assigns the value of the other MultiType and converts it to the current type. */
    307313            bool                                          setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } }
     
    322328            inline void                       resetValue()                    { if (this->value_) this->value_->reset(); }
    323329
    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. */
    327333
    328334            /** @brief Returns the current type. */
  • code/trunk/src/util/TemplateUtils.h

    r3233 r3332  
    3939namespace orxonox
    4040{
    41     /**
    42     @brief
    43         Use TypeStripper to get rid of the const and the reference of type T
    44     @note
    45         Main use of this is when trying to instantiate type T as T().
    46     */
    47     template <class T> struct TypeStripper
    48         { 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 
    5541    ///////////////////////////////////////////////////
    5642    // Static detection of implicit type conversions //
Note: See TracChangeset for help on using the changeset viewer.