Cbeam
Loading...
Searching...
No Matches
cbeam::lifecycle::item_registry Class Reference

Manages the registration and deregistration of items with unique identifiers. More...

#include <item_registry.hpp>

Public Member Functions

 item_registry (std::size_t max_number_of_items=0)
 Constructor for item_registry.
 
std::size_t register_item ()
 Registers an item and returns its unique identifier.
 
void deregister_item (std::size_t item_number)
 Deregisters an item given its unique identifier.
 

Detailed Description

Manages the registration and deregistration of items with unique identifiers.

This class implements a system for managing item registration and deregistration, assigning unique identifiers to each item. Identifiers of deregistered items are recycled and reassigned to new items upon registration. In limited mode (specified maximum number of items), the range of unique identifiers is [0..max_number_of_items-1]. In unlimited mode (maximum number set to zero), identifiers are assigned dynamically with no upper limit, reusing identifiers from deregistered items when available.

Constructor & Destructor Documentation

◆ item_registry()

cbeam::lifecycle::item_registry::item_registry ( std::size_t max_number_of_items = 0)
inlineexplicit

Constructor for item_registry.

Initializes the item registry with a specified maximum number of items. If the maximum number is set to zero, the registry operates in an unlimited mode, allowing an indefinite number of items to be registered. In limited mode, the identifiers range from 0 to max_number_of_items - 1.

Parameters
max_number_of_itemsThe maximum number of items that can be registered. A value of zero indicates no limit on the number of items.

Member Function Documentation

◆ deregister_item()

void cbeam::lifecycle::item_registry::deregister_item ( std::size_t item_number)
inline

Deregisters an item given its unique identifier.

This method deregisters an item, making its identifier available for future registrations. If the identifier is invalid or the item has already been deregistered, a runtime_error exception is thrown.

Parameters
item_numberThe unique identifier of the item to be deregistered.
Exceptions
cbeam::error::runtime_errorif item_number is invalid or if the item has already been deregistered.

◆ register_item()

std::size_t cbeam::lifecycle::item_registry::register_item ( )
inline

Registers an item and returns its unique identifier.

Registers a new item and assigns a unique identifier to it. If there are identifiers available from previously deregistered items, one of these will be reassigned. Identifiers are assigned sequentially. If the registry is full in limited mode (max_number_of_items > 0), or if the identifier count overflows in unlimited mode, an exception is thrown.

Returns
The unique identifier for the newly registered item.
Exceptions
cbeam::error::overflow_errorif the registry is full in limited mode or if the identifier count overflows in unlimited mode.

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