Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 20, 2012, 12:52:15 AM (13 years ago)
Author:
landauf
Message:

changed hasDefaultValue() to lastConversionSuccessful() (inverted meaning) and fixed two issues with this function

Location:
code/branches/testing/src/libraries/util
Files:
2 edited

Legend:

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

    r9225 r9226  
    174174        {
    175175        public:
    176             MT_ValueBase(void* data, Type::Enum type) : type_(type), bHasDefaultValue_(false), data_(data) {}
    177             virtual ~MT_ValueBase() {}
     176            inline MT_ValueBase(void* data, Type::Enum type) : type_(type), bLastConversionSuccessful(true), data_(data) {}
     177            inline virtual ~MT_ValueBase() {}
    178178
    179179            virtual MT_ValueBase* clone() const = 0;
     
    182182
    183183            /// Returns the type of the current value.
    184             const Type::Enum& getType() const { return this->type_; }
     184            inline const Type::Enum& getType() const { return this->type_; }
    185185            /// Returns true if the type of the stored value is T.
    186186            template <typename T> inline bool isType() const { return false; }
    187187
    188188            /// Checks whether the value is a default one.
    189             bool hasDefaultValue()   const { return this->bHasDefaultValue_; }
     189            inline bool lastConversionSuccessful()   const { return this->bLastConversionSuccessful; }
    190190
    191191            virtual bool setValue(const char& value)                 = 0;
     
    253253            virtual void toString(std::ostream& outstream) const = 0;
    254254
    255             virtual void importData( uint8_t*& mem )=0;
    256             virtual void exportData( uint8_t*& mem ) const=0;
    257             virtual uint8_t getSize() const=0;
    258 
    259             Type::Enum type_;       ///< The type of the current value
    260             bool bHasDefaultValue_; ///< True if the last conversion wasn't successful
    261             void* data_;            ///< For direct access to the value if the type is known
     255            virtual void importData(uint8_t*& mem) = 0;
     256            virtual void exportData(uint8_t*& mem) const = 0;
     257            virtual uint8_t getSize() const = 0;
     258
     259            Type::Enum type_;               ///< The type of the current value
     260            bool bLastConversionSuccessful; ///< True if the last conversion was successful
     261            void* data_;                    ///< For direct access to the value if the type is known
    262262        };
    263263
     
    329329
    330330            /// Converts the current value to type T.
    331             template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); }
     331            template <typename T> inline bool convert() { return this->force<T>(MultiType(*this)); }
     332//            template <typename T> inline bool convert() { return this->force<T>(this->get<typename Loki::TypeTraits<T>::UnqualifiedReferredType>()); }
    332333
    333334            /// Resets value and type. Type will be void afterwards and null() returns true.
     
    342343            std::string getTypename() const;
    343344
    344             /// Checks whether the value is a default one (assigned after a failed conversion)
    345             inline bool hasDefaultValue() const { return this->value_->hasDefaultValue(); }
     345            /// Checks whether the last conversion was successful
     346            inline bool lastConversionSuccessful() const { return !this->value_ || this->value_->lastConversionSuccessful(); }
    346347
    347348            /// Checks if the MT contains no value.
  • code/branches/testing/src/libraries/util/MultiTypeValue.h

    r9225 r9226  
    6161
    6262        /// Resets the current value to the default.
    63         inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; }
     63        inline void reset() { this->value_ = zeroise<T>(); bLastConversionSuccessful = true; }
    6464
    6565        inline bool getValue(char*                 value) const { return convertValue<T, char                >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match.
     
    9595            if (other.value_)
    9696            {
    97                 return !(bHasDefaultValue_ = !other.value_->getValue(&value_));
     97                return (this->bLastConversionSuccessful = other.value_->getValue(&value_));
    9898            }
    9999            else
    100100            {
    101101                this->value_ = zeroise<T>();
    102                 return !(bHasDefaultValue_ = true);
     102                return (bLastConversionSuccessful = false);
    103103            }
    104104        }
    105105
    106         inline bool setValue(const char& value)                 { return !(bHasDefaultValue_ = !convertValue<char                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    107         inline bool setValue(const unsigned char& value)        { return !(bHasDefaultValue_ = !convertValue<unsigned char       , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    108         inline bool setValue(const short& value)                { return !(bHasDefaultValue_ = !convertValue<short               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    109         inline bool setValue(const unsigned short& value)       { return !(bHasDefaultValue_ = !convertValue<unsigned short      , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    110         inline bool setValue(const int& value)                  { return !(bHasDefaultValue_ = !convertValue<int                 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    111         inline bool setValue(const unsigned int& value)         { return !(bHasDefaultValue_ = !convertValue<unsigned int        , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    112         inline bool setValue(const long& value)                 { return !(bHasDefaultValue_ = !convertValue<long                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    113         inline bool setValue(const unsigned long& value)        { return !(bHasDefaultValue_ = !convertValue<unsigned long       , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    114         inline bool setValue(const long long& value)            { return !(bHasDefaultValue_ = !convertValue<long long           , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    115         inline bool setValue(const unsigned long long& value)   { return !(bHasDefaultValue_ = !convertValue<unsigned long long  , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    116         inline bool setValue(const float& value)                { return !(bHasDefaultValue_ = !convertValue<float               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    117         inline bool setValue(const double& value)               { return !(bHasDefaultValue_ = !convertValue<double              , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    118         inline bool setValue(const long double& value)          { return !(bHasDefaultValue_ = !convertValue<long double         , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    119         inline bool setValue(const bool& value)                 { return !(bHasDefaultValue_ = !convertValue<bool                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    120         inline bool setValue(      void* const& value)          { return !(bHasDefaultValue_ = !convertValue<void*               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    121         inline bool setValue(const std::string& value)          { return !(bHasDefaultValue_ = !convertValue<std::string         , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    122         inline bool setValue(const orxonox::Vector2& value)     { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    123         inline bool setValue(const orxonox::Vector3& value)     { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    124         inline bool setValue(const orxonox::Vector4& value)     { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    125         inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    126         inline bool setValue(const orxonox::Quaternion& value)  { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    127         inline bool setValue(const orxonox::Radian& value)      { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian     , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    128         inline bool setValue(const orxonox::Degree& value)      { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree     , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     106        inline bool setValue(const char& value)                 { return (bLastConversionSuccessful = convertValue<char                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     107        inline bool setValue(const unsigned char& value)        { return (bLastConversionSuccessful = convertValue<unsigned char       , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     108        inline bool setValue(const short& value)                { return (bLastConversionSuccessful = convertValue<short               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     109        inline bool setValue(const unsigned short& value)       { return (bLastConversionSuccessful = convertValue<unsigned short      , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     110        inline bool setValue(const int& value)                  { return (bLastConversionSuccessful = convertValue<int                 , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     111        inline bool setValue(const unsigned int& value)         { return (bLastConversionSuccessful = convertValue<unsigned int        , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     112        inline bool setValue(const long& value)                 { return (bLastConversionSuccessful = convertValue<long                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     113        inline bool setValue(const unsigned long& value)        { return (bLastConversionSuccessful = convertValue<unsigned long       , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     114        inline bool setValue(const long long& value)            { return (bLastConversionSuccessful = convertValue<long long           , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     115        inline bool setValue(const unsigned long long& value)   { return (bLastConversionSuccessful = convertValue<unsigned long long  , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     116        inline bool setValue(const float& value)                { return (bLastConversionSuccessful = convertValue<float               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     117        inline bool setValue(const double& value)               { return (bLastConversionSuccessful = convertValue<double              , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     118        inline bool setValue(const long double& value)          { return (bLastConversionSuccessful = convertValue<long double         , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     119        inline bool setValue(const bool& value)                 { return (bLastConversionSuccessful = convertValue<bool                , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     120        inline bool setValue(      void* const& value)          { return (bLastConversionSuccessful = convertValue<void*               , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     121        inline bool setValue(const std::string& value)          { return (bLastConversionSuccessful = convertValue<std::string         , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     122        inline bool setValue(const orxonox::Vector2& value)     { return (bLastConversionSuccessful = convertValue<orxonox::Vector2    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     123        inline bool setValue(const orxonox::Vector3& value)     { return (bLastConversionSuccessful = convertValue<orxonox::Vector3    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     124        inline bool setValue(const orxonox::Vector4& value)     { return (bLastConversionSuccessful = convertValue<orxonox::Vector4    , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     125        inline bool setValue(const orxonox::ColourValue& value) { return (bLastConversionSuccessful = convertValue<orxonox::ColourValue, T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     126        inline bool setValue(const orxonox::Quaternion& value)  { return (bLastConversionSuccessful = convertValue<orxonox::Quaternion , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     127        inline bool setValue(const orxonox::Radian& value)      { return (bLastConversionSuccessful = convertValue<orxonox::Radian     , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
     128        inline bool setValue(const orxonox::Degree& value)      { return (bLastConversionSuccessful = convertValue<orxonox::Degree     , T>(&value_, value, NilValue<T>())); } ///< Assigns the value by converting it to T.
    129129
    130130        /// Puts the current value on the stream
Note: See TracChangeset for help on using the changeset viewer.