C++ mpi module for stochmagnet_main Package
shared_pointer.h
1 #ifndef SHARED_POINTER_H
2 #define SHARED_POINTER_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 
12 //shared pointer
13 template<class T>
14 using CORE_SharedPointer = typename std::shared_ptr<T> ;
15 
16 
17 //weak pointer
18 template<class T>
19 using CORE_WeakPointer = typename std::weak_ptr<T> ;
20 
21 
22 //some usefull function for manipulating smart pointers
23 namespace shared_pointer {
24 
25  /* \brief cast the shared pointer of class F to T
26  */
27  template<class T, class F>
28  static CORE_SharedPointer<T> dynamic_sp_cast(CORE_SharedPointer<F> const & r) {
29  return dynamic_pointer_cast<T>(r);
30  };
31  /* \brief cast the shared pointer of class F to T
32  */
33  template<class T, class F>
34  static CORE_SharedPointer<const T> dynamic_spc_cast(CORE_SharedPointer<const F> const & r) {
35  return dynamic_pointer_cast<const T>(r);
36  };
37 
38  /* \brief cast the unique pointer of class F to T
39  * @param[in] r : unqiue pointer of type F to cast to derived class T of the instance
40  */
41  template<class T, class F>
42  static CORE_UniquePointer<T> dynamic_up_cast(CORE_UniquePointer<F> & r) {
43  T* p = dynamic_cast<T*>( r.get() );
44  if (p!=null) r.release();
45  return CORE_UniquePointer<T>(p);
46  };
47  /* \brief cast the unique pointer of class F to T
48  * @param[in] r : unqiue pointer of type F to cast to derived class T of the instance
49  */
50  template<class T, class F>
51  static CORE_UniquePointer<T> dynamic_up_cast(CORE_UniquePointer<F> && r) {
52  T* p = dynamic_cast<T*>( r.get() );
53  if (p!=null) r.release();
54  return CORE_UniquePointer<T>(p);
55  };
56  /* \brief cast the unique pointer of class F to T
57  * @param[in] r : unqiue pointer of type F to cast to derived class T of the instance
58  */
59  template<class T, class F>
60  static CORE_UniquePointer<const T> dynamic_upc_cast(CORE_UniquePointer<const F> & r) {
61  const T* p = dynamic_cast<const T*>( r.get() );
62  if( p!=null) r.release();
63  return CORE_UniquePointer<const T>(p);
64  };
65  /* \brief cast the unique pointer of class F to T
66  * @param[in] r : unqiue pointer of type F to cast to derived class T of the instance
67  */
68  template<class T, class F>
69  static CORE_UniquePointer<const T> dynamic_upc_cast(CORE_UniquePointer<const F> && r) {
70  const T* p = dynamic_cast<const T*>( r.get() );
71  if( p!=null ) r.release();
72  return CORE_UniquePointer<const T>(p);
73  };
74 
75 
76 
77 
78 
79 };
80 #define CORE_UniqueInstance CORE_UniquePointer
81 #define CORE_SharedInstance CORE_SharedPointer
82 
83 #endif