1 #ifndef __FASTJET_SHARED_PTR_HH__
2 #define __FASTJET_SHARED_PTR_HH__
32 #include "fastjet/internal/base.hh"
39 #ifdef USETR1SHAREDPTR
41 #endif // USETR1SHAREDPTR
43 FASTJET_BEGIN_NAMESPACE
45 #ifdef USETR1SHAREDPTR
66 class SharedPtr :
public std::tr1::shared_ptr<T> {
68 SharedPtr() : std::tr1::shared_ptr<T>() {}
69 SharedPtr(T * t) : std::tr1::shared_ptr<T>(t) {}
70 SharedPtr(
const SharedPtr<T> & t) : std::tr1::shared_ptr<T>(t) {}
72 inline operator bool()
const {
return (this->
get()!=NULL);}
74 T* operator ()()
const{
80 #else // USETR1SHAREDPTR
125 _ptr =
new __SharedCountingPtr(ptr);
131 if (_ptr!=NULL) ++(*_ptr);
148 if (_ptr==NULL)
return;
163 template<
class Y>
void reset(Y * ptr){
184 if (_ptr == share._get_container())
return;
192 _ptr = share._get_container();
194 if (_ptr!=NULL) ++(*_ptr);
212 T* operator ()()
const{
213 if (_ptr==NULL)
return NULL;
224 return *(_ptr->get());
234 if (_ptr==NULL)
return NULL;
239 inline T*
get()
const{
240 if (_ptr==NULL)
return NULL;
246 return (use_count()==1);
251 if (_ptr==NULL)
return 0;
252 return _ptr->use_count();
257 inline operator bool()
const{
258 return (
get()!=NULL);
263 __SharedCountingPtr* share_container = share._ptr;
265 _ptr = share_container;
271 if (_ptr==NULL)
return;
272 _ptr->set_count(count);
296 if (_ptr!=NULL){
delete _ptr;}
300 inline T*
get()
const {
return _ptr;}
334 inline __SharedCountingPtr* _get_container()
const{
348 void _decrease_count(){
353 if (_ptr->use_count()==0)
358 __SharedCountingPtr *_ptr;
363 template<
class T,
class U>
365 return t.get() == u.get();
369 template<
class T,
class U>
371 return t.get() != u.get();
375 template<
class T,
class U>
377 return t.
get() < u.get();
392 #endif // USETR1SHAREDPTR
394 FASTJET_END_NAMESPACE
396 #endif // __FASTJET_SHARED_PTR_HH__