ECSM v0.2.0
Ref< T >final

Item identifier in the LinearPool with usage counter. More...

#include <linear-pool.hpp>

Public Member Functions

constexpr Ref (ID< T > item)
 Creates a new item reference. (Allocates counter)
 
 ~Ref ()
 Destroys item reference. (Decrements or deallocates counter)
 
 Ref (const Ref &ref) noexcept
 
 Ref (Ref &&ref) noexcept
 
Refoperator= (const Ref &ref) noexcept
 
Refoperator= (Ref &&ref) noexcept
 
int64_t getRefCount () const noexcept
 Returns current item reference count.
 
bool isLastRef () const noexcept
 Returns true if this is last item reference.
 
constexpr bool operator== (const Ref &v) const noexcept
 Returns true if this reference item is equal to the v reference item.
 
constexpr bool operator!= (const Ref &v) const noexcept
 Returns true if this reference item is not equal to the v reference item.
 
constexpr bool operator< (const Ref &v) const noexcept
 Returns true if this reference item is less than the v reference item.
 
constexpr operator ID< T > () const noexcept
 Returns reference item ID.
 
constexpr operator bool () const noexcept
 Returns true if reference item is not null.
 
uint32_t operator* () const noexcept
 Returns reference item index + 1 in the linear pool.
 

Detailed Description

template<typename T>
struct ecsm::Ref< T >

Item identifier in the LinearPool with usage counter.

Template Parameters
Ttype of the item in the linear pool

Useful in cases where we need to track item usage in the program and destroy it when it's not needed anymore.

Constructor & Destructor Documentation

◆ Ref()

template<typename T >
constexpr Ref ( ID< T > item)
inlineexplicitconstexpr

Creates a new item reference. (Allocates counter)

Parameters
itemtarget item instance
Template Parameters
Ttype of the item in the linear pool

Member Function Documentation

◆ operator==()

template<typename T >
constexpr bool operator== ( const Ref< T > & v) const
inlineconstexprnoexcept

Returns true if this reference item is equal to the v reference item.

Parameters
vother reference value

◆ operator!=()

template<typename T >
constexpr bool operator!= ( const Ref< T > & v) const
inlineconstexprnoexcept

Returns true if this reference item is not equal to the v reference item.

Parameters
vother reference value

◆ operator<()

template<typename T >
constexpr bool operator< ( const Ref< T > & v) const
inlineconstexprnoexcept

Returns true if this reference item is less than the v reference item.

Parameters
vother reference value

◆ operator ID< T >()

template<typename T >
constexpr operator ID< T > ( ) const
inlineexplicitconstexprnoexcept

Returns reference item ID.

Template Parameters
Ttype of the item in the linear pool