24 return --m_refcount<=0;
33 virtual int Release();
46 mutable int m_refcount;
70 weak_ref_object(T* pWatchedObject) : m_watched_object(pWatchedObject){};
74 inline bool expired()
const 76 return m_watched_object ==
nullptr;
78 inline bool IsValid()
const 80 return m_watched_object !=
nullptr;
84 inline T*
get()
const {
return m_watched_object; }
85 inline operator T* () {
return m_watched_object; }
89 m_watched_object =
nullptr;
104 template<
class RealT,
class DefaultPo
interClass = RealT>
131 static_assert(std::is_convertible<Y*, RealT*>::value,
"Invalid Type for ParaEngine::weak_ptr!");
133 px = p->GetWeakReference().get_weak_ref_object();
147 if (px != r.get_weak_ref_object())
151 px = r.get_weak_ref_object();
158 weak_ptr& operator=(WeakRefObject_type * r)
175 static_assert(std::is_convertible<Y*, RealT*>::value,
"Invalid Type for ParaEngine::weak_ptr!");
182 px = r ? r->GetWeakReference().get_weak_ref_object() : 0;
196 static_assert(std::is_convertible<Y*, RealT*>::value,
"Invalid Type for ParaEngine::weak_ptr!");
200 DefaultPointerClass& operator* ()
const 202 PE_ASSERT(px != 0 && (*px).get()!=0);
203 return *((*px).get());
206 DefaultPointerClass * operator-> ()
const 209 return (DefaultPointerClass*) ((*px).get());
212 DefaultPointerClass *
get()
const 214 return (DefaultPointerClass*) ((px != 0) ? (*px).get() :
nullptr);
217 inline WeakRefObject_type * get_weak_ref_object()
const 222 operator bool()
const 224 return px != 0 && (*px).get()!=
nullptr;
227 bool operator! ()
const 229 return px == 0 || (*px).get() ==
nullptr;
232 int use_count()
const 234 return (px != 0 && (*px).get()) ? ((*px).get())->GetRefCount() : 0;
239 return use_count() == 1;
251 inline bool operator==(
weak_ptr const & b)
const 253 return this->px == b.get_weak_ref_object();
256 inline bool operator!=(
weak_ptr const & b)
const 258 return this->px != b.get_weak_ref_object();
275 inline void UnWatch(){
281 WeakRefObject_type * px;
302 virtual void Clone(
IObject* obj)
const;
314 virtual bool Equals(
const IObject *obj)
const;
315 virtual const IType* GetType()
const {
return nullptr; };
316 virtual std::string ToString()
const;
319 WeakPtr_type& GetWeakReference();
328 WeakPtr_type m_weak_reference;
IType is for type information and validating It contains type information of an object.
Definition: Type.h:75
weak_ptr & operator=(Y *r)
Y must be derived class of RealT.
Definition: PERef.h:173
event that can be passed to scene object
Definition: ObjectEvent.h:6
Base class for a reference counted asset.
Definition: PERef.h:55
different physics engine has different winding order.
Definition: EventBinding.h:32
bool delref() const
decrease reference count of the object.
Definition: PERef.h:22
virtual int ProcessObjectEvent(const ObjectEvent &event)
this function is only used to backward compatibility of ParaObject:AddEvent() function.
Definition: PERef.h:322
DONOT use this class directly, use weak_ptr instead.
Definition: PERef.h:66
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
weak reference ptr use in a class like this: weak_ptr<CRefCounted> p; e.g.
Definition: PERef.h:105
weak_ptr(Y *p)
Y must be derived class of RealT.
Definition: PERef.h:129
void addref() const
add reference count of the object.
Definition: PERef.h:15
void UnWatch()
this is usually called in the destructor of type T, so that we know that the pointer is invalid...
Definition: PERef.h:88
int GetRefCount() const
get the reference count
Definition: PERef.h:27