31 #ifndef __MYGUI_ANY_H__
32 #define __MYGUI_ANY_H__
95 template<
typename ValueType>
Any(
const ValueType& value) :
96 mContent(new Holder<ValueType>(value))
100 Any(
const Any::AnyEmpty& value) :
106 mContent(other.mContent ? other.mContent->clone() :
nullptr)
117 std::swap(mContent, rhs.mContent);
121 template<
typename ValueType>
Any& operator = (
const ValueType& rhs)
127 Any& operator = (
const Any::AnyEmpty& rhs)
145 const std::type_info& getType()
const
147 return mContent ? mContent->
getType() :
typeid(void);
150 template<
typename ValueType>
151 ValueType * castType(
bool _throw =
true)
const
153 if (this->getType() ==
typeid(ValueType))
155 return &
static_cast<Any::Holder<ValueType> *
>(this->mContent)->held;
157 MYGUI_ASSERT(!_throw,
"Bad cast from type '" << getType().name() <<
"' to '" <<
typeid(ValueType).name() <<
"'");
161 void * castUnsafe()
const
163 return mContent ?
static_cast<Any::Holder<void *> *
>(this->mContent)->held :
nullptr;
170 virtual ~Placeholder() { }
173 virtual const std::type_info& getType()
const = 0;
174 virtual Placeholder * clone()
const = 0;
178 template<
typename ValueType>
class Holder :
public Placeholder
181 Holder(
const ValueType& value) :
187 virtual const std::type_info& getType()
const
189 return typeid(ValueType);
192 virtual Placeholder * clone()
const
194 return new Holder(held);
201 Holder& operator=(
const Holder &);
207 Placeholder * mContent;
213 #endif // __MYGUI_ANY_H__