stmm-games-doc  0.32.0
Public Member Functions | List of all members
stmi::Event::RegisterClass< T > Class Template Referencefinal

Template used to register event classes. More...

Public Member Functions

 RegisterClass (const char *const &p0EventClassId) noexcept
 Class registration constructor. More...
 
 ~RegisterClass () noexcept
 
const ClassgetEventClass () noexcept
 Get the class of the registered type. More...
 

Detailed Description

template<class T>
class stmi::Event::RegisterClass< T >

Template used to register event classes.

In a subclass of Event you want to register define (ex. KeyEvent):

class KeyEvent : public Event {
public:
  ...
  static const char* const s_sClassId;
  static const Event::Class& getClass()
  {
    static const Event::Class s_oKeyClass = s_oInstall.getEventClass();
    return s_oKeyClass;
  }
private:
  static RegisterClass<KeyEvent> s_oInstall;
  ...
}

with the instantiation

const char* const KeyEvent::s_sClassId = "KeyEvent";
// this instance registers the class!
Event::RegisterClass<KeyEvent> KeyEvent::s_oInstall(s_sClassId);

Beware! No registered class should be subclass of another registered class!

Constructor & Destructor Documentation

◆ RegisterClass()

template<class T >
stmi::Event::RegisterClass< T >::RegisterClass ( const char *const &  p0EventClassId)
inlineexplicitnoexcept

Class registration constructor.

The class id must be a statically defined unique ascii string with length > 0.

Parameters
p0EventClassIdThe class id. Can't be nullptr.

◆ ~RegisterClass()

template<class T >
stmi::Event::RegisterClass< T >::~RegisterClass ( )
inlinenoexcept

Member Function Documentation

◆ getEventClass()

template<class T >
const Class& stmi::Event::RegisterClass< T >::getEventClass ( )
inlinenoexcept

Get the class of the registered type.

Returns
A non-empty class.