46 lines
		
	
	
		
			899 B
		
	
	
	
		
			C
		
	
	
	
		
		
			
		
	
	
			46 lines
		
	
	
		
			899 B
		
	
	
	
		
			C
		
	
	
	
|  | #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_; | ||
|  | }; |