LiteFX 0.3.1.2022
Computer Graphics Engine
LiteFX::App Class Referenceabstract

The base class for an application. More...

#include <app.hpp>

Inherited by SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.

Classes

class  AppImpl
 

Public Member Functions

 App ()
 Initializes a new app instance. More...
 
 App (const App &)=delete
 
 App (App &&)=delete
 
virtual ~App () noexcept
 
virtual String name () const noexcept=0
 Returns the name of the app. More...
 
virtual AppVersion version () const noexcept=0
 Returns the version of the app. More...
 
Platform platform () const noexcept
 Returns the platform, the app is running on. More...
 
virtual const IBackendoperator[] (std::type_index type) const
 Returns the registered backend instance for a type index. More...
 
virtual const IBackendgetBackend (std::type_index type) const
 Returns the registered backend instance for a type index. More...
 
virtual Array< const IBackend * > getBackends (const BackendType type) const noexcept
 Returns all registered backend instances of a backend type. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void onBackendStart (const std::function< bool(TBackend *)> &callback)
 Sets a callback that is called, if a backend is started. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void onBackendStop (const std::function< void(TBackend *)> &callback)
 Sets a callback that is called, if a backend is stopped. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
const TBackend * findBackend () const
 Returns the registered backend instance for a type index. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void startBackend ()
 Attempts to start a backend of type TBackend and stops the active backend of the same BackendType, if any. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void stopBackend ()
 Stops a backend, if it is currently running. More...
 
virtual void use (UniquePtr< IBackend > &&backend)
 Adds a backend to the app. More...
 
virtual void run ()=0
 Starts the application. More...
 
virtual void initialize ()=0
 Called to initialize the application state. More...
 
virtual void resize (int &width, int &height)
 Called, if the application window resizes. More...
 

Static Public Member Functions

template<typename TApp , typename ... TArgs>
static AppBuilder build (TArgs &&... _args)
 Creates a new application builder. More...
 

Protected Member Functions

virtual IBackendgetBackend (std::type_index type)
 Returns the registered backend instance for a type index. More...
 
template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
TBackend * findBackend ()
 Returns the registered backend instance for a type index. More...
 
virtual void startBackend (std::type_index type) const
 Starts a backend. More...
 
virtual void stopBackend (std::type_index type) const
 Stops a backend. More...
 
virtual void stopActiveBackends (const BackendType &type) const
 Stops the active backend of type . More...
 
virtual IBackendactiveBackend (const BackendType &type) const
 Returns the active backend of the provided backend type . More...
 
virtual std::type_index activeBackendType (const BackendType &type) const
 Returns the type index of the active backend of the provided backend type . More...
 

Detailed Description

The base class for an application.

See also
AppBuilder, AppVersion

Constructor & Destructor Documentation

◆ App() [1/3]

App::App ( )

Initializes a new app instance.

◆ App() [2/3]

LiteFX::App::App ( const App )
delete

◆ App() [3/3]

LiteFX::App::App ( App &&  )
delete

◆ ~App()

App::~App ( )
virtualnoexcept

Member Function Documentation

◆ activeBackend()

IBackend * App::activeBackend ( const BackendType &  type) const
protectedvirtual

Returns the active backend of the provided backend type .

Parameters
typeThe type of the backend.
Returns
The active backend of the provided backend type, or std::nullptr, if no backend is active.

◆ activeBackendType()

std::type_index App::activeBackendType ( const BackendType &  type) const
protectedvirtual

Returns the type index of the active backend of the provided backend type .

Parameters
typeThe type of the backend.
Returns
Type index of the active backend of the provided backend type, or the type index of std::nullptr_t, if no backend is active.

◆ build()

template<typename TApp , typename ... TArgs>
static AppBuilder LiteFX::App::build ( TArgs &&...  _args)
inlinestatic

Creates a new application builder.

◆ findBackend() [1/2]

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
TBackend * LiteFX::App::findBackend ( )
inlineprotected

Returns the registered backend instance for a type index.

Template Parameters
TBackendThe type, the type index is derived from.
Returns
The registered backend instance for a type index, or nullptr, if the app has no backend of the provided type.

◆ findBackend() [2/2]

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
const TBackend * LiteFX::App::findBackend ( ) const
inline

Returns the registered backend instance for a type index.

Template Parameters
TBackendThe type, the type index is derived from.
Returns
The registered backend instance for a type index, or nullptr, if the app has no backend of the provided type.

◆ getBackend() [1/2]

IBackend * App::getBackend ( std::type_index  type)
protectedvirtual

Returns the registered backend instance for a type index.

