diff options
author | Travis CI <zmoelnig@travis-ci.umlaeute.mur.at> | 2019-01-09 19:48:49 +0000 |
---|---|---|
committer | Travis CI <zmoelnig@travis-ci.umlaeute.mur.at> | 2019-01-09 19:48:49 +0000 |
commit | 7bc94fb6d5cab4b0c6a0c2c957e1c6543fd226c9 (patch) | |
tree | 5311afd1ca12875216afada471ae45ae3232124b /Gem/develop/include/Gem/Utils | |
parent | be48f8978f1a25bb3ae4dc456e59db4f69700b87 (diff) |
Gem d136736e8da1d549bd8f44bb50c26fc98f76f776 osx/i386
built 'master:d136736e8da1d549bd8f44bb50c26fc98f76f776' for osx/i386
Diffstat (limited to 'Gem/develop/include/Gem/Utils')
-rw-r--r-- | Gem/develop/include/Gem/Utils/any.h | 20 | ||||
-rw-r--r-- | Gem/develop/include/Gem/Utils/is_pointer.h | 34 |
2 files changed, 47 insertions, 7 deletions
diff --git a/Gem/develop/include/Gem/Utils/any.h b/Gem/develop/include/Gem/Utils/any.h index 0861e19..435f3a3 100644 --- a/Gem/develop/include/Gem/Utils/any.h +++ b/Gem/develop/include/Gem/Utils/any.h @@ -27,7 +27,9 @@ #include <algorithm> #include <string> -//#define GEM_ANY_TYPEID_HACK +#include "is_pointer.h" + +//#define GEM_ANY_TYPEID_HACK 1 namespace gem { @@ -293,6 +295,11 @@ struct GEM_EXTERN any { { return (get_type() == typeid(T)); } + template<typename T> + bool compatible(T&x) const + { + return compatible<T>(); + } // implicit casting is disabled by default @@ -329,11 +336,10 @@ struct GEM_EXTERN any { }; // boost::any-like casting - template<typename T> -T* any_cast(any* this_) +T* any_cast(any* this_, bool force) { - if (this_->get_type() != typeid(T)) { + if (!force && !this_->compatible<T>()) { throw bad_any_cast(this_->get_type(), typeid(T)); } if (sizeof(T) <= sizeof(void*)) { @@ -346,13 +352,13 @@ T* any_cast(any* this_) template<typename T> T const* any_cast(any const* this_) { - return any_cast<T>(const_cast<any*>(this_)); + return any_cast<T>(const_cast<any*>(this_), false); } template<typename T> -T const& any_cast(any const& this_) +T const& any_cast(any const& this_, bool force_pointers=false) { - return *any_cast<T>(const_cast<any*>(&this_)); + return *any_cast<T>(const_cast<any*>(&this_), force_pointers && is_pointer<T>()); } #ifdef GEM_INTERNAL // Note: The "unsafe" versions of any_cast are not part of the diff --git a/Gem/develop/include/Gem/Utils/is_pointer.h b/Gem/develop/include/Gem/Utils/is_pointer.h new file mode 100644 index 0000000..6c5cb16 --- /dev/null +++ b/Gem/develop/include/Gem/Utils/is_pointer.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2010 fredoverflow https://stackoverflow.com/a/3177723/1169096 + * Copyright © 2019 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at + */ + +#ifndef GEM_IS_POINTER_H_ +#define GEM_IS_POINTER_H_ + +namespace gem +{ + template <typename T> + struct is_pointer_type + { + enum { value = false }; + }; + + template <typename T> + struct is_pointer_type<T*> + { + enum { value = true }; + }; + + template <typename T> + bool is_pointer(void) + { + return is_pointer_type<T>::value; + } + template <typename T> + bool is_pointer(const T&) + { + return is_pointer_type<T>::value; + } +}; +#endif // GEM_IS_POITNER_H_ |