From df3103622b7de05f4e35b22a2c94b4a46eab4efc Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 14 Nov 2018 13:16:56 +0000 Subject: COMPMID-1088: Use IMemoryRegion in interfaces where possible -Simplifies import memory interface -Changes the used of void** handles with appropriate interfaces. Change-Id: I5918c855c11f46352058864623336b352162a4b7 --- arm_compute/core/utils/misc/Cast.h | 47 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'arm_compute/core/utils') 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 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 inline Target polymorphic_downcast(Source *v) @@ -70,6 +70,49 @@ inline Target polymorphic_downcast(Source *v) ARM_COMPUTE_ERROR_ON(dynamic_cast(v) != static_cast(v)); return static_cast(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 +std::unique_ptr polymorphic_cast_unique_ptr(std::unique_ptr &&v) +{ + if(dynamic_cast(v.get()) == nullptr) + { + throw std::bad_cast(); + } + auto r = static_cast(v.release()); + return std::unique_ptr(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 +std::unique_ptr polymorphic_downcast_unique_ptr(std::unique_ptr &&v) +{ + ARM_COMPUTE_ERROR_ON(dynamic_cast(v.get()) != static_cast(v.get())); + auto r = static_cast(v.release()); + return std::unique_ptr(r, std::move(v.get_deleter())); +} } // namespace cast } // namespace utils } // namespace arm_compute -- cgit v1.2.1