1 #ifndef __FASTJET_SHARED_PTR_HH__ 
    2 #define __FASTJET_SHARED_PTR_HH__ 
   34 #include "fastjet/internal/base.hh" 
   41 #ifdef __FASTJET_USETR1SHAREDPTR 
   43 #endif // __FASTJET_USETR1SHAREDPTR 
   45 FASTJET_BEGIN_NAMESPACE      
 
   47 #ifdef __FASTJET_USETR1SHAREDPTR 
   68 class SharedPtr : 
public std::tr1::shared_ptr<T> {
 
   70   SharedPtr() : 
std::tr1::shared_ptr<T>() {}
 
   71   SharedPtr(T * t) : 
std::tr1::shared_ptr<T>(t) {}
 
   72   SharedPtr(
const SharedPtr<T> & t) : 
std::tr1::shared_ptr<T>(t) {}
 
   74   inline operator bool()
 const {
return (this->
get()!=NULL);}
 
   76   T* operator ()()
 const{
 
   82 #else // __FASTJET_USETR1SHAREDPTR 
  119   class __SharedCountingPtr;
 
  127     _ptr = 
new __SharedCountingPtr(ptr);
 
  133     if (_ptr!=NULL) ++(*_ptr);
 
  150     if (_ptr==NULL) 
return;
 
  165   template<
class Y> 
void reset(Y * ptr){
 
  186       if (_ptr == share._get_container()) 
return;
 
  194     _ptr = share._get_container();  
 
  196     if (_ptr!=NULL) ++(*_ptr);
 
  214   T* operator ()()
 const{
 
  215     if (_ptr==NULL) 
return NULL;
 
  226     return *(_ptr->get());
 
  236     if (_ptr==NULL) 
return NULL;
 
  241   inline T* 
get() 
const{
 
  242     if (_ptr==NULL) 
return NULL;
 
  248     return (use_count()==1);
 
  253     if (_ptr==NULL) 
return 0;
 
  254     return _ptr->use_count(); 
 
  259   inline operator bool()
 const{
 
  260     return (
get()!=NULL);
 
  265     __SharedCountingPtr* share_container = share._ptr;
 
  267     _ptr = share_container;
 
  273     if (_ptr==NULL) 
return;
 
  274     _ptr->set_count(count);
 
  287   class __SharedCountingPtr{
 
  290     __SharedCountingPtr() : _ptr(NULL), _count(0){}
 
  293     template<
class Y> 
explicit __SharedCountingPtr(Y* ptr) : _ptr(ptr), _count(1){}
 
  296     ~__SharedCountingPtr(){ 
 
  298       if (_ptr!=NULL){ 
delete _ptr;}
 
  302     inline T* 
get() 
const {
return _ptr;}
 
  305     inline long use_count()
 const {
return _count;}
 
  308     inline long operator++(){
return ++_count;}
 
  311     inline long operator--(){
return --_count;}
 
  316     inline long operator++(
int){
return _count++;}
 
  321     inline long operator--(
int){
return _count--;}
 
  325     void set_count(
const long & count){
 
  336   inline __SharedCountingPtr* _get_container()
 const{
 
  350   void _decrease_count(){
 
  355     if (_ptr->use_count()==0)
 
  360   __SharedCountingPtr *_ptr;
 
  365 template<
class T,
class U>
 
  367   return t.get() == u.get();
 
  371 template<
class T,
class U>
 
  373   return t.get() != u.get();
 
  377 template<
class T,
class U>
 
  379   return t.
get() < u.get();
 
  394 #endif // __FASTJET_USETR1SHAREDPTR 
  396 FASTJET_END_NAMESPACE      
 
  398 #endif   // __FASTJET_SHARED_PTR_HH__ 
T * get_pointer(SharedPtr< T > const &t)
getting the pointer 
 
long use_count() const 
return the number of counts 
 
SharedPtr & operator=(SharedPtr< Y > const &share)
overload the = operator so that it updates count 
 
SharedPtr(SharedPtr const &share)
overload the copy ctor so that it updates count 
 
void reset(Y *ptr)
reset from a pointer 
 
void reset(SharedPtr< Y > const &share)
do a smart copy 
 
bool operator==(const PseudoJet &a, const PseudoJet &b)
returns true if the 4 momentum components of the two PseudoJets are identical and all the internal in...
 
T & operator*() const 
indirection, get a reference to the stored pointer 
 
void swap(SharedPtr &share)
exchange the content of the two pointers 
 
SharedPtr(Y *ptr)
initialise with the main data 
 
an implementation of C++0x shared pointers (or boost's) 
 
bool operator!=(const PseudoJet &a, const PseudoJet &b)
inequality test which is exact opposite of operator== 
 
void swap(SharedPtr< T > &a, SharedPtr< T > &b)
swapping 
 
T * operator->() const 
indirection, get the stored pointer 
 
SharedPtr & operator=(SharedPtr const &share)
overload the = operator so that it updates count 
 
bool unique() const 
check if the instance is unique 
 
T * get() const 
get the stored pointer 
 
void set_count(const long &count)
force the count to be set to a specified value 
 
void reset()
reset the pointer to default value (NULL)