NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
ef_handle.h
1#ifndef NW4R_EF_HANDLE_H
2#define NW4R_EF_HANDLE_H
3#include <nw4r/ef/ef_linkedobject.h>
4#include <nw4r/ef/ef_referencedobject.h>
5#include <nw4r/ef/ef_types.h>
6
7namespace nw4r {
8namespace ef {
9
10class HandleBase {
11private:
12 ulong mObjectID; // at 0x0
13 LinkedObject* mObject; // at 0x4
14
15public:
16 HandleBase();
17 HandleBase(const HandleBase& rOther);
18 HandleBase(LinkedObject* pObject);
19
20 HandleBase& operator=(const HandleBase& rOther);
21 HandleBase& operator=(LinkedObject* pObject);
22
23 bool IsValid() const;
24 LinkedObject* GetPtr() const;
25};
26
27template <typename T> class Handle : public HandleBase {
28public:
29 Handle() {}
30 Handle(const Handle& rOther) : HandleBase(rOther) {}
31 Handle(T* pObject) : HandleBase(static_cast<LinkedObject*>(pObject)) {}
32
33 Handle& operator=(T* pObject) {
34 *this = static_cast<LinkedObject*>(pObject);
35 }
36
37 bool IsAlive() const {
38 ReferencedObject::LifeStatus status = GetLifeStatus();
39
40 return status == ReferencedObject::NW4R_EF_LS_ACTIVE ||
41 status == ReferencedObject::NW4R_EF_LS_WAIT;
42 }
43
44 T* GetPtr() const {
45 return static_cast<T*>(HandleBase::GetPtr());
46 }
47
48 ReferencedObject::LifeStatus GetLifeStatus() const {
49 T* pObject = static_cast<T*>(HandleBase::GetPtr());
50
51 if (pObject == NULL) {
52 return ReferencedObject::NW4R_EF_LS_CLOSED;
53 }
54
55 return pObject->GetLifeStatus();
56 }
57};
58
59} // namespace ef
60} // namespace nw4r
61
62#endif