建档
This commit is contained in:
45
source/Tool/RefObject.h
Normal file
45
source/Tool/RefObject.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tool/Common.h"
|
||||
#include "Tool/Allocator.h"
|
||||
#include <atomic>
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 引用计数器
|
||||
*/
|
||||
class RefObject : protected Noncopyable
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 增加引用计数
|
||||
void Retain();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 减少引用计数
|
||||
void Release();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取引用计数
|
||||
uint32_t GetRefCount() const;
|
||||
|
||||
static void *operator new(size_t size);
|
||||
|
||||
static void operator delete(void *ptr);
|
||||
|
||||
static void *operator new(size_t size, std::nothrow_t const &) noexcept;
|
||||
|
||||
static void operator delete(void *ptr, std::nothrow_t const &) noexcept;
|
||||
|
||||
static void *operator new(size_t size, void *ptr) noexcept;
|
||||
|
||||
static void operator delete(void *ptr, void *place) noexcept;
|
||||
|
||||
virtual ~RefObject();
|
||||
|
||||
protected:
|
||||
RefObject();
|
||||
|
||||
private:
|
||||
std::atomic<uint32_t> ref_count_;
|
||||
};
|
||||
Reference in New Issue
Block a user