|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
Supports tracking instances which can come and go during runtime. More...
|
Classes | |
| struct | embutil::InstanceElem< TTrackedClass, TKey > |
| Helper struct which is used to store Key/Value pairs in the InstanceList. More... | |
| class | embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize > |
| Generic InstanceList template container. More... | |
Typedefs | |
| template<class TTrackedClass , typename TKey = const char*, class TContainer = std::list<InstanceElem<TTrackedClass, TKey>>> | |
| using | embutil::DynamicInstanceList = InstanceList< TTrackedClass, TKey, TContainer > |
| Template class to track instances of class-type things (dynamic memory variant) More... | |
| template<class TTrackedClass , const size_t TSize = 32, typename TKey = const char*, class TContainer = etl::list<InstanceElem<TTrackedClass, TKey>, TSize>> | |
| using | embutil::StaticInstanceList = InstanceList< TTrackedClass, TKey, TContainer, TSize > |
| Template class to track instances of class-type things (static memory variant) More... | |
Supports tracking instances which can come and go during runtime.
| struct embutil::InstanceElem |
Helper struct which is used to store Key/Value pairs in the InstanceList.
This structure respresents an Instance element. The key and value are stored in the element struct, and an operator==() is implemented to support the find() and find_if() functions.
| TTrackedClass | the type of class being tracked by the instance element. |
| TKey | the type of the key used to access the element. |
Public Member Functions | |
| bool | operator== (const InstanceElem &t) const noexcept |
| Compare equality between two instance elements. More... | |
Public Attributes | |
| TKey | key |
| TTrackedClass * | value |
|
inlinenoexcept |
Compare equality between two instance elements.
Both the key and the value must match for two instance elements to be equal.
References t.
| TKey embutil::InstanceElem< TTrackedClass, TKey >::key |
| TTrackedClass* embutil::InstanceElem< TTrackedClass, TKey >::value |
| class embutil::InstanceList |
Generic InstanceList template container.
This class is not intended to be used directly. Instead use the defined aliases:
This list designed to work with STL containers and ETL containers which supply the push_back(), remove(), and remove_if() methods.
For an example module which uses an InstanceList, see embvm::DriverBase.
The DriverBase InstanceList stores pointers to DriverBase instances, which is the base class for all framework drivers:
When framework drivers are constructed, they are added to the DriverRegistry instance list. The registerDriver() interface forwards the call to the DriverRegistry add() function.
The DeriverBase destructor removes instances from the list. The unregisterDriver() interface forwards the call to the DriverRegistry remove() function.
Lookups can be performed by key:
| TTrackedClass | The type of class which is tracked by this instance list. |
| TKey | The key type which is used to lookup stored values. |
| TContainer | The container type used to store the instance list. |
| TSize | The maximum of elements to track with the list. If TSize is 0, then dynamic memory allocation will be used. Otherwise, static memory allocation is used and the maximum number of elements that can be tracked is TSize. |
Public Types | |
| using | TStorageType = InstanceElem< TTrackedClass, TKey > |
Public Member Functions | |
| InstanceList ()=default | |
| Default constructor. More... | |
| ~InstanceList ()=default | |
| Default destructor. More... | |
| size_t | size () const noexcept |
| Get the current size of the list. More... | |
| constexpr size_t | capacity () const noexcept |
| Get the total storage capacity of the list. More... | |
| TContainer & | rawStorage () noexcept |
| Registered instance list accessor. More... | |
Add Instances | |
| void | add (TKey key, TTrackedClass *instance) noexcept |
| Register an instance of the TTrackedClass with a key. More... | |
| void | add (TTrackedClass *instance) noexcept |
| Register an instance of the TTrackedClass without a key. More... | |
Remove Instances | |
| void | remove (TKey key, TTrackedClass *instance) noexcept |
| Remove instance matching key and value. More... | |
| void | remove (TKey key) noexcept |
| Remove all instances matchey key. More... | |
| void | remove (TTrackedClass *instance) noexcept |
| Remove an instance value from the list. More... | |
Instance Lookup | |
| optional_ref | operator[] (TKey key) noexcept |
| Indexing operator supports the use of key. More... | |
| optional_ref | find (TKey key) noexcept |
| Find instance using a key. More... | |
Private Types | |
| using | optional_ref = type_safe::optional_ref< TTrackedClass > |
| Convenience alias for optional references, used internally to the class. More... | |
Private Attributes | |
| TContainer | registered_ |
| The list of registered instances. More... | |
|
private |
Convenience alias for optional references, used internally to the class.
| using embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::TStorageType = InstanceElem<TTrackedClass, TKey> |
|
default |
Default constructor.
|
default |
Default destructor.
|
inlinenoexcept |
Register an instance of the TTrackedClass with a key.
add() should be called in the base-class constructor of the instance type which you are tracking. See embvm::DriverBase for an example.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
| key | The key to register the instance under. |
| instance | The instance pointer to track. |
References assert, b, embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::capacity(), embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_, and embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::size().
Referenced by embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::add().
|
inlinenoexcept |
Register an instance of the TTrackedClass without a key.
add() should be called in the base-class constructor of the instance type which you are tracking. See embvm::DriverBase for an example.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
| instance | The instance pointer to track. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::add().
|
inlinenoexcept |
Get the total storage capacity of the list.
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
Referenced by embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::add().
|
inlinenoexcept |
Find instance using a key.
| key | The key to use for looking up the corresponding TTrackedClass value. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
Referenced by embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::operator[]().
|
inlinenoexcept |
Indexing operator supports the use of key.
Allow indexing into this object's key ("compatible-key", "instance-key")
| key | The key to use for looking up the corresponding TTrackedClass value. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::find().
|
inlinenoexcept |
Registered instance list accessor.
If you need to perform lookups or other complex operations on the list, but can't work through the InstanceList interface, you can get the raw storage.
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
|
inlinenoexcept |
Remove instance matching key and value.
Both the key and the value must match for the instance to be removed.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
| key | The key corresponding to the instance to remove. |
| instance | The instance value to remove. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_, and remove().
|
inlinenoexcept |
Remove all instances matchey key.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
| key | The corresponding key to remove instances for. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
|
inlinenoexcept |
Remove an instance value from the list.
This function is marked noexcept because we want the program to terminate if an exception results from this call.
| instance | The pointer to the instance to remove from the list. |
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
|
inlinenoexcept |
Get the current size of the list.
References embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::registered_.
Referenced by embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::add().
|
private |
The list of registered instances.
Referenced by embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::add(), embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::capacity(), embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::find(), embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::rawStorage(), embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::remove(), and embutil::InstanceList< TTrackedClass, TKey, TContainer, TSize >::size().
| using embutil::DynamicInstanceList = typedef InstanceList<TTrackedClass, TKey, TContainer> |
Template class to track instances of class-type things (dynamic memory variant)
This class supports tracking instances which can come and go during runtime. The DynamicInstanceList uses dynamic memory allocation.
Example declarations:
| TTrackedClass | The type of class which is tracked by this instance list. |
| TKey | The key type which is used to lookup stored values. |
| TContainer | The container type used to store the instance list. |
| using embutil::StaticInstanceList = typedef InstanceList<TTrackedClass, TKey, TContainer, TSize> |
Template class to track instances of class-type things (static memory variant)
This class supports tracking instances which can come and go during runtime. The StaticInstanceList uses static memory allocation.
Example declarations:
| TTrackedClass | The type of class which is tracked by this instance list. |
| TSize | The maximum of elements to track with the list. |
| TKey | The key type which is used to lookup stored values. |
| TContainer | The container type used to store the instance list. |
1.8.15