DAS  3.0
Das Analysis System
SharedPtr< T >

#include <fjcore.hh>

+ Collaboration diagram for SharedPtr< T >:

Classes

class  __SharedCountingPtr
 

Public Member Functions

 SharedPtr ()
 
template<class Y >
 SharedPtr (Y *ptr)
 
 SharedPtr (SharedPtr const &share)
 
 ~SharedPtr ()
 
void reset ()
 
template<class Y >
void reset (Y *ptr)
 
template<class Y >
void reset (SharedPtr< Y > const &share)
 
SharedPtroperator= (SharedPtr const &share)
 
template<class Y >
SharedPtroperator= (SharedPtr< Y > const &share)
 
T * operator() () const
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 
bool unique () const
 
long use_count () const
 
 operator bool () const
 
void swap (SharedPtr &share)
 
void set_count (const long &count)
 

Private Member Functions

__SharedCountingPtr_get_container () const
 
void _decrease_count ()
 

Private Attributes

__SharedCountingPtr_ptr
 

Constructor & Destructor Documentation

◆ SharedPtr() [1/3]

SharedPtr ( )
inline
297 : _ptr(NULL){}

◆ SharedPtr() [2/3]

SharedPtr ( Y *  ptr)
inlineexplicit
298  {
299  _ptr = new __SharedCountingPtr(ptr);
300  }

◆ SharedPtr() [3/3]

SharedPtr ( SharedPtr< T > const &  share)
inline
301  : _ptr(share._get_container()){
302  if (_ptr!=NULL) ++(*_ptr);
303  }

◆ ~SharedPtr()

~SharedPtr ( )
inline
304  {
305  if (_ptr==NULL) return;
306  _decrease_count();
307  }

Member Function Documentation

◆ _decrease_count()

void _decrease_count ( )
inlineprivate
392  {
393  (*_ptr)--;
394  if (_ptr->use_count()==0)
395  delete _ptr; // that automatically deletes the object itself
396  }

◆ _get_container()

__SharedCountingPtr* _get_container ( ) const
inlineprivate
389  {
390  return _ptr;
391  }

◆ get()

T* get ( ) const
inline
342  {
343  if (_ptr==NULL) return NULL;
344  return _ptr->get();
345  }

◆ operator bool()

operator bool ( ) const
inline
356  {
357  return (get()!=NULL);
358  }

◆ operator()()

T* operator() ( ) const
inline
331  {
332  if (_ptr==NULL) return NULL;
333  return _ptr->get(); // automatically returns NULL when out-of-scope
334  }

◆ operator*()

T& operator* ( ) const
inline
335  {
336  return *(_ptr->get());
337  }

◆ operator->()

T* operator-> ( ) const
inline
338  {
339  if (_ptr==NULL) return NULL;
340  return _ptr->get();
341  }

◆ operator=() [1/2]

SharedPtr& operator= ( SharedPtr< T > const &  share)
inline
322  {
323  reset(share);
324  return *this;
325  }

◆ operator=() [2/2]

SharedPtr& operator= ( SharedPtr< Y > const &  share)
inline
326  {
327  reset(share);
328  return *this;
329  }

◆ reset() [1/3]

void reset ( )
inline
308  {
309  SharedPtr().swap(*this);
310  }

◆ reset() [2/3]

void reset ( SharedPtr< Y > const &  share)
inline
314  {
315  if (_ptr!=NULL){
316  if (_ptr == share._get_container()) return;
317  _decrease_count();
318  }
319  _ptr = share._get_container(); // Note: automatically set it to NULL if share is empty
320  if (_ptr!=NULL) ++(*_ptr);
321  }

◆ reset() [3/3]

void reset ( Y *  ptr)
inline
311  {
312  SharedPtr(ptr).swap(*this);
313  }

◆ set_count()

void set_count ( const long &  count)
inline
364  {
365  if (_ptr==NULL) return;
366  _ptr->set_count(count);
367  }

◆ swap()

void swap ( SharedPtr< T > &  share)
inline
359  {
360  __SharedCountingPtr* share_container = share._ptr;
361  share._ptr = _ptr;
362  _ptr = share_container;
363  }

◆ unique()

bool unique ( ) const
inline
346  {
347  return (use_count()==1);
348  }

◆ use_count()

long use_count ( ) const
inline
349  {
350  if (_ptr==NULL) return 0;
351  return _ptr->use_count(); // automatically returns NULL when out-of-scope
352  }

Member Data Documentation

◆ _ptr

__SharedCountingPtr* _ptr
private

The documentation for this class was generated from the following file:
SharedPtr::_decrease_count
void _decrease_count()
Definition: fjcore.hh:392
SharedPtr::__SharedCountingPtr::set_count
void set_count(const long &count)
Definition: fjcore.hh:381
SharedPtr::_ptr
__SharedCountingPtr * _ptr
Definition: fjcore.hh:397
SharedPtr::__SharedCountingPtr::use_count
long use_count() const
Definition: fjcore.hh:376
SharedPtr::SharedPtr
SharedPtr()
Definition: fjcore.hh:297
SharedPtr::get
T * get() const
Definition: fjcore.hh:342
SharedPtr::reset
void reset()
Definition: fjcore.hh:308
SharedPtr::__SharedCountingPtr::get
T * get() const
Definition: fjcore.hh:375
SharedPtr::_get_container
__SharedCountingPtr * _get_container() const
Definition: fjcore.hh:389
SharedPtr::use_count
long use_count() const
Definition: fjcore.hh:349