[Orxonox-commit 6344] r11001 - code/branches/cpp11_v2/src/libraries/util

landauf at orxonox.net landauf at orxonox.net
Wed Dec 30 20:53:54 CET 2015


Author: landauf
Date: 2015-12-30 20:53:54 +0100 (Wed, 30 Dec 2015)
New Revision: 11001

Modified:
   code/branches/cpp11_v2/src/libraries/util/MultiType.h
Log:
removed spezializations for MultiType::get<>(), using type-traits instead.

Modified: code/branches/cpp11_v2/src/libraries/util/MultiType.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/MultiType.h	2015-12-30 14:17:35 UTC (rev 11000)
+++ code/branches/cpp11_v2/src/libraries/util/MultiType.h	2015-12-30 19:53:54 UTC (rev 11001)
@@ -353,9 +353,12 @@
             /// Assigns the value to the given pointer. The value gets converted if the types don't match.
             template <typename T> inline bool getValue(T* value) const { if (this->value_) { return this->value_->getValue(value); } return false; }
 
-            /// Returns the current value, converted to the requested type. This base implementation works only for pointers. All other supported types are
-            /// implemented in  specialized functions at the bottom of this file.
-            template <typename T> inline T get() const { return static_cast<T>(this->get<void*>()); }
+            /// Returns the current value, converted to the requested type.
+            template <typename T> /* for normal types */ typename std::enable_if<!std::is_pointer<T>::value, T>::type
+            inline /*T*/ get() const { return (this->value_ ? this->value_->get<T>() : NilValue<T>()); }
+            /// Returns the current value, converted to a pointer of the requested type.
+            template <typename T> /* for pointers */ typename std::enable_if<std::is_pointer<T>::value, T>::type
+            inline /*T*/ get() const { return this->value_ ? static_cast<T>(this->value_->get<void*>()) : nullptr; }
 
 
             ///////////////////////////////
@@ -475,30 +478,6 @@
     template <> inline bool MultiType::isType<void>() const { return this->null(); }
     template <> inline bool MultiType::convert<void>() { this->reset(); return true; }
 
-    template <> inline char                 MultiType::get() const { return (this->value_ ? this->value_->get<char>()                 : 0); }
-    template <> inline unsigned char        MultiType::get() const { return (this->value_ ? this->value_->get<unsigned char>()        : 0); }
-    template <> inline short                MultiType::get() const { return (this->value_ ? this->value_->get<short>()                : 0); }
-    template <> inline unsigned short       MultiType::get() const { return (this->value_ ? this->value_->get<unsigned short>()       : 0); }
-    template <> inline int                  MultiType::get() const { return (this->value_ ? this->value_->get<int>()                  : 0); }
-    template <> inline unsigned int         MultiType::get() const { return (this->value_ ? this->value_->get<unsigned int>()         : 0); }
-    template <> inline long                 MultiType::get() const { return (this->value_ ? this->value_->get<long>()                 : 0); }
-    template <> inline unsigned long        MultiType::get() const { return (this->value_ ? this->value_->get<unsigned long>()        : 0); }
-    template <> inline long long            MultiType::get() const { return (this->value_ ? this->value_->get<long long>()            : 0); }
-    template <> inline unsigned long long   MultiType::get() const { return (this->value_ ? this->value_->get<unsigned long long>()   : 0); }
-    template <> inline float                MultiType::get() const { return (this->value_ ? this->value_->get<float>()                : 0); }
-    template <> inline double               MultiType::get() const { return (this->value_ ? this->value_->get<double>()               : 0); }
-    template <> inline long double          MultiType::get() const { return (this->value_ ? this->value_->get<long double>()          : 0); }
-    template <> inline bool                 MultiType::get() const { return (this->value_ ? this->value_->get<bool>()                 : 0); }
-    template <> inline void*                MultiType::get() const { return (this->value_ ? this->value_->get<void*>()                : nullptr); }
-    template <> inline std::string          MultiType::get() const { return (this->value_ ? this->value_->get<std::string>()          : NilValue<std::string>()); }
-    template <> inline orxonox::Vector2     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector2>()     : NilValue<orxonox::Vector2>()); }
-    template <> inline orxonox::Vector3     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector3>()     : NilValue<orxonox::Vector3>()); }
-    template <> inline orxonox::Vector4     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector4>()     : NilValue<orxonox::Vector4>()); }
-    template <> inline orxonox::ColourValue MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::ColourValue>() : NilValue<orxonox::ColourValue>()); }
-    template <> inline orxonox::Quaternion  MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Quaternion>()  : NilValue<orxonox::Quaternion>()); }
-    template <> inline orxonox::Radian      MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Radian>()      : NilValue<orxonox::Radian>()); }
-    template <> inline orxonox::Degree      MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Degree>()      : NilValue<orxonox::Degree>()); }
-
     template <> _UtilExport void MultiType::createNewValueContainer(const char& value);
     template <> _UtilExport void MultiType::createNewValueContainer(const unsigned char& value);
     template <> _UtilExport void MultiType::createNewValueContainer(const short& value);




More information about the Orxonox-commit mailing list