29 #ifndef INCLUDE_SMART_PTR_HH
30 #define INCLUDE_SMART_PTR_HH
32 #ifndef SMART_PTR_USE_DEFAULT_ALLOCATOR_FOR_REF_COUNT
33 #include "FSBAllocator.hh"
38 template<
typename Data_t,
typename Allocator = std::allocator<Data_t> >
42 SmartPtr(
const Allocator& = Allocator());
43 SmartPtr(Data_t*,
const Allocator& = Allocator());
49 const Data_t* operator->()
const;
52 const Data_t& operator*()
const;
55 operator bool()
const {
return data != 0; }
56 bool isShared()
const;
66 if(refCount && --(*refCount) == 0)
68 Allocator::destroy(data);
69 Allocator::deallocate(data, 1);
71 #ifdef SMART_PTR_USE_DEFAULT_ALLOCATOR_FOR_REF_COUNT
72 typename Allocator::template
73 rebind<size_t>::other(*this).deallocate(refCount, 1);
81 template<
typename Data_t,
typename Allocator>
83 Allocator(a), data(0), refCount(0)
86 template<
typename Data_t,
typename Allocator>
88 Allocator(a), data(d),
89 #ifdef SMART_PTR_USE_DEFAULT_ALLOCATOR_FOR_REF_COUNT
90 refCount(typename Allocator::template
91 rebind<size_t>::other(*this).allocate(1))
99 template<
typename Data_t,
typename Allocator>
105 template<
typename Data_t,
typename Allocator>
107 Allocator(rhs), data(rhs.data), refCount(rhs.refCount)
109 if(refCount) ++(*refCount);
112 template<
typename Data_t,
typename Allocator>
116 if(data == rhs.data)
return *
this;
119 Allocator::operator=(rhs);
121 refCount = rhs.refCount;
122 if(refCount) ++(*refCount);
126 template<
typename Data_t,
typename Allocator>
132 template<
typename Data_t,
typename Allocator>
138 template<
typename Data_t,
typename Allocator>
144 template<
typename Data_t,
typename Allocator>
150 template<
typename Data_t,
typename Allocator>
156 template<
typename Data_t,
typename Allocator>
159 return refCount && (*refCount) > 1;