mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
more optimization
This commit is contained in:
parent
81fcb5cbf5
commit
0fe95a31c4
@ -164,6 +164,12 @@ private:
|
|||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
friend ValueType* UnsafeAnyCast(Any*);
|
friend ValueType* UnsafeAnyCast(Any*);
|
||||||
|
|
||||||
|
template <typename ValueType>
|
||||||
|
friend ValueType& RefAnyCast(Any&);
|
||||||
|
|
||||||
|
template <typename ValueType>
|
||||||
|
friend const ValueType& RefAnyCast(const Any&);
|
||||||
|
|
||||||
Placeholder* _content;
|
Placeholder* _content;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -208,7 +214,8 @@ ValueType AnyCast(const Any& operand)
|
|||||||
/// these cases.
|
/// these cases.
|
||||||
{
|
{
|
||||||
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
|
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
|
||||||
if (!result) throw BadCastException("Failed to convert between const Any types");
|
if (!result)
|
||||||
|
throw BadCastException("Failed to convert between const Any types");
|
||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,16 +239,16 @@ ValueType AnyCast(Any& operand)
|
|||||||
|
|
||||||
|
|
||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
const ValueType& RefAnyCast(const Any & operand)
|
const ValueType& RefAnyCast(const Any& operand)
|
||||||
/// AnyCast operator used to return a const reference to the internal data.
|
/// AnyCast operator used to return a const reference to the internal data.
|
||||||
///
|
///
|
||||||
/// Example Usage:
|
/// Example Usage:
|
||||||
/// const MyType& tmp = RefAnyCast<MyType>(anAny);
|
/// const MyType& tmp = RefAnyCast<MyType>(anAny);
|
||||||
{
|
{
|
||||||
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
|
if (operand.type() == typeid(ValueType))
|
||||||
if (!result)
|
return static_cast<Any::Holder<ValueType>*>(operand._content)->_held;
|
||||||
|
else
|
||||||
throw BadCastException("RefAnyCast: Failed to convert between const Any types");
|
throw BadCastException("RefAnyCast: Failed to convert between const Any types");
|
||||||
return *result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -252,10 +259,10 @@ ValueType& RefAnyCast(Any& operand)
|
|||||||
/// Example Usage:
|
/// Example Usage:
|
||||||
/// MyType& tmp = RefAnyCast<MyType>(anAny);
|
/// MyType& tmp = RefAnyCast<MyType>(anAny);
|
||||||
{
|
{
|
||||||
ValueType* result = AnyCast<ValueType>(&operand);
|
if (operand.type() == typeid(ValueType))
|
||||||
if (!result)
|
return static_cast<Any::Holder<ValueType>*>(operand._content)->_held;
|
||||||
|
else
|
||||||
throw BadCastException("RefAnyCast: Failed to convert between Any types");
|
throw BadCastException("RefAnyCast: Failed to convert between Any types");
|
||||||
return *result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user