Files
o3de/Code/Editor/Util/RefCountBase.h
T
Esteban Papp 7c9653087d Builds Windows nounity and unity
Builds Linux nounity and unity

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
2021-07-16 13:13:59 -07:00

56 lines
1.2 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Reference counted base object.
#ifndef CRYINCLUDE_EDITOR_UTIL_REFCOUNTBASE_H
#define CRYINCLUDE_EDITOR_UTIL_REFCOUNTBASE_H
#pragma once
#include <Include/EditorCoreAPI.h>
#include <CryCommon/ISystem.h>
//! Derive from this class to get reference counting in your class.
class EDITOR_CORE_API CRefCountBase
{
public:
CRefCountBase() {}
//! Add a new reference to this object.
int AddRef()
{
m_nRefCount++;
return m_nRefCount;
}
//! Release reference to this object.
//! When the reference count reaches zero, the object is deleted.
int Release()
{
int refs = --m_nRefCount;
if (m_nRefCount == 0)
{
delete this;
}
else if (m_nRefCount < 0)
{
CryFatalError("Negative ref count");
}
return refs;
}
protected:
virtual ~CRefCountBase() {}
private:
int m_nRefCount = 0;
};
#endif // CRYINCLUDE_EDITOR_UTIL_REFCOUNTBASE_H