2022-08-13 01:26:00 +00:00
|
|
|
#ifndef _TTOKEN_HPP
|
|
|
|
#define _TTOKEN_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "Kyoto/CSimplePool.hpp"
|
|
|
|
#include "Kyoto/CToken.hpp"
|
|
|
|
#include "Kyoto/IObj.hpp"
|
|
|
|
|
|
|
|
#include "rstl/auto_ptr.hpp"
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TToken : public CToken {
|
|
|
|
public:
|
|
|
|
TToken() {}
|
|
|
|
TToken(const CToken& token) : CToken(token) {}
|
|
|
|
TToken(T* obj) : CToken(GetIObjObjectFor(obj).release()) {}
|
|
|
|
TToken(const rstl::auto_ptr< T >& obj) : CToken(GetIObjObjectFor(obj).release()) {}
|
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
T* GetT() { return reinterpret_cast< T* >(CToken::GetObj()->GetContents()); }
|
|
|
|
T* operator*() { return GetT(); }
|
|
|
|
|
|
|
|
static inline rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetIObjObjectFor(T* obj) {
|
2022-08-13 01:26:00 +00:00
|
|
|
return TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj);
|
|
|
|
}
|
2022-09-18 06:05:46 +00:00
|
|
|
static inline rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > >
|
|
|
|
GetIObjObjectFor(const rstl::auto_ptr< T >& obj) {
|
2022-08-13 01:26:00 +00:00
|
|
|
return TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TCachedToken : public TToken< T > {
|
|
|
|
public:
|
|
|
|
TCachedToken() {}
|
2022-09-13 04:26:54 +00:00
|
|
|
TCachedToken(const CToken& token) : TToken< T >(token), x8_item(GetT()) {}
|
2022-08-13 01:26:00 +00:00
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
T* operator*() { return x8_item; }
|
2022-08-14 18:38:41 +00:00
|
|
|
|
2022-08-13 01:26:00 +00:00
|
|
|
private:
|
|
|
|
T* x8_item;
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
2022-09-13 04:26:54 +00:00
|
|
|
class TLockedToken {
|
2022-08-13 01:26:00 +00:00
|
|
|
public:
|
|
|
|
TLockedToken() {}
|
2022-09-13 04:26:54 +00:00
|
|
|
TLockedToken(const CToken& token) : x0_token(token), x8_item(*x0_token) {}
|
2022-09-18 06:05:46 +00:00
|
|
|
TLockedToken(const TLockedToken< T >& token) : x0_token(token), x8_item(*token) {
|
|
|
|
x0_token.Lock();
|
|
|
|
}
|
2022-09-13 04:26:54 +00:00
|
|
|
|
|
|
|
TLockedToken& operator=(const TLockedToken< T >& token) {
|
|
|
|
x0_token = token;
|
|
|
|
x8_item = *token;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-08-14 18:38:41 +00:00
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
operator const TToken< T >&() const { return x0_token; }
|
|
|
|
T* operator*() const { return x8_item; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
TToken< T > x0_token;
|
|
|
|
T* x8_item;
|
2022-08-13 01:26:00 +00:00
|
|
|
};
|
|
|
|
|
2022-09-18 06:05:46 +00:00
|
|
|
#endif
|