aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core/utils
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-11-14 13:16:56 +0000
committerIsabella Gottardi <isabella.gottardi@arm.com>2018-11-21 09:52:04 +0000
commitdf3103622b7de05f4e35b22a2c94b4a46eab4efc (patch)
tree17e10253e7a069c69d10bea0882b699b99d74b86 /arm_compute/core/utils
parentc47ef20d69e8ea0f519fdc679435cd7037fc18fe (diff)
downloadComputeLibrary-df3103622b7de05f4e35b22a2c94b4a46eab4efc.tar.gz
COMPMID-1088: Use IMemoryRegion in interfaces where possible
-Simplifies import memory interface -Changes the used of void** handles with appropriate interfaces. Change-Id: I5918c855c11f46352058864623336b352162a4b7
Diffstat (limited to 'arm_compute/core/utils')
-rw-r--r--arm_compute/core/utils/misc/Cast.h47
1 files changed, 45 insertions, 2 deletions
diff --git a/arm_compute/core/utils/misc/Cast.h b/arm_compute/core/utils/misc/Cast.h
index f6c91dd2de..5d9d1b0eca 100644
--- a/arm_compute/core/utils/misc/Cast.h
+++ b/arm_compute/core/utils/misc/Cast.h
@@ -41,7 +41,7 @@ namespace cast
*
* @param[in] v Value to cast
*
- * @return The casted type
+ * @return The casted value
*/
template <typename Target, typename Source>
inline Target polymorphic_cast(Source *v)
@@ -62,7 +62,7 @@ inline Target polymorphic_cast(Source *v)
*
* @param[in] v Value to cast
*
- * @return The casted type
+ * @return The casted value
*/
template <typename Target, typename Source>
inline Target polymorphic_downcast(Source *v)
@@ -70,6 +70,49 @@ inline Target polymorphic_downcast(Source *v)
ARM_COMPUTE_ERROR_ON(dynamic_cast<Target>(v) != static_cast<Target>(v));
return static_cast<Target>(v);
}
+
+/** Polymorphic cast between two unique pointer types
+ *
+ * @warning Will throw an exception if cast cannot take place
+ *
+ * @tparam Target Target to cast type
+ * @tparam Source Source from cast type
+ * @tparam Deleter Deleter function type
+ *
+ * @param[in] v Value to cast
+ *
+ * @return The casted value
+ */
+template <typename Target, typename Source, typename Deleter>
+std::unique_ptr<Target, Deleter> polymorphic_cast_unique_ptr(std::unique_ptr<Source, Deleter> &&v)
+{
+ if(dynamic_cast<Target *>(v.get()) == nullptr)
+ {
+ throw std::bad_cast();
+ }
+ auto r = static_cast<Target *>(v.release());
+ return std::unique_ptr<Target, Deleter>(r, std::move(v.get_deleter()));
+}
+
+/** Polymorphic down cast between two unique pointer types
+ *
+ * @warning Will assert if cannot take place
+ *
+ * @tparam Target Target to cast type
+ * @tparam Source Source from cast type
+ * @tparam Deleter Deleter function type
+ *
+ * @param[in] v Value to cast
+ *
+ * @return The casted value
+ */
+template <typename Target, typename Source, typename Deleter>
+std::unique_ptr<Target, Deleter> polymorphic_downcast_unique_ptr(std::unique_ptr<Source, Deleter> &&v)
+{
+ ARM_COMPUTE_ERROR_ON(dynamic_cast<Target *>(v.get()) != static_cast<Target *>(v.get()));
+ auto r = static_cast<Target *>(v.release());
+ return std::unique_ptr<Target, Deleter>(r, std::move(v.get_deleter()));
+}
} // namespace cast
} // namespace utils
} // namespace arm_compute