12
NSmartPtr(const NSmartPtr& rp);
14
NSmartPtr& operator = (const NSmartPtr<T>& rp);
15
NSmartPtr& operator = (const T* rp);
17
bool operator == (const NSmartPtr<T>& rp) const;
18
bool operator == (const T* ptr) const;
19
bool operator != (const NSmartPtr<T>& rp) const;
20
bool operator != (const T* ptr) const;
21
bool operator < (const NSmartPtr<T>& rp) const;
22
bool operator < (const T* ptr) const;
23
bool operator > (const NSmartPtr<T>& rp) const;
24
bool operator > (const T* ptr) const;
27
const T& operator* () const;
29
const T* operator-> () const;
31
bool operator! () const;
32
bool IsValid () const;
34
const T* GetPtr() const;
37
void CheckReferenceCount();
42
inline NSmartPtr<T>::NSmartPtr()
47
template<class T> inline
48
NSmartPtr<T>::NSmartPtr(T* t)
58
inline NSmartPtr<T>::NSmartPtr(const NSmartPtr& rp)
68
inline NSmartPtr<T>::~NSmartPtr()
73
CheckReferenceCount();
78
inline void NSmartPtr<T>::CheckReferenceCount()
80
if(m_ptr->GetRefCount() == 0)
88
inline NSmartPtr<T>& NSmartPtr<T>::operator = (const NSmartPtr& rp)
90
// if the value to assign to the pointer is already set, just return this element
96
// decrement ref count of RefCounted previously pointed to by this pointer
100
CheckReferenceCount();
103
// copy new pointer value
106
// increment ref count of RefCounted now pointed to by this pointer
116
inline bool NSmartPtr<T>::operator == (const NSmartPtr& rp) const
118
return (m_ptr == rp.m_ptr);
122
inline bool NSmartPtr<T>::operator == (const T* ptr) const
124
return (m_ptr == ptr);
128
inline bool NSmartPtr<T>::operator != (const NSmartPtr& rp) const
130
return (m_ptr != rp.m_ptr);
134
inline bool NSmartPtr<T>::operator != (const T* ptr) const
136
return (m_ptr != ptr);
140
inline bool NSmartPtr<T>::operator < (const NSmartPtr& rp) const
142
return (m_ptr < rp.m_ptr);
146
inline bool NSmartPtr<T>::operator < (const T* ptr) const
148
return (m_ptr < ptr);
152
inline bool NSmartPtr<T>::operator > (const NSmartPtr& rp) const
154
return (m_ptr > rp.m_ptr);
158
inline bool NSmartPtr<T>::operator > (const T* ptr) const
160
return (m_ptr > ptr);
164
inline T& NSmartPtr<T>::operator * ()
170
inline const T& NSmartPtr<T>::operator * () const
176
inline T* NSmartPtr<T>::operator -> ()
182
inline const T* NSmartPtr<T>::operator -> () const
188
inline bool NSmartPtr<T>::operator ! () const
190
return (m_ptr == NULL);
194
inline bool NSmartPtr<T>::IsValid() const
196
return (m_ptr != NULL);
200
inline T* NSmartPtr<T>::GetPtr()
206
inline const T* NSmartPtr<T>::GetPtr() const
213
#endif // NSMARTPTR_H