DGtal 2.1.0
Loading...
Searching...
No Matches
DGtal::NClone< T > Class Template Reference

Public Member Functions

 ~NClone ()
 
 NClone (const NClone &)
 
 NClone (const T &t)
 
 NClone (CountedPtr< T > ptr)
 
 NClone (CowPtr< T > ptr)
 
 operator T () const
 
 operator CowPtr< T > () const
 

Private Member Functions

 NClone ()
 
NCloneoperator= (const NClone &other)
 

Private Attributes

CowPtr< T > myCowPtr
 The copy-on-write pointer to the T object that is to be duplicated.
 

Detailed Description

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

Tentative Clone. Performs without unnecessary duplicates "parameter -> member data"

  • const A & -> A
  • const A & -> CowPtr
  • CowPtr -> A
  • CowPtr -> CowPtr It uses an intermediate CowPtr, which forces dynamic allocation. This slows down too much for small objects.

Definition at line 62 of file testClone2.cpp.

Constructor & Destructor Documentation

◆ ~NClone()

template<typename T >
DGtal::NClone< T >::~NClone ( )
inline

Destructor. Does nothing.

Definition at line 70 of file testClone2.cpp.

70{}

◆ NClone() [1/5]

template<typename T >
DGtal::NClone< T >::NClone ( const NClone< T > &  )
inline

Copy constructor. Invalid.

Definition at line 75 of file testClone2.cpp.

75{ ASSERT( false ); }

◆ NClone() [2/5]

template<typename T >
DGtal::NClone< T >::NClone ( const T &  t)
inline

Constructor from an instance of T. The object is referenced in 'this' and is generally immediately duplicated by the user to instantiate a data member.

Parameters
tany object of type T.

Definition at line 83 of file testClone2.cpp.

83: myCowPtr( const_cast<T*>( &t ) ) {}
CowPtr< T > myCowPtr
The copy-on-write pointer to the T object that is to be duplicated.

◆ NClone() [3/5]

template<typename T >
DGtal::NClone< T >::NClone ( CountedPtr< T >  ptr)
inline

Constructor from a pointer to a valid instance of T. The object is referenced in 'this' and is generally immediately duplicated by the user to instantiate a data member.

Parameters
ptrany valid pointer to a object of type T.
Precondition
ptr != 0

Definition at line 92 of file testClone2.cpp.

92: myCowPtr( ptr ) {}

◆ NClone() [4/5]

template<typename T >
DGtal::NClone< T >::NClone ( CowPtr< T >  ptr)
inline

Definition at line 93 of file testClone2.cpp.

93: myCowPtr( ptr ) {}

◆ NClone() [5/5]

template<typename T >
DGtal::NClone< T >::NClone ( )
private

Constructor. Forbidden.

Member Function Documentation

◆ operator CowPtr< T >()

template<typename T >
DGtal::NClone< T >::operator CowPtr< T > ( ) const
inline

Cast operator to a CowPtr<T> instance. If the clone was initialized with an This is only at this moment that the object is duplicated (and only once). This allows things like: CountedPtr a2 = a1; where a1 is of type NClone. It also allows CowPtr a2 = a1;

Definition at line 112 of file testClone2.cpp.

113 { return myCowPtr.unique()
114 ? CowPtr<T>( new T( *( const_cast< CowPtr<T>& >( myCowPtr ).drop() ) ) )
115 : myCowPtr;
116 }
Aim: Copy on write shared pointer.
Definition CowPtr.h:68

References DGtal::NClone< T >::myCowPtr, and DGtal::CowPtr< T >::unique().

◆ operator T()

template<typename T >
DGtal::NClone< T >::operator T ( ) const
inline

Cast operator to a T instance. This is only at this moment that the object is duplicated. This allows things like: A a2 = a1; where a1 is of type NClone.

Definition at line 100 of file testClone2.cpp.

101 { return myCowPtr.unique()
102 ? T( *( const_cast< CowPtr<T>& >( myCowPtr ).drop() ) )
103 : T( *( myCowPtr.get() ) );
104 }

References DGtal::NClone< T >::myCowPtr.

◆ operator=()

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

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden (otherwise the user might be tempted to use it as a member).

Field Documentation

◆ myCowPtr

template<typename T >
CowPtr<T> DGtal::NClone< T >::myCowPtr
private

The copy-on-write pointer to the T object that is to be duplicated.

Definition at line 126 of file testClone2.cpp.

Referenced by DGtal::NClone< T >::operator CowPtr< T >(), and DGtal::NClone< T >::operator T().


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