From 578e1cbd4b704b90936a4f8adffd5385a6de4689 Mon Sep 17 00:00:00 2001 From: PliskinDev <36959936+PliskinDev@users.noreply.github.com> Date: Thu, 7 Sep 2023 23:02:43 +0300 Subject: [PATCH] add atReferenceCounter (#137) --- classes.cpp | 1 + rage/atReferenceCounter.hpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rage/atReferenceCounter.hpp diff --git a/classes.cpp b/classes.cpp index b7f5c13..a0f7c16 100644 --- a/classes.cpp +++ b/classes.cpp @@ -139,6 +139,7 @@ #include "player/CPlayerAngles.hpp" #include "player/CPlayerInfo.hpp" #include "rage/atArray.hpp" +#include "rage/atReferenceCounter.hpp" #include "rage/atSingleton.hpp" #include "rage/joaat.hpp" #include "rage/rlGamerHandle.hpp" diff --git a/rage/atReferenceCounter.hpp b/rage/atReferenceCounter.hpp new file mode 100644 index 0000000..e9bb2fa --- /dev/null +++ b/rage/atReferenceCounter.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "../base/datBase.hpp" + +namespace rage +{ + class atReferenceCounter : public datBase + { + public: + atReferenceCounter() : m_ref_count(0) {} + + void AddReference() { + m_ref_count++; + } + + void ReleaseReference() { + m_ref_count--; + if(m_ref_count == 0) { + delete this; + } + } + + int GetReferenceCount() const { + return m_ref_count; + } + + private: + int m_ref_count; // 0x0000 + }; +} \ No newline at end of file