Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::Register< T > Class Template Reference

#include <Register.h>

Public Types

using IteratorCallback = std::function<void(const String&, SharedPointer<Array<T>>)>
 Function type used for iterating through registers.
 

Public Member Functions

 Register (Register const &)=delete
 Deleted copy constructor to prevent unintended copying.
 
void operator= (Register const &)=delete
 Deleted assignment operator to prevent unintended copying.
 
 Register ()
 Constructs an empty Register.
 
bool setRegister (const String &name, const T *values, size_t count)
 Sets or replaces a register with the given name and array of values.
 
bool addToRegister (const String &name, const T &value)
 Adds a single value to an existing register or creates a new one.
 
bool getRegisterValue (const String &name, size_t idx, T &outValue) const
 Retrieves a value from the register by name and index.
 
bool setRegisterValue (const String &name, size_t idx, const T &value)
 Updates a value in the register at the specified index.
 
size_t getRegisterLength (const String &name) const
 Gets the number of values in the specified register.
 
void iterateRegisters (IteratorCallback callback) const
 Iterates through all registers and calls the callback function for each one.
 

Protected Member Functions

virtual void _processRegister (const String &name, const T &value)
 Hook method called when a register value is added or modified.
 

Member Typedef Documentation

◆ IteratorCallback

template<typename T>
using uniot::Register< T >::IteratorCallback = std::function<void(const String&, SharedPointer<Array<T>>)>

Function type used for iterating through registers.

The callback receives the register name and a pointer to its value array

Constructor & Destructor Documentation

◆ Register() [1/2]

template<typename T>
uniot::Register< T >::Register ( Register< T > const & )
delete

Deleted copy constructor to prevent unintended copying.

◆ Register() [2/2]

template<typename T>
uniot::Register< T >::Register ( )
inline

Constructs an empty Register.

Member Function Documentation

◆ _processRegister()

template<typename T>
virtual void uniot::Register< T >::_processRegister ( const String & name,
const T & value )
inlineprotectedvirtual

Hook method called when a register value is added or modified.

This virtual method is intended to be overridden by derived classes to implement custom behavior when register values change. The base implementation does nothing.

Parameters
nameThe name identifier of the register being modified
valueThe value being set or added

Reimplemented in uniot::GpioRegister.

◆ addToRegister()

template<typename T>
bool uniot::Register< T >::addToRegister ( const String & name,
const T & value )
inline

Adds a single value to an existing register or creates a new one.

If the register doesn't exist yet, it will be created with a default initial capacity. The method automatically handles dynamic resizing if the register's capacity is exceeded. After adding the value, the _processRegister hook is called to allow derived classes to perform additional processing.

Parameters
nameThe name identifier for the register
valueThe value to add to the register
Return values
trueValue was added successfully
falseMemory allocation failed or register could not be created

◆ getRegisterLength()

template<typename T>
size_t uniot::Register< T >::getRegisterLength ( const String & name) const
inline

Gets the number of values in the specified register.

Parameters
nameThe name identifier for the register
Return values
size_tThe number of values in the register
0The register doesn't exist or is empty

◆ getRegisterValue()

template<typename T>
bool uniot::Register< T >::getRegisterValue ( const String & name,
size_t idx,
T & outValue ) const
inline

Retrieves a value from the register by name and index.

Performs bounds checking to ensure the requested index is valid. The value is copied to the provided outValue reference if found.

Parameters
nameThe name identifier for the register
idxZero-based index of the value within the register
outValueReference where the retrieved value will be stored
Return values
trueValue was retrieved successfully
falseRegister doesn't exist or index is out of bounds

◆ iterateRegisters()

template<typename T>
void uniot::Register< T >::iterateRegisters ( IteratorCallback callback) const
inline

Iterates through all registers and calls the callback function for each one.

This method provides a way to access all registers without knowing their names in advance. The callback receives both the register name and a shared pointer to its array of values.

Example usage:

register.iterateRegisters([](const String& name, SharedPointer<Array<int>> values) {
Serial.printf("Register %s has %d values\n", name.c_str(), values->size());
});
Definition Array.h:66
std::shared_ptr< T > SharedPointer
Type alias for std::shared_ptr with cleaner syntax.
Definition Common.h:160
Parameters
callbackThe function to call for each register (nullptr callbacks are ignored)

◆ operator=()

template<typename T>
void uniot::Register< T >::operator= ( Register< T > const & )
delete

Deleted assignment operator to prevent unintended copying.

◆ setRegister()

template<typename T>
bool uniot::Register< T >::setRegister ( const String & name,
const T * values,
size_t count )
inline

Sets or replaces a register with the given name and array of values.

This method completely replaces any existing register with the same name. If a register with the given name exists, it will be removed before adding the new one. If count is 0, the register will be removed without creating a new one.

Parameters
nameThe name identifier for the register
valuesPointer to an array of values to store
countNumber of values in the array
Return values
trueRegister was set successfully
falseInvalid parameters or memory allocation failed

◆ setRegisterValue()

template<typename T>
bool uniot::Register< T >::setRegisterValue ( const String & name,
size_t idx,
const T & value )
inline

Updates a value in the register at the specified index.

Performs bounds checking to ensure the requested index is valid. After setting the value, the _processRegister hook is called to allow derived classes to perform additional processing.

Parameters
nameThe name identifier for the register
idxZero-based index of the value to update
valueThe new value to set
Return values
trueValue was updated successfully
falseRegister doesn't exist or index is out of bounds

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