5 #ifndef DUNE_SHARED_PTR_HH
6 #define DUNE_SHARED_PTR_HH
8 #if defined SHARED_PTR_HEADER
9 # include SHARED_PTR_HEADER
11 #if defined HAVE_BOOST_SHARED_PTR_HPP
12 #if defined HAVE_BOOST_MAKE_SHARED_HPP
13 # include <boost/make_shared.hpp>
28 #ifdef SHARED_PTR_NAMESPACE
29 using SHARED_PTR_NAMESPACE :: shared_ptr;
49 : count_(rep.count_) {}
106 template<
class T1,
class Deleter>
107 inline shared_ptr(T1 * pointer, Deleter deleter);
141 inline const element_type&
operator*()
const;
144 inline const element_type*
operator->()
const;
147 element_type*
get()
const {
152 operator bool()
const {
153 return count_ != 0 && rep_ != 0;
166 inline void reset(T1* pointer);
169 template<
class T1,
class Deleter>
170 inline void reset(T1* pointer, Deleter deleter);
180 template<
class Deleter>
181 class SharedCountImpl :
187 SharedCountImpl(T* elem,
const Deleter& deleter) :
193 SharedCountImpl(
const SharedCountImpl& rep)
194 : SharedCount(rep), deleter_(rep.deleter_), rep_(rep.rep_) {}
205 struct DefaultDeleter
207 void operator() (element_type* p)
const
216 typedef T* *__unspecified_bool_type;
220 operator __unspecified_bool_type() const
222 return rep_ == 0 ? 0 : &shared_ptr::rep_;
232 count_ =
new SharedCountImpl<DefaultDeleter>(p, DefaultDeleter());
243 template<
class T1,
class Deleter>
247 count_ =
new SharedCountImpl<Deleter>(p, deleter);
260 : count_(other.count_), rep_(other.rep_)
268 : count_(other.count_), rep_(other.rep_)
278 return assign(other);
284 return assign(other);
294 if(rep_!=0 && --(count_->count_)<=0) {
299 count_ = other.count_;
306 if(rep_!=0 && --(count_->count_)==0) {
339 return count_->count_;
347 other.count_ = dummy;
367 template<
class T1,
class Deleter>
374 #endif // #ifdef SHARED_PTR_NAMESPACE
381 #ifdef SHARED_PTR_NAMESPACE
392 template<
typename T,
typename Arg1>
398 template<
typename T,
typename Arg1,
typename Arg2>
404 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
410 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4>
416 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
424 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
425 typename Arg5,
typename Arg6>
427 const Arg5& arg5,
const Arg6& arg6)
432 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
433 typename Arg5,
typename Arg6,
typename Arg7>
435 const Arg5& arg5,
const Arg6& arg6,
const Arg7& arg7)
437 return shared_ptr<T>(
new T(arg1,arg2,arg3,arg4,arg5,arg6,arg7));
440 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
441 typename Arg5,
typename Arg6,
typename Arg7,
typename Arg8>
443 const Arg5& arg5,
const Arg6& arg6,
const Arg7& arg7,
const Arg8& arg8)
445 return shared_ptr<T>(
new T(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8));
448 template<
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
449 typename Arg5,
typename Arg6,
typename Arg7,
typename Arg8,
typename Arg9>
451 const Arg5& arg5,
const Arg6& arg6,
const Arg7& arg7,
const Arg8& arg8,
454 return shared_ptr<T>(
new T(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9));
457 #endif // custom make_shared
520 template<
typename T,
typename T2>
Traits for type conversions and type information.
T t
Definition: alignment.hh:38
Dune namespace.
Definition: alignment.hh:13
~shared_ptr()
Destructor.
Definition: shared_ptr.hh:304
void reset()
Decrease the reference count by one and free the memory if the reference count has reached 0...
Definition: shared_ptr.hh:354
The object we reference.
Definition: shared_ptr.hh:38
Fallback implementation of the nullptr object in C++0x.
int use_count() const
The number of shared_ptrs pointing to the object we point to.
Definition: shared_ptr.hh:337
SharedCount()
Constructor from existing Pointer.
Definition: shared_ptr.hh:46
element_type & operator*()
Dereference as object.
Definition: shared_ptr.hh:313
Fallback implementation of nullptr.
Definition: nullptr.hh:19
shared_ptr< T2 > stackobject_to_shared_ptr(T &t)
Convert a stack object to a shared_ptr of a base class.
Definition: shared_ptr.hh:521
SharedCount(const SharedCount &rep)
Copy constructor with type conversion.
Definition: shared_ptr.hh:48
shared_ptr()
Constructs a new smart pointer and allocates the referenced Object.
Definition: shared_ptr.hh:251
int count_
The number of references.
Definition: shared_ptr.hh:44
A reference counting smart pointer.
Definition: shared_ptr.hh:63
shared_ptr & operator=(const shared_ptr< T1 > &pointer)
Assignment operator.
void swap(shared_ptr &other)
Swap content of this shared_ptr and another.
Definition: shared_ptr.hh:343
shared_ptr< T > make_shared(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5, const Arg6 &arg6, const Arg7 &arg7, const Arg8 &arg8, const Arg9 &arg9)
Definition: shared_ptr.hh:450
virtual ~SharedCount()
Destructor, deletes element_type* rep_.
Definition: shared_ptr.hh:52
element_type * operator->()
Dereference as pointer.
Definition: shared_ptr.hh:319
void operator()(T *) const
Definition: shared_ptr.hh:490
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Convert a stack-allocated object to a shared_ptr:
Definition: shared_ptr.hh:502
T element_type
The data type we are a pointer for.
Definition: shared_ptr.hh:73
shared_ptr< T > make_shared()
Definition: shared_ptr.hh:387
implements the Deleter concept of shared_ptr without deleting anything
Definition: shared_ptr.hh:488