DGtal  1.5.beta
DGtal::OwningOrAliasingPtr< T > Class Template Reference

Aim: This class describes a smart pointer that is, given the constructor called by the user, either an alias pointer on existing data or an owning pointer on a copy. More...

#include <DGtal/base/OwningOrAliasingPtr.h>

Inheritance diagram for DGtal::OwningOrAliasingPtr< T >:
[legend]

Public Types

typedef T Value
 
typedef T * Pointer
 
typedef T & Reference
 

Public Member Functions

 OwningOrAliasingPtr (const T &aValue)
 
 OwningOrAliasingPtr (Pointer aPtr, bool isOwning=false)
 
 OwningOrAliasingPtr (const OwningOrAliasingPtr &other)
 
OwningOrAliasingPtroperator= (const OwningOrAliasingPtr &other)
 
 ~OwningOrAliasingPtr ()
 
Pointer operator-> () const
 
Pointer get () const
 
Reference operator* () const
 
bool isOwning () const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Private Member Functions

 BOOST_CONCEPT_ASSERT ((boost::CopyConstructible< T >))
 

Private Attributes

Pointer myPtr
 
bool myFlagIsOwning
 

Detailed Description

template<typename T>
class DGtal::OwningOrAliasingPtr< T >

Aim: This class describes a smart pointer that is, given the constructor called by the user, either an alias pointer on existing data or an owning pointer on a copy.

Description of template class 'OwningOrAliasingPtr'

Such a pointer may be used for a (big) member of class, which can be either given at construction (aliasing pointer) or default-constructed (owning pointer).

Such a pointer may be also used to make the user be able to decide whether the data should be copied (owning pointer) or not (aliasing pointer).

Obviously, the data are free'd at destruction in the case of an owning pointer.

Template Parameters
Ta model of boost::CopyConstructible

Definition at line 72 of file OwningOrAliasingPtr.h.

Member Typedef Documentation

◆ Pointer

template<typename T >
typedef T* DGtal::OwningOrAliasingPtr< T >::Pointer

Definition at line 80 of file OwningOrAliasingPtr.h.

◆ Reference

template<typename T >
typedef T& DGtal::OwningOrAliasingPtr< T >::Reference

Definition at line 81 of file OwningOrAliasingPtr.h.

◆ Value

template<typename T >
typedef T DGtal::OwningOrAliasingPtr< T >::Value

Definition at line 79 of file OwningOrAliasingPtr.h.

Constructor & Destructor Documentation

◆ OwningOrAliasingPtr() [1/3]

template<typename T >
DGtal::OwningOrAliasingPtr< T >::OwningOrAliasingPtr ( const T &  aValue)

Constructor with copy.

Parameters
aValuevalue, myPtr owns a copy of which.

◆ OwningOrAliasingPtr() [2/3]

template<typename T >
DGtal::OwningOrAliasingPtr< T >::OwningOrAliasingPtr ( Pointer  aPtr,
bool  isOwning = false 
)

Constructor without copy.

Parameters
aPtrany pointer assigned to myPtr
isOwning'true' if myPtr must be an owning pointer 'false' if myPtr must be only an alias (default).

◆ OwningOrAliasingPtr() [3/3]

template<typename T >
DGtal::OwningOrAliasingPtr< T >::OwningOrAliasingPtr ( const OwningOrAliasingPtr< T > &  other)

Copy constructor.

Parameters
otherthe object to clone.

◆ ~OwningOrAliasingPtr()

template<typename T >
DGtal::OwningOrAliasingPtr< T >::~OwningOrAliasingPtr ( )

Destructor.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT()

template<typename T >
DGtal::OwningOrAliasingPtr< T >::BOOST_CONCEPT_ASSERT ( (boost::CopyConstructible< T >)  )
private

◆ get()

template<typename T >
Pointer DGtal::OwningOrAliasingPtr< T >::get ( ) const

Access to the underlying pointer.

Returns
the pointer.

Referenced by testOwningOrAliasingPtr().

◆ isOwning()

template<typename T >
bool DGtal::OwningOrAliasingPtr< T >::isOwning ( ) const

Tells whether the pointer owns the data or not.

Returns
boolean equal to 'true' if myPtr owns the data 'false' otherwise.

Referenced by testOwningOrAliasingPtr().

◆ isValid()

template<typename T >
bool DGtal::OwningOrAliasingPtr< T >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Referenced by testOwningOrAliasingPtr().

◆ operator*()

template<typename T >
Reference DGtal::OwningOrAliasingPtr< T >::operator* ( ) const

Dereferencement.

Returns
the data.

◆ operator->()

template<typename T >
Pointer DGtal::OwningOrAliasingPtr< T >::operator-> ( ) const

Indirection.

Returns
the pointer.

◆ operator=()

template<typename T >
OwningOrAliasingPtr& DGtal::OwningOrAliasingPtr< T >::operator= ( const OwningOrAliasingPtr< T > &  other)

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.

◆ selfDisplay()

template<typename T >
void DGtal::OwningOrAliasingPtr< T >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Field Documentation

◆ myFlagIsOwning

template<typename T >
bool DGtal::OwningOrAliasingPtr< T >::myFlagIsOwning
private

Boolean that is equal to 'true' if myPtr owns the data 'false' otherwise

Definition at line 172 of file OwningOrAliasingPtr.h.

◆ myPtr

template<typename T >
Pointer DGtal::OwningOrAliasingPtr< T >::myPtr
private

Owning or aliasing pointer to the data

Definition at line 166 of file OwningOrAliasingPtr.h.


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