9 #ifndef _fei_SharedPtr_hpp_
10 #define _fei_SharedPtr_hpp_
12 #include <fei_macros.hpp>
65 template<
typename T>
class SharedPtr {
84 explicit SharedPtr(T* p)
111 #if !defined( FEI_NO_MEMBER_TEMPLATES )
122 SharedPtr(
const SharedPtr<Y>& x)
125 ++*(count = x.count);
145 SharedPtr&
operator=(
const SharedPtr<Y>& x) {
146 share(x.pointer,x.count);
149 #endif // FEI_NO_MEMBER_TEMPLATES
160 SharedPtr(
const SharedPtr& x)
163 ++*(count = x.count);
181 SharedPtr&
operator=(
const SharedPtr& x) {
182 share(x.pointer, x.count);
204 if ( pointer == p )
return;
228 T&
operator*()
const {
return *pointer; }
242 T*
get()
const {
return pointer; }
250 long use_count()
const {
return *count; }
258 bool unique()
const {
return *count == 1; }
261 void share(T* xpointer,
long* xcount) {
262 if (count != xcount) {
280 #if defined( FEI_NO_MEMBER_TEMPLATES ) || !defined( FEI_NO_MEMBER_TEMPLATES )
287 #if !defined( FEI_NO_MEMBER_TEMPLATES ) && !defined( FEI_NO_MEMBER_TEMPLATES )
288 template<
typename Y>
friend class SharedPtr;
296 template<
typename T,
typename U>
297 inline bool operator==(
const SharedPtr<T>& a,
const SharedPtr<U>& b)
298 {
return a.get() == b.get(); }
303 template<
typename T,
typename U>
304 inline bool operator!=(
const SharedPtr<T>& a,
const SharedPtr<U>& b)
305 {
return a.get() != b.get(); }
309 #endif // _fei_SharedPtr_hpp_
void share(T *xpointer, long *xcount)
bool operator==(const SharedPtr< T > &a, const SharedPtr< U > &b)
SharedPtr & operator=(const SharedPtr< Y > &x)
bool operator!=(const SharedPtr< T > &a, const SharedPtr< U > &b)