dune-common  2.2.1
Classes | Public Types | Public Member Functions | Friends | Related Functions | List of all members
Dune::shared_ptr< T > Class Template Reference

A reference counting smart pointer. More...

#include <dune/common/shared_ptr.hh>

Inheritance diagram for Dune::shared_ptr< T >:
Inheritance graph

Classes

struct  DefaultDeleter
 A default deleter that just calls delete.
class  SharedCountImpl
 Adds call to deleter to SharedCount.

Public Types

typedef T element_type
 The data type we are a pointer for.

Public Member Functions

 shared_ptr ()
 Constructs a new smart pointer and allocates the referenced Object.
 shared_ptr (nullptr_t null)
template<class T1 >
 shared_ptr (T1 *pointer)
 Constructs a new smart pointer from a preallocated Object.
template<class T1 , class Deleter >
 shared_ptr (T1 *pointer, Deleter deleter)
 Constructs a new smart pointer from a preallocated Object.
template<class T1 >
 shared_ptr (const shared_ptr< T1 > &pointer)
 Copy constructor.
 shared_ptr (const shared_ptr &pointer)
 Copy constructor.
 ~shared_ptr ()
 Destructor.
template<class T1 >
shared_ptroperator= (const shared_ptr< T1 > &pointer)
 Assignment operator.
shared_ptroperator= (const shared_ptr &pointer)
 Assignment operator.
element_typeoperator* ()
 Dereference as object.
element_typeoperator-> ()
 Dereference as pointer.
const element_typeoperator* () const
 Dereference as const object.
const element_typeoperator-> () const
 Dereference as const pointer.
element_typeget () const
 Access to the raw pointer, if you really want it.
 operator bool () const
 Checks if shared_ptr manages an object, i.e. whether get() != 0.
void swap (shared_ptr &other)
 Swap content of this shared_ptr and another.
void reset ()
 Decrease the reference count by one and free the memory if the reference count has reached 0.
template<class T1 >
void reset (T1 *pointer)
 Detach shared pointer and set it anew for the given pointer.
template<class T1 , class Deleter >
void reset (T1 *pointer, Deleter deleter)
int use_count () const
 The number of shared_ptrs pointing to the object we point to.
 operator __unspecified_bool_type () const
 Implicit conversion to "bool".

Friends

class shared_ptr

Related Functions

(Note that these are not member functions.)

template<typename T >
shared_ptr< T > stackobject_to_shared_ptr (T &t)
 Convert a stack-allocated object to a shared_ptr:
template<typename T , typename T2 >
shared_ptr< T2 > stackobject_to_shared_ptr (T &t)
 Convert a stack object to a shared_ptr of a base class.

Detailed Description

template<class T>
class Dune::shared_ptr< T >

A reference counting smart pointer.

It is designed such that it is usable within a std::vector. The contained object is destroyed only if there are no more references to it.

Member Typedef Documentation

template<class T>
typedef T Dune::shared_ptr< T >::element_type

The data type we are a pointer for.

This has to have a parameterless constructor.

Constructor & Destructor Documentation

template<class T>
Dune::shared_ptr< T >::shared_ptr ( )
inline

Constructs a new smart pointer and allocates the referenced Object.

Member Function Documentation

template<class T>
element_type* Dune::shared_ptr< T >::get ( ) const
inline

Access to the raw pointer, if you really want it.

Referenced by Dune::Generic_MPI_Op< Type, BinaryFunction >::get().

template<class T>
Dune::shared_ptr< T >::operator __unspecified_bool_type ( ) const
inline

Implicit conversion to "bool".

template<class T>
Dune::shared_ptr< T >::operator bool ( ) const
inline

Checks if shared_ptr manages an object, i.e. whether get() != 0.

Friends And Related Function Documentation

template<typename T >
shared_ptr< T > stackobject_to_shared_ptr ( T &  t)
related

Convert a stack-allocated object to a shared_ptr:

int i = 10;
shared_ptr<int> pi = stackobject_to_shared_ptr(i);

References t.

template<typename T , typename T2 >
shared_ptr< T2 > stackobject_to_shared_ptr ( T &  t)
related

Convert a stack object to a shared_ptr of a base class.

class A {};
class B : public A {};
...
B b;
shared_ptr<A> pa = stackobject_to_shared_ptr<A>(b);

References t.


The documentation for this class was generated from the following file: