aboutsummaryrefslogtreecommitdiff
path: root/Gem/develop/include/Gem/Utils/any.h
diff options
context:
space:
mode:
Diffstat (limited to 'Gem/develop/include/Gem/Utils/any.h')
-rw-r--r--Gem/develop/include/Gem/Utils/any.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/Gem/develop/include/Gem/Utils/any.h b/Gem/develop/include/Gem/Utils/any.h
index 5841c79..0861e19 100644
--- a/Gem/develop/include/Gem/Utils/any.h
+++ b/Gem/develop/include/Gem/Utils/any.h
@@ -27,6 +27,7 @@
#include <algorithm>
#include <string>
+//#define GEM_ANY_TYPEID_HACK
namespace gem
{
@@ -70,7 +71,7 @@ struct fxns {
struct type {
static const std::type_info& get_type(void)
{
-#if 0
+#if GEM_ANY_TYPEID_HACK
const std::type_info&res=typeid(T);
// the following is a dummy use of the type_info struct
// to make the template engine work properly on OSX/10.9
@@ -104,7 +105,7 @@ struct fxns<false> {
struct type {
static const std::type_info& get_type(void)
{
-#if 0
+#if GEM_ANY_TYPEID_HACK
const std::type_info&res=typeid(T);
return res;
#else
@@ -353,6 +354,34 @@ T const& any_cast(any const& this_)
{
return *any_cast<T>(const_cast<any*>(&this_));
}
+#ifdef GEM_INTERNAL
+// Note: The "unsafe" versions of any_cast are not part of the
+// public interface (and hence protected by GEM_INTERNAL) and may
+// be removed at any time. They are required where we know what type
+// is stored in the any and can't use typeid() comparison, e.g.,
+// when our types may travel across different shared libraries.
+template<typename T>
+T* unsafe_any_cast(any* this_)
+{
+ if (sizeof(T) <= sizeof(void*)) {
+ return reinterpret_cast<T*>(&this_->object);
+ } else {
+ return reinterpret_cast<T*>(this_->object);
+ }
+}
+
+template<typename T>
+T const* unsafe_any_cast(any const* this_)
+{
+ return unsafe_any_cast<T>(const_cast<any*>(this_));
+}
+
+template<typename T>
+T const& unsafe_any_cast(any const& this_)
+{
+ return *unsafe_any_cast<T>(const_cast<any*>(&this_));
+}
+#endif
}
#ifdef _MSC_VER