2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 17:07:41 +00:00

TLockedToken cached pointer

This commit is contained in:
Jack Andersen
2016-02-07 19:10:17 -10:00
parent 259eb89b00
commit 718436d2a6
6 changed files with 77 additions and 31 deletions

View File

@@ -202,7 +202,7 @@ public:
}
};
template<class T>
template <class T>
class TToken : public CToken
{
public:
@@ -212,17 +212,21 @@ public:
}
TToken() = default;
TToken(const CToken& other) : CToken(other) {}
TToken(CToken&& other) : CToken(std::move(other)) {}
TToken(T* obj)
: CToken(GetIObjObjectFor(std::unique_ptr<T>(obj))) {}
TToken& operator=(T* obj) {*this = CToken(GetIObjObjectFor(obj)); return this;}
T* GetObj() {return static_cast<TObjOwnerDerivedFromIObj<T>*>(CToken::GetObj())->GetObj();}
};
template<class T>
template <class T>
class TLockedToken : public TToken<T>
{
T* m_obj;
public:
TLockedToken(const CToken& other) : TToken<T>(other) {CToken::Lock();}
TLockedToken(const CToken& other) : TToken<T>(other) {m_obj = TToken<T>::GetObj();}
TLockedToken(CToken&& other) : TToken<T>(std::move(other)) {m_obj = TToken<T>::GetObj();}
T* GetObj() {return m_obj;}
};
}