Parameters
typeThe type index of the requested backend.
Returns
The registered backend instance for a type index, or nullptr, if the app has no backend of the provided type.

◆ getBackend() [2/2]

const IBackend * App::getBackend ( std::type_index  type) const
virtual

Returns the registered backend instance for a type index.

Parameters
typeThe type index of the requested backend.
Returns
The registered backend instance for a type index, or nullptr, if the app has no backend of the provided type.

◆ getBackends()

Array< const IBackend * > App::getBackends ( const BackendType  type) const
virtualnoexcept

Returns all registered backend instances of a backend type.

Parameters
typeThe backend type of the requested backends.
Returns
All registered instances of type .

◆ initialize()

virtual void LiteFX::App::initialize ( )
pure virtual

Called to initialize the application state.

Implemented in SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.

◆ name()

virtual String LiteFX::App::name ( ) const
pure virtualnoexcept

Returns the name of the app.

Returns
The name of the app.

Implemented in SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.

◆ onBackendStart()

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void LiteFX::App::onBackendStart ( const std::function< bool(TBackend *)> &  callback)
inline

Sets a callback that is called, if a backend is started.

A backend can have multiple start callbacks, that are executed if a backend is started. Typically such a callback is used to initialize a device and surface for an application. An application might use multiple callbacks, if it creates multiple devices, for example to create a plugin architecture.

Template Parameters
TBackendThe type of the backend.
Parameters
callbackThe function to call during backend startup.
See also
onBackendStop

◆ onBackendStop()

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void LiteFX::App::onBackendStop ( const std::function< void(TBackend *)> &  callback)
inline

Sets a callback that is called, if a backend is stopped.

Template Parameters
TBackendThe type of the backend.
Parameters
callbackThe function to call during backend shutdown.
See also
onBackendStart

◆ operator[]()

const IBackend * App::operator[] ( std::type_index  type) const
virtual

Returns the registered backend instance for a type index.

Parameters
typeThe type index of the requested backend.
Returns
The registered backend instance for a type index, or nullptr, if the app has no backend of the provided type.

◆ platform()

Platform App::platform ( ) const
noexcept

Returns the platform, the app is running on.

Returns
The platform, the app is running on.

◆ resize()

void App::resize ( int &  width,
int &  height 
)
virtual

Called, if the application window resizes.

Calling this method ensures, that the width and height parameters are valid.

Parameters
widthThe new width of the application window.
heightThe new height of the application window.

Reimplemented in SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.

◆ run()

virtual void LiteFX::App::run ( )
pure virtual

Starts the application.

Implemented in SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.

◆ startBackend() [1/2]

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void LiteFX::App::startBackend ( )
inline

Attempts to start a backend of type TBackend and stops the active backend of the same BackendType, if any.

Template Parameters
TBackendThe type of the backend to start.
Exceptions
InvalidArgumentExceptionThrown, if no backend of type TBackend is registered.

◆ startBackend() [2/2]

void App::startBackend ( std::type_index  type) const
protectedvirtual

Starts a backend.

Starting a backend will first stop the active backend of the same BackendType. It will then call all start callbacks for the backend. If the backend has been started successfully, it calls IBackend::activate before returning.

Parameters
typeThe type index of the backend to start.
See also
Backend, onBackendStart

◆ stopActiveBackends()

void App::stopActiveBackends ( const BackendType &  type) const
protectedvirtual

Stops the active backend of type .

Parameters
typeThe backend type for which the active backend should be stopped.
See also
stopBackend

◆ stopBackend() [1/2]

template<typename TBackend >
requires rtti::implements<TBackend, IBackend>
void LiteFX::App::stopBackend ( )
inline

Stops a backend, if it is currently running.

Template Parameters
TBackendThe type of the backend to stop.
Exceptions
InvalidArgumentExceptionThrown, if no backend of type TBackend is registered.

◆ stopBackend() [2/2]

void App::stopBackend ( std::type_index  type) const
protectedvirtual

Stops a backend.

This method calls all stop callbacks for the backend, before returing. If the backend is not running, calling this method has no effect.

Parameters
typeThe type index of the backend to start.
See also
Backend, onBackendStop

◆ use()

void App::use ( UniquePtr< IBackend > &&  backend)
virtual

Adds a backend to the app.

Parameters
backendThe backend to add.
Exceptions
InvalidArgumentExceptionThrown, if the backend is not initialized.

◆ version()

virtual AppVersion LiteFX::App::version ( ) const
pure virtualnoexcept

Returns the version of the app.

Returns
The version of the app.

Implemented in SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, and SampleApp.