add some class docs

This commit is contained in:
Jack Andersen 2016-02-08 19:05:36 -10:00
parent 718436d2a6
commit 69f32a4706
1 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,7 @@ namespace Retro
class IObjectStore; class IObjectStore;
class IObj; class IObj;
/** Shared data-structure for CToken references, analogous to std::shared_ptr */
class CObjectReference class CObjectReference
{ {
friend class CToken; friend class CToken;
@ -31,7 +32,10 @@ public:
CObjectReference(std::unique_ptr<IObj>&& obj) CObjectReference(std::unique_ptr<IObj>&& obj)
: x10_object(obj.release()) {} : x10_object(obj.release()) {}
/** Indicates an asynchronous load transaction has been submitted and is not yet finished */
bool IsLoading() const {return x3_loading;} bool IsLoading() const {return x3_loading;}
/** Decrements 2nd ref-count, performing unload or async-load-cancel if 0 reached */
void Unlock() void Unlock()
{ {
--x2_lockCount; --x2_lockCount;
@ -42,6 +46,8 @@ public:
else if (IsLoading()) else if (IsLoading())
CancelLoad(); CancelLoad();
} }
/** Increments 2nd ref-count, performing async-factory-load if needed */
void Lock() void Lock()
{ {
++x2_lockCount; ++x2_lockCount;
@ -52,6 +58,9 @@ public:
x3_loading = true; x3_loading = true;
} }
} }
/** Mechanism by which CToken decrements 1st ref-count, indicating CToken invalidation or reset.
* Reaching 0 indicates the CToken should delete the CObjectReference */
u16 RemoveReference() u16 RemoveReference()
{ {
--x0_refCount; --x0_refCount;
@ -73,12 +82,16 @@ public:
x3_loading = false; x3_loading = false;
} }
} }
/** Pointer-synchronized object-destructor, another building Lock cycle may be performed after */
void Unload() void Unload()
{ {
delete x10_object; delete x10_object;
x10_object = nullptr; x10_object = nullptr;
x3_loading = false; x3_loading = false;
} }
/** Synchronous object-fetch, guaranteed to return complete object on-demand, blocking build if not ready */
IObj* GetObject() IObj* GetObject()
{ {
if (!x10_object) if (!x10_object)
@ -102,11 +115,15 @@ public:
} }
}; };
/** Counted meta-object, reference-counting against a shared CObjectReference
* This class is analogous to std::shared_ptr and C++11 rvalues have been implemented accordingly
* (default/empty constructor, move constructor/assign) */
class CToken class CToken
{ {
CObjectReference* x0_objRef = nullptr; CObjectReference* x0_objRef = nullptr;
bool x4_lockHeld = false; bool x4_lockHeld = false;
public: public:
/* Added to test for non-null state */
operator bool() const {return x0_objRef != nullptr;} operator bool() const {return x0_objRef != nullptr;}
void Unlock() void Unlock()
{ {