TResPtr: Use in-class initializers where applicable

This commit is contained in:
Lioncash 2020-06-11 13:14:33 -04:00
parent 11f156352a
commit 9925925b6f
1 changed files with 8 additions and 11 deletions

View File

@ -6,20 +6,17 @@
template <typename ResType> template <typename ResType>
class TResPtr class TResPtr
{ {
ResType *mpRes; ResType *mpRes = nullptr;
public: public:
TResPtr() constexpr TResPtr() = default;
: mpRes(nullptr) {}
TResPtr(void *pPtr) TResPtr(void *pPtr)
: mpRes(nullptr)
{ {
*this = pPtr; *this = pPtr;
} }
TResPtr(const TResPtr<ResType>& rkSource) TResPtr(const TResPtr<ResType>& rkSource)
: mpRes(nullptr)
{ {
*this = rkSource; *this = rkSource;
} }
@ -30,7 +27,7 @@ public:
mpRes->Release(); mpRes->Release();
} }
inline void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
CAssetID ID = (mpRes && !rArc.IsReader() ? mpRes->ID() : CAssetID::InvalidID(rArc.Game())); CAssetID ID = (mpRes && !rArc.IsReader() ? mpRes->ID() : CAssetID::InvalidID(rArc.Game()));
rArc.SerializePrimitive(ID, 0); rArc.SerializePrimitive(ID, 0);
@ -42,29 +39,29 @@ public:
} }
} }
inline void Delete() void Delete()
{ {
// use with caution! this function exists because not all resources are cached currently // use with caution! this function exists because not all resources are cached currently
delete mpRes; delete mpRes;
mpRes = nullptr; mpRes = nullptr;
} }
inline ResType* RawPointer() const ResType* RawPointer() const
{ {
return mpRes; return mpRes;
} }
inline operator ResType*() const operator ResType*() const
{ {
return mpRes; return mpRes;
} }
inline ResType& operator*() const ResType& operator*() const
{ {
return *mpRes; return *mpRes;
} }
inline ResType* operator->() const ResType* operator->() const
{ {
return mpRes; return mpRes;
} }