37#ifndef UNTYPED_SHARED_PTR_H
38#define UNTYPED_SHARED_PTR_H
82 virtual const std::type_info&
getType()
const = 0;
98 using ELEM_TYPE =
typename std::remove_all_extents<T>::type;
103 template <
typename Deleter>
111 template <
typename U,
typename _ =
typename std::enable_if<
112 std::is_array<T>::value, U>::type>
116 const std::type_info&
getType()
const override
181 template <
typename T,
class Deleter = std::default_delete<T>>
306 template <
typename T>
309 const auto& templateType =
typeid(T);
310 const auto& templateTypeNoConst =
typeid(std::remove_const_t<T>);
311 const auto& ownType = this->
getType();
312 const auto& templatePtrType =
typeid(T*);
313 const auto& templatePtrTypeNoConst =
314 typeid(std::remove_const_t<T>*);
320 if (ownPtrType == templatePtrType && templateType == ownType) {
321 std::shared_ptr<const Model<T>> typedPtr =
322 std::dynamic_pointer_cast<const Model<T>>(
324 if (typedPtr != NULL) {
325 return typedPtr->sharedPtr;
332 if (ownPtrType == templatePtrTypeNoConst &&
333 templateType == ownType) {
334 std::shared_ptr<const Model<std::remove_const_t<T>>> typedPtr =
335 std::dynamic_pointer_cast<
338 if (typedPtr != NULL) {
346 if (templateType == ownType) {
347 std::shared_ptr<const Model<T>> typedPtr =
348 std::dynamic_pointer_cast<const Model<T>>(
350 if (typedPtr != NULL) {
351 return typedPtr->sharedPtr;
359 if (templateTypeNoConst == ownType) {
360 std::shared_ptr<const Model<std::remove_const_t<T>>> typedPtr =
361 std::dynamic_pointer_cast<
364 if (typedPtr != NULL) {
370 std::string msg(
"Cannot convert ");
371 msg.append(ownPtrType.name());
372 msg.append(
" into ");
373 msg.append(templatePtrType.name());
376 throw std::runtime_error(msg);
392 return [](T* ptr) {};
Class behaving as a std::shared_ptr whose type is not templated.
Definition: untypedSharedPtr.h:72
const std::type_info & getType() const
Accessor to the type of data stored in the UntypedSharedPtr.
Definition: untypedSharedPtr.h:227
std::shared_ptr< const Concept > sharedPtrContainer
Shared container containing the data structure containing the actual std::shared_ptr.
Definition: untypedSharedPtr.h:393
const std::type_info & getPtrType() const
Accessor to the pointer type of data stored in the UntypedSharedPtr.
Definition: untypedSharedPtr.h:257
UntypedSharedPtr(std::shared_ptr< Concept > concept)
Constructor from an existing Concept.
Definition: untypedSharedPtr.h:199
UntypedSharedPtr()=delete
Deleted default constructor.
std::shared_ptr< std::remove_all_extents_t< T > > getSharedPointer() const
Get the shared_ptr store in the UntypedSharedPtr.
Definition: untypedSharedPtr.h:307
UntypedSharedPtr(T *obj, Deleter func=Deleter())
Main constructor of the UntypedSharedPtr class.
Definition: untypedSharedPtr.h:182
static std::function< void(T *)> emptyDestructor()
Get an empty destructor function for any type.
Definition: untypedSharedPtr.h:390
Definition: array2DWrapper.h:44
Internal structure of the type erasure pattern.
Definition: untypedSharedPtr.h:78
virtual const std::type_info & getPtrType() const =0
Polymorphic getPtrType() function.
virtual ~Concept()=default
Default deleter made virtual to activate polyphormism.
virtual const std::type_info & getType() const =0
Polymorphic getType() function.
Internal templated structure of the type erasure pattern.
Definition: untypedSharedPtr.h:96
Model(T *t, Deleter func)
Definition: untypedSharedPtr.h:104
Model(U *p)
Definition: untypedSharedPtr.h:113
typename std::remove_all_extents< T >::type ELEM_TYPE
Raw type of the element stored in the shared_ptr.
Definition: untypedSharedPtr.h:98
const std::type_info & getPtrType() const override
Polymorphic getPtrType() function.
Definition: untypedSharedPtr.h:122
std::shared_ptr< ELEM_TYPE > sharedPtr
std::shared_ptr of the UntypedSharedPtr
Definition: untypedSharedPtr.h:128
const std::type_info & getType() const override
Polymorphic getType() function.
Definition: untypedSharedPtr.h:116