@@ -77,9 +77,18 @@ struct OPENVINO_API DiscreteTypeInfo {
77
77
OPENVINO_API
78
78
std::ostream& operator <<(std::ostream& s, const DiscreteTypeInfo& info);
79
79
80
+ namespace frontend {
81
+ class ConversionExtensionBase ;
82
+ } // frontend
83
+
84
+ template <typename T>
85
+ constexpr bool use_ov_dynamic_cast () {
80
86
#if defined(__ANDROID__) || defined(ANDROID)
81
- # define OPENVINO_DYNAMIC_CAST
87
+ return true ;
88
+ #else
89
+ return std::is_base_of_v<ov::frontend::ConversionExtensionBase, T>;
82
90
#endif
91
+ }
83
92
84
93
// / \brief Tests if value is a pointer/shared_ptr that can be statically cast to a
85
94
// / Type*/shared_ptr<Type>
@@ -97,11 +106,10 @@ template <typename Type, typename Value>
97
106
typename std::enable_if<std::is_convertible<decltype(static_cast <Type*>(std::declval<Value>())), Type*>::value,
98
107
Type*>::type
99
108
as_type (Value value) {
100
- #ifdef OPENVINO_DYNAMIC_CAST
101
- return ov::is_type<Type>(value) ? static_cast <Type*>(value) : nullptr ;
102
- #else
103
- return dynamic_cast <Type*>(value);
104
- #endif
109
+ if constexpr (use_ov_dynamic_cast<Type>())
110
+ return is_type<Type>(value) ? static_cast <Type*>(value) : nullptr ;
111
+ else
112
+ return dynamic_cast <Type*>(value);
105
113
}
106
114
107
115
namespace util {
@@ -120,13 +128,12 @@ struct AsTypePtr<std::shared_ptr<In>> {
120
128
121
129
// / Casts a std::shared_ptr<Value> to a std::shared_ptr<Type> if it is of type
122
130
// / Type, nullptr otherwise
123
- template <typename T, typename U>
124
- auto as_type_ptr (const U& value) -> decltype(::ov::util::AsTypePtr<U>::template call<T>(value)) {
125
- #ifdef OPENVINO_DYNAMIC_CAST
126
- return ::ov::util::AsTypePtr<U>::template call<T>(value);
127
- #else
128
- return std::dynamic_pointer_cast<T>(value);
129
- #endif
131
+ template <typename Type, typename Value>
132
+ auto as_type_ptr (const Value& value) -> decltype(::ov::util::AsTypePtr<Value>::template call<Type>(value)) {
133
+ if constexpr (use_ov_dynamic_cast<Type>())
134
+ return ::ov::util::AsTypePtr<Value>::template call<Type>(value);
135
+ else
136
+ return std::dynamic_pointer_cast<Type>(value);
130
137
}
131
138
} // namespace ov
132
139
0 commit comments