libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::ObjectPool< Data >::ConstHandle Class Reference

只读句柄:共享一个槽位,可以复制。 Read-only handle: shares one slot, copyable. More...

#include <object_pool.hpp>

Public Member Functions

 ConstHandle ()=default
 构造空句柄 / Construct an empty handle.
 
 ConstHandle (const ConstHandle &other) noexcept
 复制引用 / Copy the reference.
 
 ConstHandle (ConstHandle &&other) noexcept
 转移引用并清空源句柄 / Transfer the reference and empty the source.
 
 ConstHandle (Handle &&writer) noexcept
 接过可写句柄的槽位,源句柄变空 / Take over a writable handle's slot; the source becomes empty.
 
ConstHandle & operator= (const ConstHandle &other) noexcept
 复制赋值:先保留新引用再释放旧引用 / Copy-assign: retain the new reference before releasing the old one.
 
ConstHandle & operator= (ConstHandle &&other) noexcept
 转移赋值并释放旧引用 / Move-assign and release the old reference.
 
ConstHandle & operator= (Handle &&writer) noexcept
 接过可写句柄的槽位并释放旧引用 / Take over a writable handle's slot and release the old reference.
 
 ~ConstHandle ()
 释放本引用;最后一个引用归还槽位 / Release; the final reference returns the slot.
 
bool Valid () const
 是否持有引用 / Whether this handle owns a reference.
 
const Data & Get () const
 只读访问负载,句柄必须有效 / Read-only payload access; requires a valid handle.
 
const Data * operator-> () const
 返回只读负载指针 / Return a read-only payload pointer.
 
const Data & operator* () const
 只读解引用 / Dereference read-only.
 
IndexType Index () const
 返回有效句柄的槽索引 / Return the slot index of a valid handle.
 
void Reset ()
 清空句柄并释放引用;空句柄无操作 / Empty and release; no-op on an empty handle.
 

Detailed Description

template<typename Data>
class LibXR::ObjectPool< Data >::ConstHandle

只读句柄:共享一个槽位,可以复制。 Read-only handle: shares one slot, copyable.

只能由 Handle 移动得到或由其他 ConstHandle 复制得到;复制增加引用,最后一个 引用释放时槽位回到池中。 Obtained only by moving a Handle or copying another ConstHandle. Copies add references; the final release returns the slot to the pool.

Definition at line 199 of file object_pool.hpp.

Constructor & Destructor Documentation

◆ ConstHandle() [1/3]

template<typename Data >
LibXR::ObjectPool< Data >::ConstHandle::ConstHandle ( const ConstHandle & other)
inlinenoexcept

复制引用 / Copy the reference.

Definition at line 206 of file object_pool.hpp.

207 : pool_(other.pool_), index_(other.index_)
208 {
209 if (pool_ != nullptr)
210 {
211 pool_->Retain(index_);
212 }
213 }

◆ ConstHandle() [2/3]

template<typename Data >
LibXR::ObjectPool< Data >::ConstHandle::ConstHandle ( ConstHandle && other)
inlinenoexcept

转移引用并清空源句柄 / Transfer the reference and empty the source.

Definition at line 216 of file object_pool.hpp.

217 : pool_(std::exchange(other.pool_, nullptr)),
218 index_(std::exchange(other.index_, IndexType{}))
219 {
220 }
uint32_t IndexType
槽索引类型 / Slot index type.

◆ ConstHandle() [3/3]

template<typename Data >
LibXR::ObjectPool< Data >::ConstHandle::ConstHandle ( Handle && writer)
inlinenoexcept

接过可写句柄的槽位,源句柄变空 / Take over a writable handle's slot; the source becomes empty.

Definition at line 224 of file object_pool.hpp.

225 : pool_(std::exchange(writer.pool_, nullptr)),
226 index_(std::exchange(writer.index_, IndexType{}))
227 {
228 }

◆ ~ConstHandle()

template<typename Data >
LibXR::ObjectPool< Data >::ConstHandle::~ConstHandle ( )
inline

释放本引用;最后一个引用归还槽位 / Release; the final reference returns the slot.

