GameKit  0.0.1a
C++ gamedev tools
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
gk::ApplicationStateStack Class Reference

Stack containing ApplicationState instances. More...

#include <ApplicationStateStack.hpp>

Public Member Functions

template<typename T , typename... Args>
auto push (Args &&...args) -> typename std::enable_if< std::is_base_of< ApplicationState, T >::value, T &>::type
 Push a new gk::ApplicationState to the stack. More...
 
void pop ()
 Remove the top ApplicationState in the stack. More...
 
void clear ()
 Clear the stack. More...
 
void clearDeletedStates ()
 Clear the removed states of the stack. More...
 
ApplicationStatetop () const
 Get the top ApplicationState in the stack. More...
 
bool empty () const
 Check if the container is empty. More...
 
std::size_t size () const
 Get the amount of ApplicationState in the stack. More...
 

Static Public Member Functions

static ApplicationStateStackgetInstance ()
 Get the current singleton instance. More...
 
static void setInstance (ApplicationStateStack &instance)
 Set the current singleton instance. More...
 

Private Attributes

std::stack< std::shared_ptr< ApplicationState > > m_states
 Stack containing the states. More...
 
std::stack< std::shared_ptr< ApplicationState > > m_trash
 Removed states waiting to be deleted. More...
 

Static Private Attributes

static ApplicationStateStacks_instance = nullptr
 Current singleton instance. More...
 

Detailed Description

Stack containing ApplicationState instances.

gk::ApplicationStateStack is a stack container of gk::ApplicationState instances.

Usage example:

// In a gk::CoreApplication subclass
m_stateStack.push<MyApplicationState>(...);
// In a gk::ApplicationState subclass
m_stateStack->push<MyApplicationState>(...);
// Everywhere else
gk::ApplicationStateStack::getInstance().push<MyApplicationState>(...);
See also
gk::ApplicationState

Definition at line 28 of file ApplicationStateStack.hpp.

Member Function Documentation

§ clear()

void gk::ApplicationStateStack::clear ( )
inline

Clear the stack.

Definition at line 57 of file ApplicationStateStack.hpp.

§ clearDeletedStates()

void gk::ApplicationStateStack::clearDeletedStates ( )

Clear the removed states of the stack.

This function is automatically called in CoreApplication::mainLoop()

Definition at line 25 of file ApplicationStateStack.cpp.

§ empty()

bool gk::ApplicationStateStack::empty ( ) const
inline

Check if the container is empty.

Returns
true if the container is empty, otherwise false

Definition at line 81 of file ApplicationStateStack.hpp.

§ getInstance()

static ApplicationStateStack& gk::ApplicationStateStack::getInstance ( )
inlinestatic

Get the current singleton instance.

Returns
Current singleton instance
See also
setInstance

Definition at line 99 of file ApplicationStateStack.hpp.

§ pop()

void gk::ApplicationStateStack::pop ( )

Remove the top ApplicationState in the stack.

The state is moved to another stack while waiting for clearDeleteStates() to remove it.

Definition at line 20 of file ApplicationStateStack.cpp.

§ push()

template<typename T , typename... Args>
auto gk::ApplicationStateStack::push ( Args &&...  args) -> typename std::enable_if<std::is_base_of<ApplicationState, T>::value, T&>::type
inline

Push a new gk::ApplicationState to the stack.

Parameters
argsConstructor arguments of type T

This function will populate ApplicationState::m_stateStack

Definition at line 39 of file ApplicationStateStack.hpp.

§ setInstance()

static void gk::ApplicationStateStack::setInstance ( ApplicationStateStack instance)
inlinestatic

Set the current singleton instance.

Parameters
instanceNew singleton instance
See also
getInstance

Definition at line 111 of file ApplicationStateStack.hpp.

§ size()

std::size_t gk::ApplicationStateStack::size ( ) const
inline

Get the amount of ApplicationState in the stack.

Returns
Size of the stack

Definition at line 89 of file ApplicationStateStack.hpp.

§ top()

ApplicationState& gk::ApplicationStateStack::top ( ) const
inline

Get the top ApplicationState in the stack.

Returns
The currently active ApplicationState

Definition at line 73 of file ApplicationStateStack.hpp.

Member Data Documentation

§ m_states

std::stack<std::shared_ptr<ApplicationState> > gk::ApplicationStateStack::m_states
private

Stack containing the states.

Definition at line 121 of file ApplicationStateStack.hpp.

§ m_trash

std::stack<std::shared_ptr<ApplicationState> > gk::ApplicationStateStack::m_trash
private

Removed states waiting to be deleted.

Definition at line 122 of file ApplicationStateStack.hpp.

§ s_instance

ApplicationStateStack * gk::ApplicationStateStack::s_instance = nullptr
staticprivate

Current singleton instance.

Definition at line 119 of file ApplicationStateStack.hpp.


The documentation for this class was generated from the following files: