|
const T * | instance () const noexcept |
| Returns a pointer to the current instance of the object that is built by the builder. More...
|
|
const TParent & | parent () const noexcept |
| Returns a reference of the parent builder. More...
|
|
| Builder (TParent &parent, TPointer &&instance) noexcept |
| Initializes the builder instance. More...
|
|
| Builder (builder_type &&_other) noexcept |
| Initializes the builder instance by taking over another instance. More...
|
|
| Builder (const builder_type &)=delete |
|
virtual | ~Builder () noexcept=default |
|
template<typename TInstance > |
void | use (pointer_type &&)=delete |
| Called by child builders to pass a constructed object back to the parent builder. More...
|
|
TParent & | add () |
| First, calls build, then use on the parent builder using the current object instance and finally returns the parent builder. More...
|
|
template<typename TDerived, typename T, typename TParent, typename TPointer>
class LiteFX::Builder< TDerived, T, TParent, TPointer >
Describes an generic builder type.
Describes a child builder.
Builders are helper classes to create objects or object hierarchies. A builder is called root builder, if TParent is set to std::nullptr_t
, otherwise it is called child builder and TParent is set to the type of the parent builder in the hierarchy. A builder can be a child builder to either a root builder or another child builder. However, at the top of the hierarchy there needs to be one root builder and each hierarchy can only have one root builder.
Building a child object using a child builder can be terminated by calling add
on it. This will call use
on the parent builder and pass the object instance to it. If any work needs to be done by the builder before passing it to the parent builder, it is possible to overwrite the build
method. For root builders no additional call is required. Instead a root builder provides a move-assignment operator for T . Assigning the builder instance to an instance of TPointer will return the instance object. Similar to child builders, it is possible to overwrite the build
method, to perform any additional pre-construction work.
The derived type TDerived marks the actual implementation of the builder, which itself is derived from this class in CRTP-fashion. It is typically used to define builder methods that return references to this
.
Builders create the object instances they manage in form of smart pointers. The TPointer can either be set to any smart pointer type that wraps T for convenience.
- Template Parameters
-
TDerived | The concrete implementation of the builder itself. |
T | The type of the object the builder builds. |
TParent | The type of the parent builder or std::nullptr_t . |
TPointer | The type of the pointer, used to access the instance of T this builder builds. |
- Template Parameters
-
TDerived | The concrete implementation of the builder itself. |
T | The type of the object the builder builds. |
TPointer | The type of the pointer, used to access the instance of T this builder builds. |