diff --git a/src/core/include/openvino/core/any.hpp b/src/core/include/openvino/core/any.hpp index f9d5fa32934..2e094c44f2d 100644 --- a/src/core/include/openvino/core/any.hpp +++ b/src/core/include/openvino/core/any.hpp @@ -203,6 +203,8 @@ class OPENVINO_API Any { throw ov::Exception{"Could read type without std::istream& operator>>(std::istream&, T) defined"}; } + static bool equal(std::type_index lhs, std::type_index rhs); + /** * @brief Base API of erased type */ @@ -232,9 +234,11 @@ class OPENVINO_API Any { bool visit_attributes(AttributeVisitor&) const; std::string to_string() const; + bool is(const std::type_info& other) const; + template bool is() const { - return typeid(decay_t) == type_info(); + return is(typeid(decay_t)); } template @@ -474,11 +478,11 @@ public: template bool is() const { if (_impl != nullptr) { - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return true; } for (const auto& type_index : _impl->base_type_info()) { - if (type_index == typeid(decay_t)) { + if (equal(type_index, typeid(decay_t))) { return true; } } @@ -497,7 +501,7 @@ public: _temp_impl = std::make_shared>>(T{}); return _temp_impl->as(); } else { - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return std::move(*static_cast*>(_impl->addressof())); } else { auto runtime_attribute = _impl->as_runtime_attribute(); @@ -532,7 +536,7 @@ public: _temp_impl = std::make_shared>>(T{}); return _temp_impl->as(); } else { - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } else { auto runtime_attribute = _impl->as_runtime_attribute(); @@ -568,7 +572,7 @@ public: _temp_impl = std::make_shared>>(T{}); return _temp_impl->as(); } else { - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } else { auto runtime_attribute = _impl->as_runtime_attribute(); @@ -603,7 +607,7 @@ public: T>::type&& as() && { impl_check(); - if (_impl->type_info() == typeid(std::string)) { + if (_impl->is(typeid(std::string))) { _temp_impl = std::make_shared>>(); std::stringstream strm{as()}; _temp_impl->read(strm); @@ -624,16 +628,16 @@ public: T>::type& as() & { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); - } else if (_impl->type_info() == typeid(std::string)) { + } else if (_impl->is(typeid(std::string))) { _temp_impl = std::make_shared>>(); std::stringstream strm{as()}; _temp_impl->read(strm); return *static_cast*>(_temp_impl->addressof()); } for (const auto& type_index : _impl->base_type_info()) { - if (type_index == typeid(decay_t)) { + if (equal(type_index, typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } } @@ -651,16 +655,16 @@ public: T>::type& as() const& { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); - } else if (_impl->type_info() == typeid(std::string)) { + } else if (_impl->is(typeid(std::string))) { _temp_impl = std::make_shared>>(); std::stringstream strm{as()}; _temp_impl->read(strm); return *static_cast*>(_temp_impl->addressof()); } for (const auto& type_index : _impl->base_type_info()) { - if (type_index == typeid(decay_t)) { + if (equal(type_index, typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } } @@ -693,11 +697,11 @@ public: T>::type& as() & { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } for (const auto& type_index : _impl->base_type_info()) { - if (type_index == typeid(decay_t)) { + if (equal(type_index, typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } } @@ -715,11 +719,11 @@ public: T>::type& as() const& { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } for (const auto& type_index : _impl->base_type_info()) { - if (type_index == typeid(decay_t)) { + if (equal(type_index, typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } } @@ -734,7 +738,7 @@ public: template typename std::enable_if::value, T>::type&& as() && { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return std::move(*static_cast*>(_impl->addressof())); } else { std::stringstream strm; @@ -752,7 +756,7 @@ public: template typename std::enable_if::value, T>::type& as() & { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } else { std::stringstream strm; @@ -770,7 +774,7 @@ public: template const typename std::enable_if::value, T>::type& as() const& { impl_check(); - if (_impl->type_info() == typeid(decay_t)) { + if (_impl->is(typeid(decay_t))) { return *static_cast*>(_impl->addressof()); } else { std::stringstream strm; diff --git a/src/core/src/any.cpp b/src/core/src/any.cpp index 3ac509495b0..cf0b83b58cc 100644 --- a/src/core/src/any.cpp +++ b/src/core/src/any.cpp @@ -8,8 +8,22 @@ namespace ov { +bool Any::equal(std::type_index lhs, std::type_index rhs) { + auto result = lhs == rhs; +#ifdef __ANDROID__ + if (!result) { + result = std::strcmp(lhs.name(), rhs.name()) == 0; + } +#endif + return result; +} + +bool Any::Base::is(const std::type_info& other) const { + return Any::equal(type_info(), other); +} + void Any::Base::type_check(const std::type_info& type_info_) const { - OPENVINO_ASSERT(type_info() == type_info_, "Bad cast from: ", type_info().name(), " To type: ", type_info_.name()); + OPENVINO_ASSERT(is(type_info_), "Bad cast from: ", type_info().name(), " To type: ", type_info_.name()); } std::shared_ptr Any::Base::as_runtime_attribute() const {