Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10197


Ignore:
Timestamp:
Jan 17, 2015, 6:43:35 PM (9 years ago)
Author:
landauf
Message:

avoid implicit conversion in MultiType.get<T>()

Location:
code/trunk
Files:
3 edited

Legend:

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

    r9550 r10197  
    348348            inline bool null() const { return !this->value_; }
    349349
    350             inline operator char()                 const { return (this->value_ ? this->value_->get<char>()                 : 0); }
    351             inline operator unsigned char()        const { return (this->value_ ? this->value_->get<unsigned char>()        : 0); }
    352             inline operator short()                const { return (this->value_ ? this->value_->get<short>()                : 0); }
    353             inline operator unsigned short()       const { return (this->value_ ? this->value_->get<unsigned short>()       : 0); }
    354             inline operator int()                  const { return (this->value_ ? this->value_->get<int>()                  : 0); }
    355             inline operator unsigned int()         const { return (this->value_ ? this->value_->get<unsigned int>()         : 0); }
    356             inline operator long()                 const { return (this->value_ ? this->value_->get<long>()                 : 0); }
    357             inline operator unsigned long()        const { return (this->value_ ? this->value_->get<unsigned long>()        : 0); }
    358             inline operator long long()            const { return (this->value_ ? this->value_->get<long long>()            : 0); }
    359             inline operator unsigned long long()   const { return (this->value_ ? this->value_->get<unsigned long long>()   : 0); }
    360             inline operator float()                const { return (this->value_ ? this->value_->get<float>()                : 0); }
    361             inline operator double()               const { return (this->value_ ? this->value_->get<double>()               : 0); }
    362             inline operator long double()          const { return (this->value_ ? this->value_->get<long double>()          : 0); }
    363             inline operator bool()                 const { return (this->value_ ? this->value_->get<bool>()                 : 0); }
    364             inline operator void*()                const { return (this->value_ ? this->value_->get<void*>()                : 0); }
    365             inline operator std::string()          const { return (this->value_ ? this->value_->get<std::string>()          : NilValue<std::string>()); }
    366             inline operator orxonox::Vector2()     const { return (this->value_ ? this->value_->get<orxonox::Vector2>()     : NilValue<orxonox::Vector2>()); }
    367             inline operator orxonox::Vector3()     const { return (this->value_ ? this->value_->get<orxonox::Vector3>()     : NilValue<orxonox::Vector3>()); }
    368             inline operator orxonox::Vector4()     const { return (this->value_ ? this->value_->get<orxonox::Vector4>()     : NilValue<orxonox::Vector4>()); }
    369             inline operator orxonox::ColourValue() const { return (this->value_ ? this->value_->get<orxonox::ColourValue>() : NilValue<orxonox::ColourValue>()); }
    370             inline operator orxonox::Quaternion()  const { return (this->value_ ? this->value_->get<orxonox::Quaternion>()  : NilValue<orxonox::Quaternion>()); }
    371             inline operator orxonox::Radian()      const { return (this->value_ ? this->value_->get<orxonox::Radian>()      : NilValue<orxonox::Radian>()); }
    372             inline operator orxonox::Degree()      const { return (this->value_ ? this->value_->get<orxonox::Degree>()      : NilValue<orxonox::Degree>()); }
    373             /// Returns the current value, converted to a T* pointer.
    374             template <class T> operator T*() const { return (static_cast<T*>(this->operator void*())); }
     350            /// Conversion operator for all types
     351            template <class T> operator T()  const { return this->get<T>(); }
    375352
    376353            /// Assigns the value to the given pointer. The value gets converted if the types don't match.
    377354            template <typename T> inline bool getValue(T* value) const { if (this->value_) { return this->value_->getValue(value); } return false; }
    378355
    379             /// Returns the current value, converted to the requested type.
    380             template <typename T> inline T get() const { return *this; }
     356            /// Returns the current value, converted to the requested type. This base implementation works only for pointers. All other supported types are
     357            /// implemented in  specialized functions at the bottom of this file.
     358            template <typename T> inline T get() const { return static_cast<T>(this->get<void*>()); }
    381359
    382360
     
    493471    template <> inline bool MultiType::isType<void>() const { return this->null(); }
    494472    template <> inline bool MultiType::convert<void>() { this->reset(); return true; }
     473
     474    template <> inline char                 MultiType::get() const { return (this->value_ ? this->value_->get<char>()                 : 0); }
     475    template <> inline unsigned char        MultiType::get() const { return (this->value_ ? this->value_->get<unsigned char>()        : 0); }
     476    template <> inline short                MultiType::get() const { return (this->value_ ? this->value_->get<short>()                : 0); }
     477    template <> inline unsigned short       MultiType::get() const { return (this->value_ ? this->value_->get<unsigned short>()       : 0); }
     478    template <> inline int                  MultiType::get() const { return (this->value_ ? this->value_->get<int>()                  : 0); }
     479    template <> inline unsigned int         MultiType::get() const { return (this->value_ ? this->value_->get<unsigned int>()         : 0); }
     480    template <> inline long                 MultiType::get() const { return (this->value_ ? this->value_->get<long>()                 : 0); }
     481    template <> inline unsigned long        MultiType::get() const { return (this->value_ ? this->value_->get<unsigned long>()        : 0); }
     482    template <> inline long long            MultiType::get() const { return (this->value_ ? this->value_->get<long long>()            : 0); }
     483    template <> inline unsigned long long   MultiType::get() const { return (this->value_ ? this->value_->get<unsigned long long>()   : 0); }
     484    template <> inline float                MultiType::get() const { return (this->value_ ? this->value_->get<float>()                : 0); }
     485    template <> inline double               MultiType::get() const { return (this->value_ ? this->value_->get<double>()               : 0); }
     486    template <> inline long double          MultiType::get() const { return (this->value_ ? this->value_->get<long double>()          : 0); }
     487    template <> inline bool                 MultiType::get() const { return (this->value_ ? this->value_->get<bool>()                 : 0); }
     488    template <> inline void*                MultiType::get() const { return (this->value_ ? this->value_->get<void*>()                : 0); }
     489    template <> inline std::string          MultiType::get() const { return (this->value_ ? this->value_->get<std::string>()          : NilValue<std::string>()); }
     490    template <> inline orxonox::Vector2     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector2>()     : NilValue<orxonox::Vector2>()); }
     491    template <> inline orxonox::Vector3     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector3>()     : NilValue<orxonox::Vector3>()); }
     492    template <> inline orxonox::Vector4     MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Vector4>()     : NilValue<orxonox::Vector4>()); }
     493    template <> inline orxonox::ColourValue MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::ColourValue>() : NilValue<orxonox::ColourValue>()); }
     494    template <> inline orxonox::Quaternion  MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Quaternion>()  : NilValue<orxonox::Quaternion>()); }
     495    template <> inline orxonox::Radian      MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Radian>()      : NilValue<orxonox::Radian>()); }
     496    template <> inline orxonox::Degree      MultiType::get() const { return (this->value_ ? this->value_->get<orxonox::Degree>()      : NilValue<orxonox::Degree>()); }
    495497
    496498    template <> _UtilExport void MultiType::createNewValueContainer(const char& value);
  • code/trunk/src/orxonox/gamestates/GSServer.cc

    r9667 r10197  
    5858        GameMode::setIsServer(true);
    5959
    60         this->server_ = new Server(CommandLineParser::getValue("port"));
     60        this->server_ = new Server(CommandLineParser::getValue("port").get<int>());
    6161        orxout(user_status) << "Loading scene in server mode" << endl;
    6262
  • code/trunk/test/util/MultiTypeTest.cc

    r9545 r10197  
    6060    TEST(MultiType, ValueBool)              { bool value = true;                                MultiType mt(value);    EXPECT_TRUE(mt.isType<bool>());                 EXPECT_EQ(true, mt.get<bool>()); }
    6161    TEST(MultiType, ValueVoidpointer)       { int* pointer = new int; void* value = pointer;    MultiType mt(value);    EXPECT_TRUE(mt.isType<void*>());                EXPECT_EQ(value, mt.get<void*>()); delete pointer; }
     62    TEST(MultiType, ValueSomepointer)       { int* value = new int;                             MultiType mt(value);    EXPECT_TRUE(mt.isType<void*>());                EXPECT_EQ(value, mt.get<int*>()); delete value; }
    6263    TEST(MultiType, ValueString)            { std::string value = "Hello World";                MultiType mt(value);    EXPECT_TRUE(mt.isType<std::string>());          EXPECT_EQ("Hello World", mt.get<std::string>()); }
    6364    TEST(MultiType, ValueVector2)           { Vector2 value = Vector2(11, 22);                  MultiType mt(value);    EXPECT_TRUE(mt.isType<Vector2>());              EXPECT_EQ(Vector2(11, 22), mt.get<Vector2>()); }
Note: See TracChangeset for help on using the changeset viewer.