Cbeam
|
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. | |
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.
|
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.
max_number_of_items | The maximum number of items that can be registered. A value of zero indicates no limit on the number of items. |
|
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.
item_number | The unique identifier of the item to be deregistered. |
cbeam::error::runtime_error | if item_number is invalid or if the item has already been deregistered. |
|
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.
cbeam::error::overflow_error | if the registry is full in limited mode or if the identifier count overflows in unlimited mode. |