C++ main module for stochmagnet Package  1.0
sp.h
Go to the documentation of this file.
1 #ifndef CORE_SP_H
2 #define CORE_SP_H
3 
4 #include "CORE_Object.h"
5 
6 //unique pointer
7 template<class T>
8 using CORE_UniquePointer = typename std::unique_ptr<T,CORE_Object::Delete> ;
9 
10 
11 //shared pointer
12 template<class T>
13 using CORE_SharedPointer = typename std::shared_ptr<T> ;
14 
15 //weak pointer
16 template<class T>
17 using CORE_WeakPointer = typename std::weak_ptr<T> ;
18 
19 
20 //some usefull function for manipulating smart pointers
21 namespace sp {
22 
23 
24 
25  //casting of smart pointer for not virtual base B class by reference
26  template<typename D,typename B>
28  return CORE_UniquePointer<D>(static_cast<D*>(basePointer.release()));
29  }
30  //casting of smart pointer for not virtual base B class by L-Value
31  template<typename D,typename B>
33  return CORE_UniquePointer<D>(static_cast<D*>(basePointer.release()));
34  }
35 
36  //casting of smart pointer for virtual base B class
37  template<typename D,typename B>
39  return CORE_UniquePointer<D>(dynamic_cast<D*>(basePointer.release()));
40  }
41  //casting of smart pointer for virtual base B class by L-Value
42  template<typename D,typename B>
44  return CORE_UniquePointer<D>(dynamic_cast<D*>(basePointer.release()));
45  }
46 
47 
48  /* \brief cast the shared pointer of class U to T
49  */
50  template<class T, class U>
51  static CORE_SharedPointer<T> dynamic_sp_cast(CORE_SharedPointer<U> const & r) {
52  return dynamic_pointer_cast<T>(r);
53  };
54  /* \brief cast the shared pointer of class U to T
55  */
56  template<class T, class U>
57  static CORE_SharedPointer<const T> dynamic_spc_cast(CORE_SharedPointer<const U> const & r) {
58  return dynamic_pointer_cast<const T>(r);
59  };
60 
61 
62 
63 };
64 
65 #endif
Definition: sp.h:21
CORE_UniquePointer< D > static_upointer_cast(CORE_UniquePointer< B > &basePointer)
Definition: sp.h:27
CORE_UniquePointer< D > dynamic_upointer_cast(CORE_UniquePointer< B > &basePointer)
Definition: sp.h:38
typename std::unique_ptr< T, CORE_Object::Delete > CORE_UniquePointer
Definition: sp.h:8
typename std::weak_ptr< T > CORE_WeakPointer
Definition: sp.h:17
typename std::shared_ptr< T > CORE_SharedPointer
Definition: sp.h:13