Template Class RegistryList#

Class Documentation#

template<class T>
class RegistryList#

A registry for managing unique instances of objects of type T.

This class is designed to manage a collection of shared pointers to objects of type T. It enforces uniqueness of entries and provides methods to add, remove, and query items.

Template Parameters:

T – The type of the objects to be stored. Expected to provide typeString() and name() methods.

Public Types

using iterator = std::vector<ks_ptr<T>>::iterator#

Iterator type for access to items.

using const_iterator = std::vector<ks_ptr<T>>::const_iterator#

Cosnt iterator type for read-only access to items.

using reverse_iterator = std::vector<ks_ptr<T>>::reverse_iterator#

Reverse iterator type for access to items.

using const_reverse_iterator = std::vector<ks_ptr<T>>::const_reverse_iterator#

Const reverse iterator type for read-only access to items.

Public Functions

inline void add(const ks_ptr<T> &val)#

Adds an item to the registry.

If the item already exists in the registry, an exception is thrown.

Parameters:

val – A shared pointer to the item to add.

Throws:

std::invalid_argument – If the item is already registered.

inline void remove(const ks_ptr<T> &val)#

Removes an item from the registry.

If the item does not exist in the registry, an exception is thrown.

Parameters:

val – A shared pointer to the item to remove.

Throws:

std::invalid_argument – If the item is not registered.

inline bool contains(const ks_ptr<const T> &val) const#

Returns true if the object is in the registry.

Parameters:

val – A shared pointer to the item to check.

Returns:

true if the object is registered here

inline bool contains(id_t id) const#

Checks whether there is an item with the matching id in the registry.

Parameters:

id – Item id

Returns:

true is there is an item with the matching id in the registry

inline const std::vector<ks_ptr<T>> &items() const#

Return the list of registered items.

Returns:

list of registered items

inline ks_ptr<T> lookup(id_t id) const#

Returns object with the matching id in the registry.

Parameters:

id – Item id

Returns:

Item with the matching id or nullptr if there is no item

inline const std::vector<ks_ptr<T>> lookupAll(std::string_view name) const#

Returns list of objects with the matching name in the registry.

Parameters:

name – Item name

Returns:

List of items with the matching name

inline ks_ptr<T> lookup(std::string_view name) const#

Returns the object with the matching name in the registry.

This method will throw an error if it finds more than one object with the matching name.

Parameters:

name – Item name

Returns:

Item with the matching name or null if there is no matching item

inline size_t size() const#

Gets the number of items in the registry.

Returns:

The number of items currently registered.

inline const ks_ptr<T> &at(size_t index) const#

Gets the item in the registry at the position given by index.

Parameters:

index – The index that specifies the position to get the item at.

Throws:

std::out_of_range – if the index is out of bounds.

Returns:

The item at the given index.

inline const std::string dumpString(std::string_view prefix = "") const#

Dumps the registry content as a string.

This method returns a string representation of the registry’s contents.

Parameters:

prefix – A prefix string to prepend.

Returns:

A string representation of the registry contents.

inline void clear()#

Clear the registry list.

inline const std::vector<ks_ptr<T>> &items()#

Return list of items.

Returns:

The list of items.

inline iterator begin()#

Returns an iterator to the beginning of the items.

Returns:

Iterator to the first item.

inline iterator end()#

Returns an iterator to the end of the items.

Returns:

Iterator to one-past-the-last item.

inline const_iterator begin() const#

Returns a constant iterator to the beginning of the items.

Returns:

Constant iterator to the first item.

inline const_iterator end() const#

Returns a constant iterator to the end of the items.

Returns:

Constant iterator to one-past-the-last item.

inline const_iterator cbegin() const#

Returns a constant iterator to the beginning of the items.

Returns:

Constant iterator to the first item.

inline const_iterator cend() const#

Returns a constant iterator to the end of the items.

Returns:

Constant iterator to one-past-the-last item.

inline ks_ptr<T> front() const#

Returns the first item in the list.

Returns:

ks_ptr to the first item.

inline reverse_iterator rbegin()#

Returns a reverse iterator to the beginning of the reversed items.

Returns:

Reverse iterator to the the beginning of the reversed items.

inline reverse_iterator rend()#

Returns a reverse iterator to the end of the reversed items.

Returns:

Reverse iterator to the end of the reversed items.

inline const_reverse_iterator rbegin() const#

Returns a constant reverse iterator to the beginning of the reversed items.

Returns:

Constant reverse iterator to the beginning of the reversed items.

inline const_reverse_iterator rend() const#

Returns a constant reverse iterator to the end of the reversed items.

Returns:

Constant reverse iterator to the end of the reversed items.

inline const_reverse_iterator crbegin() const#

Returns a constant reverse iterator to the beginning of the reversed items.

Returns:

Constant reverse iterator to the beginning of the reversed items.

inline const_reverse_iterator crend() const#

Returns a constant reverse iterator to the end of the reversed items.

Returns:

Constant reverse iterator to the end of the reversed items.