Files
cocos4/native/cocos/scripting/js-bindings/jswrapper/RefCounter.hpp
T
James Chen 53250dad49 se::Ref -> se::RefCounter, addRef -> incRef, release -> decRef
This is for distinguishing from cocos2d::Ref.
2017-08-31 14:24:34 +08:00

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 {