sharedPointer_boost.hh

Go to the documentation of this file.
1 
5 #pragma once
6 #include "boost/shared_ptr.hpp"
7 #include "boost/weak_ptr.hpp"
8 
9 namespace concepts {
10 
11  // ********************************************************** null_deleter **
12 
13  struct null_deleter
14  {
15  void operator()(void const *) const
16  {
17  }
18  };
19 
20  // ******************************************************************* RCP **
21 
27  template<class T>
28  class RCP : public boost::shared_ptr<T>
29  {
30  public:
32  RCP() : boost::shared_ptr<T>() {}
33 
46  explicit RCP(T* x) : boost::shared_ptr<T>(x) {}
47 
48  RCP(boost::shared_ptr<T>& x) : boost::shared_ptr<T>(x) {}
49 
50  template<class F>
51  RCP(const boost::shared_ptr<F>& x) : boost::shared_ptr<T>(x) {}
52 
54  template<class F, class G>
55  RCP(F x, G y) : boost::shared_ptr<T>(x, y) {}
56 
58  {
59  RCP<T>(x).swap(*this);
60  return *this;
61  }
62 
63  template<class F>
64  RCP<T>& operator=(const boost::shared_ptr<F> x)
65  {
66  RCP<T>(x).swap(*this);
67  return *this;
68  }
69 
70  // this conversion operator is already implemented for shared_ptr
71  #if 0
72  // template function for implicit conversion ops.
73  template<class NewType>
74  operator RCP<NewType>()
75  {
76  return RCP<NewType>( boost::shared_ptr<NewType>(*this) );
77  }
78  #endif
79  };
80 
81  // *************************************************************** makeRCP **
82 
101  template <class T>
103  {
104  return RCP<T>(x);
105  }
106 
107  // ********************************************************** makeRCP_weak **
108 
121  template<class T>
123  {
124  return RCP<T>(x, null_deleter());
125  }
126 
127 #if 1
128  template<class T>
129  RCP<const T> makecRCP_weak(T* x) // create a const pointer
130  {
131  return RCP<const T>(x, null_deleter());
132  }
133 #endif
134 
135 
136 } // namespace concepts
void operator()(void const *) const
RCP(F x, G y)
Constructor which includes the deleter G.
RCP< T > & operator=(const boost::shared_ptr< F > x)
RCP< T > makeRCP_weak(T *x)
Function to create a RCP without deleting the object in the destructor.
RCP(boost::shared_ptr< T > &x)
RCP< const T > makecRCP_weak(T *x)
RCP()
Default constructor.
RCP(const boost::shared_ptr< F > &x)
RCP< T > makeRCP(T *x)
Function to create a RCP which deletes the object when no RCP points on it anymore.
Reference-counting pointer.
Definition: bf_iddiv.hh:15
RCP(T *x)
Constructor for a simple pointer, which will be deleted by the RCP.
RCP< T > & operator=(const RCP< T > x)
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich