Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9223


Ignore:
Timestamp:
May 19, 2012, 11:35:32 AM (12 years ago)
Author:
landauf
Message:

renamed setType<T>() to reset<T>()

Location:
code/branches/testing
Files:
2 edited

Legend:

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

    r9222 r9223  
    5858    If you want to change the type, there are three possibilities:
    5959     - @ref orxonox::MultiType::convert "convert<T>()" sets the type to T and converts the currently assigned value
    60      - @ref orxonox::MultiType::setType "setType<T>()" sets the type to T and resets the value to zero using zeroise<T>()
     60     - @ref orxonox::MultiType::reset "reset<T>()" sets the type to T and resets the value to zero using zeroise<T>()
    6161     - setValue<T>(value) assigns a new value and changes the type to T.
    6262
     
    339339                    return this->assignValue     (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value)));
    340340            }
     341            /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted).
     342            template <typename T, typename V> inline bool setValue(const V& value) { this->reset<T>(); return this->setValue(value); }
    341343            /// Assigns the value of the other MultiType and converts it to the current type.
    342344            bool                                          setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } }
    343             /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted).
    344             template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); }
    345 
    346345
    347346            /// Copies the other MultiType by assigning value and type.
     
    353352            /// Resets value and type. Type will be void afterwards and null() returns true.
    354353            inline void                       reset()                      { if (this->value_) delete this->value_; this->value_ = 0; }
    355             /// Current content gets overridden with default zero value
     354            /// Resets the value and changes the internal type to T.
     355            template <typename T> inline void reset()                      { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); }
     356            /// Current value gets overridden with default zero value
    356357            inline void                       resetValue()                 { if (this->value_) this->value_->reset(); }
    357 
    358             /// Resets the value and changes the internal type to T.
    359             template <typename T> inline void setType()                    { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); }
    360358
    361359            /// Returns true if the current type is T.
     
    377375
    378376            /// Checks if the MT contains no value.
    379             bool                              null() const { return (!this->value_); }
     377            bool                              null() const { return !this->value_; }
    380378
    381379            operator char()                  const;
     
    497495    _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; }
    498496
    499     template <> inline bool MultiType::isType<void>()                 const { return this->null();                                                       } ///< Returns true if the current type equals the given type.
     497    template <> inline bool MultiType::isType<void>()                 const { return this->null();                                                    } ///< Returns true if the current type equals the given type.
    500498    template <> inline bool MultiType::isType<char>()                 const { return (this->value_ && this->value_->type_ == Type::Char);             } ///< Returns true if the current type equals the given type.
    501499    template <> inline bool MultiType::isType<unsigned char>()        const { return (this->value_ && this->value_->type_ == Type::UnsignedChar);     } ///< Returns true if the current type equals the given type.
  • code/branches/testing/test/util/MultiTypeTest.cc

    r9221 r9223  
    1818    // x convert<type>()
    1919    // x reset
     20    // x reset<type>()
    2021    // x resetValue
    21     // x setType<type>()
    2222
    2323    // x isType<type>()
     
    310310    }
    311311
     312    ///////////////////
     313    // reset<type>() //
     314    ///////////////////
     315    TEST(MultiType, SetType)
     316    {
     317        MultiType mt(10);
     318
     319        EXPECT_TRUE(mt.isType<int>());
     320        EXPECT_FALSE(mt.isType<float>());
     321        EXPECT_EQ(10, mt.getInt());
     322
     323        mt.reset<float>();
     324
     325        EXPECT_FALSE(mt.isType<int>());
     326        EXPECT_TRUE(mt.isType<float>());
     327        EXPECT_EQ(0, mt.getInt());
     328    }
     329
    312330    ////////////////
    313331    // resetValue //
     
    323341
    324342        EXPECT_TRUE(mt.isType<int>());
    325         EXPECT_EQ(0, mt.getInt());
    326     }
    327 
    328     /////////////////////
    329     // setType<type>() //
    330     /////////////////////
    331     TEST(MultiType, SetType)
    332     {
    333         MultiType mt(10);
    334 
    335         EXPECT_TRUE(mt.isType<int>());
    336         EXPECT_FALSE(mt.isType<float>());
    337         EXPECT_EQ(10, mt.getInt());
    338 
    339         mt.setType<float>();
    340 
    341         EXPECT_FALSE(mt.isType<int>());
    342         EXPECT_TRUE(mt.isType<float>());
    343343        EXPECT_EQ(0, mt.getInt());
    344344    }
Note: See TracChangeset for help on using the changeset viewer.