Skip to content

Commit

Permalink
Use OV dynamic cast on Android only
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Jankowski <[email protected]>
  • Loading branch information
t-jankowski committed Jan 17, 2025
1 parent 93b2567 commit 56480d6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/include/openvino/core/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ struct OPENVINO_API DiscreteTypeInfo {
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const DiscreteTypeInfo& info);

#if defined(__ANDROID__) || defined(ANDROID)
# define OPENVINO_DYNAMIC_CAST
#endif

/// \brief Tests if value is a pointer/shared_ptr that can be statically cast to a
/// Type*/shared_ptr<Type>
template <typename Type, typename Value>
Expand All @@ -93,7 +97,11 @@ template <typename Type, typename Value>
typename std::enable_if<std::is_convertible<decltype(static_cast<Type*>(std::declval<Value>())), Type*>::value,
Type*>::type
as_type(Value value) {
#ifdef OPENVINO_DYNAMIC_CAST
return ov::is_type<Type>(value) ? static_cast<Type*>(value) : nullptr;
#else
return dynamic_cast<Type*>(value);
#endif
}

namespace util {
Expand All @@ -114,7 +122,11 @@ struct AsTypePtr<std::shared_ptr<In>> {
/// Type, nullptr otherwise
template <typename T, typename U>
auto as_type_ptr(const U& value) -> decltype(::ov::util::AsTypePtr<U>::template call<T>(value)) {
#ifdef OPENVINO_DYNAMIC_CAST
return ::ov::util::AsTypePtr<U>::template call<T>(value);
#else
return std::dynamic_pointer_cast<T>(value);
#endif
}
} // namespace ov

Expand Down

0 comments on commit 56480d6

Please sign in to comment.