mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 02:52:39 +08:00
53250dad49
This is for distinguishing from cocos2d::Ref.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#pragma once
|
|
|
|
namespace se {
|
|
|
|
/**
|
|
* This class is used to manage reference-counting providing a simple interface and a counter.
|
|
*
|
|
*/
|
|
class RefCounter
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Increases reference count by one.
|
|
*/
|
|
void incRef();
|
|
|
|
/**
|
|
* @brief Decrements the reference count, if it reaches zero, destroys this instance of RefCounter to release its memory.
|
|
* @note Please note that after calling this function, the caller should absolutely avoid to use the pointer to this instance since it may not be valid anymore.
|
|
*/
|
|
void decRef();
|
|
|
|
/**
|
|
* @brief Gets reference count.
|
|
* @return The reference count.
|
|
* @note When this goes to zero during a decRef() call, the object will auto-delete itself.
|
|
*/
|
|
unsigned int getRefCount();
|
|
|
|
protected:
|
|
// Default constructor
|
|
// Initialises the internal reference count to 1.
|
|
RefCounter();
|
|
// Destructor
|
|
virtual ~RefCounter();
|
|
|
|
private:
|
|
unsigned int _refCount;
|
|
};
|
|
|
|
} // namespace se {
|