Loading...
Searching...
No Matches
ml::TraitWith< Manifest > Class Template Reference

Base for traits that declare a manifest. More...

#include <Trait.h>

Inheritance diagram for ml::TraitWith< Manifest >:

Public Types

using manifest_type = Manifest
 The manifest type, used by GatherFlags and GatherStates to locate this class's flag and state declarations.

Public Member Functions

std::enable_if_t<!std::is_void_v< T >, T > getState () const
 Return the current state value.
std::enable_if_t<!std::is_void_v< T >, bool > isState (T state) const
 Return true if currently in state.
std::enable_if_t<!std::is_void_v< T > > onStateEnter (std::function< void(T)> callback)
 Register a callback invoked after each state transition.
std::enable_if_t<!std::is_void_v< T > > onStateExit (std::function< void(T)> callback)
 Register a callback invoked before each state transition.
std::enable_if_t<!std::is_void_v< T > > setState (T newState)
 Transition to a new state.

Detailed Description

template<typename Manifest>
class ml::TraitWith< Manifest >

Base for traits that declare a manifest.

TraitWith<Manifest> combines the Trait marker with Customizable<Manifest>, wiring the trait's Flags and State enums into the GatherFlags / GatherStates machinery so they are automatically included in the flag and state stores of any ComponentWith that mixes in this trait.

Usage

class MyTraitManifest : public Manifest {
public:
enum class Flag { Active };
enum class State { Idle, Running };
};
class MyTrait : public ml::TraitWith<MyTraitManifest> {
// access flags via dynamic_cast<SingleFlaggable<MyTraitManifest::Flag>*>(this)
};
Base class for all Malena manifests.
Definition Manifest.h:81
Flag
System-level boolean flags available on every ml::Core object.
Definition Flag.h:60
Template Parameters
ManifestA Manifest subclass declaring Flag/State enums.
See also
Trait, Customizable, Draggable, GatherFlags, GatherStates

Definition at line 60 of file Trait.h.

Member Typedef Documentation

◆ manifest_type

template<typename Manifest>
using ml::Customizable< Manifest >::manifest_type = Manifest
inherited

The manifest type, used by GatherFlags and GatherStates to locate this class's flag and state declarations.

Definition at line 64 of file Customizable.h.

Member Function Documentation

◆ getState()

std::enable_if_t<!std::is_void_v< T >, T > ml::StateManager< extract_State< Manifest >::type >::getState ( ) const
inherited

Return the current state value.

Returns
The active StateEnum value.

◆ isState()

std::enable_if_t<!std::is_void_v< T >, bool > ml::StateManager< extract_State< Manifest >::type >::isState ( T state) const
inherited

Return true if currently in state.

Parameters
stateThe state value to compare against.
Returns
true if the current state equals state.

◆ onStateEnter()

std::enable_if_t<!std::is_void_v< T > > ml::StateManager< extract_State< Manifest >::type >::onStateEnter ( std::function< void(T)> callback)
inherited

Register a callback invoked after each state transition.

The callback receives the newly entered state. Only one enter callback is active at a time; calling this again replaces it.

Parameters
callbackFunction called with the new state after each transition.

◆ onStateExit()

std::enable_if_t<!std::is_void_v< T > > ml::StateManager< extract_State< Manifest >::type >::onStateExit ( std::function< void(T)> callback)
inherited

Register a callback invoked before each state transition.

The callback receives the state being left. Only one exit callback is active at a time; calling this again replaces it.

Parameters
callbackFunction called with the old state before each transition.

◆ setState()

std::enable_if_t<!std::is_void_v< T > > ml::StateManager< extract_State< Manifest >::type >::setState ( T newState)
inherited

Transition to a new state.

Fires the exit callback with the current state, updates the stored state to newState, then fires the enter callback with the new state. Either callback may be unset (nullptr), in which case it is skipped.

Parameters
newStateThe state to transition into.

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