LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Builder< T, TParent, TPointer > Class Template Reference

Describes an generic builder type. More...

#include <containers.hpp>

Public Types

using instance_type = T
 
using parent_type = TParent
 
using pointer_type = TPointer
 

Public Member Functions

constexpr const T * instance () const noexcept
 Returns a pointer to the current instance of the object that is built by the builder.
 
constexpr const TParent & parent () const noexcept
 Returns a reference of the parent builder.
 
constexpr Builder (TParent &parent, TPointer &&instance) noexcept
 Initializes the builder instance.
 
constexpr Builder (Builder &&_other) noexcept
 Initializes the builder instance by taking over another instance.
 
constexpr Builder (const Builder &)=delete
 
auto operator= (const Builder &)=delete
 
auto operator= (Builder &&) noexcept=delete
 
virtual constexpr ~Builder () noexcept=default
 
template<typename TInstance >
void use (pointer_type &&) noexcept=delete
 Called by child builders to pass a constructed object back to the parent builder.
 
constexpr TParent & add ()
 First, calls build, then use on the parent builder using the current object instance and finally returns the parent builder.
 

Protected Member Functions

constexpr T * instance () noexcept
 Returns a pointer to the current instance of the object that is built by the builder.
 
virtual constexpr void build ()
 Can be overwritten to perform any pre-construction work before the builder returns the final object instance.
 

Detailed Description

template<typename T, typename TParent, typename TPointer>
class LiteFX::Builder< 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.

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
TThe type of the object the builder builds.
TParentThe type of the parent builder or std::nullptr_t.
TPointerThe type of the pointer, used to access the instance of T this builder builds.
Template Parameters
TThe type of the object the builder builds.
TPointerThe type of the pointer, used to access the instance of T this builder builds.

Member Typedef Documentation

◆ instance_type

template<typename T , typename TParent , typename TPointer >
using LiteFX::Builder< T, TParent, TPointer >::instance_type = T

◆ parent_type

template<typename T , typename TParent , typename TPointer >
using LiteFX::Builder< T, TParent, TPointer >::parent_type = TParent

◆ pointer_type

template<typename T , typename TParent , typename TPointer >
using LiteFX::Builder< T, TParent, TPointer >::pointer_type = TPointer

Constructor & Destructor Documentation

◆ Builder() [1/3]

template<typename T , typename TParent , typename TPointer >
LiteFX::Builder< T, TParent, TPointer >::Builder ( TParent & parent,
TPointer && instance )
inlineexplicitconstexprnoexcept

Initializes the builder instance.

Parameters
parentThe instance of the parent builder.
instanceThe instance of the object to build.

◆ Builder() [2/3]

template<typename T , typename TParent , typename TPointer >
LiteFX::Builder< T, TParent, TPointer >::Builder ( Builder< T, TParent, TPointer > && _other)
inlineconstexprnoexcept

Initializes the builder instance by taking over another instance.

Parameters
_otherThe instance of another builder object to take over.

◆ Builder() [3/3]

template<typename T , typename TParent , typename TPointer >
LiteFX::Builder< T, TParent, TPointer >::Builder ( const Builder< T, TParent, TPointer > & )
constexprdelete

◆ ~Builder()

template<typename T , typename TParent , typename TPointer >
virtual constexpr LiteFX::Builder< T, TParent, TPointer >::~Builder ( )
constexprvirtualdefaultnoexcept

Member Function Documentation

◆ add()

template<typename T , typename TParent , typename TPointer >
TParent & LiteFX::Builder< T, TParent, TPointer >::add ( )
inlinenodiscardconstexpr

First, calls build, then use on the parent builder using the current object instance and finally returns the parent builder.

◆ build()

template<typename T , typename TParent , typename TPointer >
virtual constexpr void LiteFX::Builder< T, TParent, TPointer >::build ( )
inlineconstexprprotectedvirtual

Can be overwritten to perform any pre-construction work before the builder returns the final object instance.

◆ instance() [1/2]

template<typename T , typename TParent , typename TPointer >
const T * LiteFX::Builder< T, TParent, TPointer >::instance ( ) const
inlineconstexprnoexcept

Returns a pointer to the current instance of the object that is built by the builder.

Returns
A pointer to the current object instance.

◆ instance() [2/2]

template<typename T , typename TParent , typename TPointer >
T * LiteFX::Builder< T, TParent, TPointer >::instance ( )
inlineconstexprprotectednoexcept

Returns a pointer to the current instance of the object that is built by the builder.

Returns
A pointer to the current object instance.

◆ operator=() [1/2]

template<typename T , typename TParent , typename TPointer >
auto LiteFX::Builder< T, TParent, TPointer >::operator= ( Builder< T, TParent, TPointer > && )
deletenoexcept

◆ operator=() [2/2]

template<typename T , typename TParent , typename TPointer >
auto LiteFX::Builder< T, TParent, TPointer >::operator= ( const Builder< T, TParent, TPointer > & )
delete

◆ parent()

template<typename T , typename TParent , typename TPointer >
const TParent & LiteFX::Builder< T, TParent, TPointer >::parent ( ) const
inlineconstexprnoexcept

Returns a reference of the parent builder.

Returns
A reference of the parent builder.

◆ use()

template<typename T , typename TParent , typename TPointer >
template<typename TInstance >
void LiteFX::Builder< T, TParent, TPointer >::use ( pointer_type && )
deletenoexcept

Called by child builders to pass a constructed object back to the parent builder.

This method must be implemented for each child builder, a builder can create. This introduces a hard dependency between child and parent builders. It is not possible to define a child builder without implementing the counter part in the parent builder.