Definition at line 264 of file object_pool.hpp.

264{ Reset(); }
void Reset()
清空句柄并释放引用;空句柄无操作 / Empty and release; no-op on an empty handle.

Member Function Documentation

◆ Get()

template<typename Data >
const Data & LibXR::ObjectPool< Data >::ConstHandle::Get ( ) const
inlinenodiscard

只读访问负载,句柄必须有效 / Read-only payload access; requires a valid handle.

Definition at line 271 of file object_pool.hpp.

272 {
273 ASSERT(Valid());
274 return pool_->slots_[index_].data_;
275 }
bool Valid() const
是否持有引用 / Whether this handle owns a reference.

◆ Index()

template<typename Data >
IndexType LibXR::ObjectPool< Data >::ConstHandle::Index ( ) const
inlinenodiscard

返回有效句柄的槽索引 / Return the slot index of a valid handle.

Definition at line 283 of file object_pool.hpp.

284 {
285 ASSERT(Valid());
286 return index_;
287 }

◆ operator*()

template<typename Data >
const Data & LibXR::ObjectPool< Data >::ConstHandle::operator* ( ) const
inlinenodiscard

只读解引用 / Dereference read-only.

Definition at line 280 of file object_pool.hpp.

280{ return Get(); }
const Data & Get() const
只读访问负载,句柄必须有效 / Read-only payload access; requires a valid handle.

◆ operator->()

template<typename Data >
const Data * LibXR::ObjectPool< Data >::ConstHandle::operator-> ( ) const
inlinenodiscard

返回只读负载指针 / Return a read-only payload pointer.

Definition at line 278 of file object_pool.hpp.

278{ return &Get(); }

◆ operator=() [1/3]

template<typename Data >
ConstHandle & LibXR::ObjectPool< Data >::ConstHandle::operator= ( const ConstHandle & other)
inlinenoexcept

复制赋值:先保留新引用再释放旧引用 / Copy-assign: retain the new reference before releasing the old one.

Definition at line 232 of file object_pool.hpp.

233 {
234 if (pool_ != other.pool_ || index_ != other.index_)
235 {
236 ConstHandle copy(other);
237 Swap(copy);
238 }
239 return *this;
240 }
ConstHandle()=default
构造空句柄 / Construct an empty handle.

◆ operator=() [2/3]

template<typename Data >
ConstHandle & LibXR::ObjectPool< Data >::ConstHandle::operator= ( ConstHandle && other)
inlinenoexcept

转移赋值并释放旧引用 / Move-assign and release the old reference.

Definition at line 243 of file object_pool.hpp.

244 {
245 if (this != &other)
246 {
247 ConstHandle moved(std::move(other));
248 Swap(moved);
249 }
250 return *this;
251 }

◆ operator=() [3/3]

template<typename Data >
ConstHandle & LibXR::ObjectPool< Data >::ConstHandle::operator= ( Handle && writer)
inlinenoexcept

接过可写句柄的槽位并释放旧引用 / Take over a writable handle's slot and release the old reference.

Definition at line 255 of file object_pool.hpp.

256 {
257 ConstHandle moved(std::move(writer));
258 Swap(moved);
259 return *this;
260 }

◆ Reset()

template<typename Data >
void LibXR::ObjectPool< Data >::ConstHandle::Reset ( )
inline

清空句柄并释放引用;空句柄无操作 / Empty and release; no-op on an empty handle.

Definition at line 291 of file object_pool.hpp.

292 {
293 ObjectPool* pool = std::exchange(pool_, nullptr);
294 const IndexType index = std::exchange(index_, IndexType{});
295 if (pool != nullptr)
296 {
297 pool->Release(index);
298 }
299 }
ObjectPool(size_t slot_count)
用内部槽数组构造池 / Construct the pool with internal slots.

◆ Valid()

template<typename Data >
bool LibXR::ObjectPool< Data >::ConstHandle::Valid ( ) const
inlinenodiscard

是否持有引用 / Whether this handle owns a reference.

Definition at line 267 of file object_pool.hpp.

267{ return pool_ != nullptr; }

The documentation for this class was generated from the following file: