10 #if FE_CODEGEN<=FE_DEBUG 11 #define FE_PTR_NULL_CHECK TRUE 13 #define FE_PTR_NULL_CHECK FALSE 16 #define FE_PTR_STACK_CHECK FE_CHECK_HEAP 18 #if FE_CODEGEN<FE_DEBUG 19 #define FE_PTR_TRACK TRUE 21 #define FE_PTR_TRACK FALSE 24 #define FE_PTR_DEBUG FALSE 29 template<
typename T>
class hp;
56 sp(
void): m_tPtr(NULL) {}
58 explicit sp(T* pT): m_tPtr(pT)
60 #if FE_PTR_STACK_CHECK 61 if(pT && !Memory::isHeapOrCannotTell(pT))
62 feX((
"fe::sp< "+FE_TYPESTRING(T)+
" >::sp").c_str(),
63 "attempt to reference stack value");
73 rspT.m_tPtr->acquire();
79 sp(
const sp<X>& rspX): m_tPtr(NULL)
83 sp(
const hp<X>& rhpX): m_tPtr(NULL)
84 { operator=(rhpX.
object()); }
97 sp<T> &operator=(T* pT)
101 #if FE_PTR_STACK_CHECK 102 if(pT && !Memory::isHeapOrCannotTell(pT))
104 feX((
"fe::sp< "+FE_TYPESTRING(T)+
105 " >::operator=").c_str(),
106 "attempt to reference stack value");
122 if(rspT.raw() != raw())
125 rspT.m_tPtr->acquire();
129 m_tPtr = rspT.m_tPtr;
139 T* pT=fe_cast<T>(rspX.raw());
141 if(!pT && rspX.raw())
143 feLog(
"[33m>> sp<%s> could not convert %p" 144 " from \"%s\" [0m\n",
145 FE_TYPESTRING(T).c_str(),
147 FE_TYPESTRING(X).c_str());
150 return operator=(pT);
152 return operator=(fe_cast<T>(rspX.raw()));
159 return (fe_cast<X>(raw()) != NULL);
175 #if FE_PTR_NULL_CHECK 177 feX((
"fe::sp< "+FE_TYPESTRING(T)+
178 " >::operator*").c_str(),
179 "attempt to dereference invalid sp<>");
186 const T& operator*(
void)
const 188 #if FE_PTR_NULL_CHECK 190 feX((
"fe::sp< "+FE_TYPESTRING(T)+
191 " >::operator*").c_str(),
192 "attempt to dereference invalid sp<>");
198 T* operator->(
void)
const 200 #if FE_PTR_NULL_CHECK 202 feX((
"fe::sp< "+FE_TYPESTRING(T)+
203 " >::operator->").c_str(),
204 (
"attempt to use invalid sp<"+
205 FE_TYPESTRING(T)+
">").c_str());
211 const T* asConst(
void)
const 213 #if FE_PTR_NULL_CHECK 215 feX((
"fe::sp< "+FE_TYPESTRING(T)+
216 " >::asConst").c_str(),
217 (
"attempt to use invalid sp<"+
218 FE_TYPESTRING(T)+
">").c_str());
226 #if FE_PTR_NULL_CHECK 228 feX((
"fe::sp< "+FE_TYPESTRING(T)+
229 " >::abandon").c_str(),
230 (
"attempt to use invalid sp<"+
231 FE_TYPESTRING(T)+
">").c_str());
240 T* raw(
void)
const {
return m_tPtr; }
241 BWORD isValid(
void)
const {
return m_tPtr != NULL; }
242 BWORD isNull(
void)
const {
return m_tPtr == NULL; }
247 virtual void track(
void)
251 m_tPtr->trackReference(
this,
"sp<> "+m_tPtr->name());
258 m_tPtr->untrackReference(
this);
263 void untrack(
void) {}
269 template <
class T,
class X>
272 return (rspLeft.raw() ==
sp<T>(rspRight).raw());
276 template <
class T,
class X>
279 return (rspLeft.raw() !=
sp<T>(rspRight).raw());
284 template <
class T,
class X>
285 inline BWORD operator<(const sp<T>& rspLeft,
const sp<X>& rspRight)
287 return (FE_UWORD)(rspLeft.raw()) < (FE_UWORD)(
sp<T>(rspRight).raw());
293 FE_UWORD operator()(
const sp<T>& rspT)
const 294 {
return reinterpret_cast<FE_UWORD
>(rspT.raw()); }
300 bool operator()(
const sp<T>& rspT1,
const sp<T>& rspT2)
const 301 {
return rspT1 == rspT2; }
304 template<
typename T,
typename U>
305 class AutoHashMap< sp<T>, U >:
306 public HashMap< sp<T>, U, hash_sp<T>, eq_sp<T> > {};
BWORD operator!=(const sp< T > &rspLeft, const sp< X > &rspRight)
Definition: src/core/ptr.h:277
kernel
Definition: namespace.dox:3
BWORD operator==(const sp< T > &rspLeft, const sp< X > &rspRight)
Definition: src/core/ptr.h:270
sp< T > object(void) const
Returns a smart pointer of the same templated type.
Definition: Handled.h:176
Safe handle for shared pointer.
Definition: Handled.h:61
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53