LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::App Class Referenceabstract

The base class for an application. More...

#include <app.hpp>

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

Classes

class  AppImpl
 

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

Event< const IBackend * > backendStarted
 Invoked, if a backend has been started.
 
Event< const IBackend * > backendStopped
 Invoked, if a backend has been stopped.
 
Event< EventArgsstartup
 Invoked, if the application has been started.
 
Event< EventArgsinitializing
 Invoked during initialization.
 
Event< EventArgsshutdown
 Invoked, if the application has is shutting down.
 
Event< ResizeEventArgsresized
 Invoked, if the app window or context gets resized.
 

Protected Member Functions

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

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 && )
deletenoexcept

◆ ~App()

App::~App ( )
virtualnoexcept

Member Function Documentation

◆ activeBackend()

IBackend * App::activeBackend ( BackendType type) const
protected

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 ( BackendType type) const
protected

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>
AppBuilder LiteFX::App::build ( TArgs &&... _args)
inlinestaticnodiscard

Creates a new application builder.

◆ findBackend() [1/2]

template<typename TBackend >
requires meta::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 meta::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)
protected

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

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()

Enumerable< const IBackend & > App::getBackends ( const BackendType type) const

Returns all registered backend instances of a backend type.

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

◆ name()

virtual StringView 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, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, TestApp, and TestApp.

◆ onBackendStart()

template<typename TBackend >
requires meta::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.

Different to the backendStarted event, this event can be strongly typed at compile time, thus different callbacks can be provided per backend type without requiring to differentiate them at run-time.

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

◆ onBackendStop()

template<typename TBackend >
requires meta::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.

Different to the backendStopped event, this event can be strongly typed at compile time, thus different callbacks can be provided per backend type without requiring to differentiate them at run-time.

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

◆ operator=() [1/2]

auto LiteFX::App::operator= ( App && )
deletenoexcept

◆ operator=() [2/2]

auto LiteFX::App::operator= ( const App & )
delete

◆ operator[]()

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

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 )

Called, if the application window resizes.

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

◆ run()

void App::run ( )

Starts the application.

◆ startBackend() [1/2]

template<typename TBackend >
requires meta::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
protected

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 ( BackendType type) const
protected

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 meta::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
protected

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, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, SampleApp, TestApp, and TestApp.

Member Data Documentation

◆ backendStarted

Event<const IBackend*> LiteFX::App::backendStarted
mutable

Invoked, if a backend has been started.

◆ backendStopped

Event<const IBackend*> LiteFX::App::backendStopped
mutable

Invoked, if a backend has been stopped.

◆ initializing

Event<EventArgs> LiteFX::App::initializing
mutable

Invoked during initialization.

◆ resized

Event<ResizeEventArgs> LiteFX::App::resized
mutable

Invoked, if the app window or context gets resized.

◆ shutdown

Event<EventArgs> LiteFX::App::shutdown
mutable

Invoked, if the application has is shutting down.

◆ startup

Event<EventArgs> LiteFX::App::startup
mutable

Invoked, if the application has been started.