![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Base/DataComponentList.h>
Class for holding a collection of DataComponents. More...
Class for holding a collection of DataComponents.
DataComponents are uniquely identified by their type and DataComponentList will hold only a single instance of a specific DataComponent type.
DataComponents inheriting from LazyInstantiatedDataComponent can never be deleted from a DataComponentList due to their invariant that references remain valid over the lifetime of the parent Data. Therefore, the assign() and erase() may behave unexpected as they will not remove existing DataComponents of such types.
Example:
Public Member Functions | |
DataComponentList (const Data *parentData=nullptr) | |
Constructor. | |
DataComponentList (const DataComponentList &other) | |
Copy constructor, cloning all DataComponents held by other. | |
DataComponentList (DataComponentList &&other) noexcept | |
Move constructor, taking ownership of all DataComponents held by other. | |
bool | operator== (const DataComponentList &other) const |
Return true if all held components are the same, ignoring their order within the DataComponentList. | |
void | assign (const DataComponentList &rhs) |
Copy assignment, removing all existing components where possible and cloning all DataComponents held by rhs. | |
template<typename T> | |
T * | add (std::unique_ptr< T > component) |
Adds the given DataComponent to the collection. | |
void | add (const DataComponentList &other) |
Adds all DataComponents in other to this one. | |
template<typename T> | |
T * | get () |
Returns the DataComponent exactly matching the given type. | |
template<typename T> | |
const T * | get () const |
Returns the DataComponent exactly matching the given type. | |
template<typename T, typename... Args> | |
T & | getOrCreate (Args &&... ctorArgs) |
Returns the DataComponent exactly matching the given type. | |
std::vector< DataComponentBase * > | getAll () |
Returns all DataComponents without requiring any specific type. | |
std::vector< const DataComponentBase * > | getAll () const |
template<typename T> | |
bool | erase () |
Will erase the DataComponent of the exact given type if possible. | |
bool | erase (const std::string &id) |
Will erase the DataComponent of the exact given id if possible. | |
void | clear () |
Erases all data components in the list that are not persistent. | |
bool | empty () const |
Returns whether the list contains any DataComponent. | |
int | size () const |
Returns the total number of DataComponents. | |
void | configuration (Properties *p) const override |
Writes the configuration of all DataComponents with non-empty string ID to the given properties. | |
void | configure (const Properties *p) override |
Restores the collection of components and their state from the given properties configuration. | |
void | swapWith (DataComponentList &other) |
Swaps the data component lists. | |
![]() | |
virtual void | configureDefaults () |
Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
void | registerParameter (ParameterBase *param) |
Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
void | unregisterParameter (const ParameterBase *param) |
Remove the given Parameter or SubProperty from the list of registered parameters. | |
Configurable (const Configurable &rhs) | |
Configurable (Configurable &&rhs) noexcept | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
Public Attributes | |
Signal | signalListChanged |
Emitted whenever the DataComponentList changes by a DataComponent being added or removed. | |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
Protected Attributes | |
std::vector< std::unique_ptr< DataComponentBase > > | m_components |
Collection of components of this list. | |
const Data * | m_parentData = nullptr |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
|
inline |
Constructor.
parentData | Optionally a parent data can be provided which will be set for any DataComponentWithParentInterface added to the DataComponentList |
void assign | ( | const DataComponentList & | rhs | ) |
Copy assignment, removing all existing components where possible and cloning all DataComponents held by rhs.
T * add | ( | std::unique_ptr< T > | component | ) |
Adds the given DataComponent to the collection.
void add | ( | const DataComponentList & | other | ) |
Adds all DataComponents in other to this one.
Any given DataComponent of the exact same type will be overwritten.
T * get | ( | ) |
Returns the DataComponent exactly matching the given type.
Returns 0 if this object does not have a component of the given type.
const T * get | ( | ) | const |
Returns the DataComponent exactly matching the given type.
Returns 0 if this object does not have a component of the given type.
T & getOrCreate | ( | Args &&... | ctorArgs | ) |
Returns the DataComponent exactly matching the given type.
If no such DataComponent exists yet, a new one will be created first.
ctorArgs | Arguments to be forwarded to the constructor of T in case the DataComponent needs to be created. |
|
overridevirtual |
Writes the configuration of all DataComponents with non-empty string ID to the given properties.
Reimplemented from Configurable.
|
overridevirtual |
Restores the collection of components and their state from the given properties configuration.
Reimplemented from Configurable.
void swapWith | ( | DataComponentList & | other | ) |
Swaps the data component lists.
Permanent data components are kept in original data component list (and copied to other list). Temporary data components are removed from both lists.