![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Base/LazyInstantiatedDataComponent.h>
Extended interface for DataComponents that support lazy instantiation / lazy retrieval. More...
Extended interface for DataComponents that support lazy instantiation / lazy retrieval.
Usually, a DataComponent has to be explicitly instantiated first and then added to its corresponding Data object. However, for certain use cases of DataComponents (e.g. display options) it may be handy to always create a default instance when you're trying to retrieve it from a Data object, which does not yet have a component of such type. This class allows for such lazy instantiation of through its static get() method.
In order to implement your own data-specific options class, inherit from this class directly using your class type as template parameter (this pattern is commonly known as the CRTP pattern). Furthermore, make sure to implement to needed constructor taking a const Data* as argument.
Example:
ComponentType | Specific type of the inheriting class (CRTP pattern). |
DataType | Type of the constructor that ComponentType requires. Must inherit from Data, allows to restrict a DataComponent to certain data types. |
Static Public Member Functions | |
static ComponentType & | get (const DataType &data) |
Returns the specific options of type T that are associated with the given data. | |
static ComponentType * | get (const DataType *data) |
Returns the specific options of type T that are associated with the given data. | |
|
inlinestatic |
Returns the specific options of type T that are associated with the given data.
All data-specific options are lazily instantiated. Thus, this method always returns a valid reference, which will remain valid as long as the corresponding Data object exists.
data | Reference to the data for which to return the data-specific options. |
|
inlinestatic |
Returns the specific options of type T that are associated with the given data.
All data-specific options are lazily instantiated. Thus, this method always returns a valid reference, which will remain valid as long as the corresponding Data object exists.
data | Reference to the data for which to return the data-specific options. |