Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::Registrator< TRegisterable > Class Template Reference

Helper class for registering a class at program startup. More...

#include <registrator.hpp>

Public Member Functions

void emptyFunc ()
 

Static Public Member Functions

static RegistratorgetRegistrator ()
 

Detailed Description

template<typename TRegisterable>
class ToyMaker::Registrator< TRegisterable >

Helper class for registering a class at program startup.

It accomplishes this by:

  • Forcing an implementation of static function registerSelf() using CRTP, called here.
  • Ensuring its owner's registerSelf() function is called during the static initialization phase of the program.

Usage:

class YourClass {
// ... the rest of your class definition
// ...
YourClass() {s_registrator.emptyFunc()} // NOTE: Explicit constructor definition
// NOTE: This function will be called by constructor Registrator<YourClass>()
static YourReturnType registerSelf() {
// NOTE: Ensure correct order of registration for related classes,
// hopefully avoiding static initialization order fiasco
Registrator<ClassYouDependOn>::getRegistrator(); //< Calls ClassYouDependOn's registerSelf() in turn.
Registrator<AnotherClassYouDependOn>::getRegistrator();
// NOTE: ... whatever the class needs to do to actually register itself
// wherever it needs to be registered
}
// NOTE: Declaration and initialization of the registrator static
// member associated with your class.
inline static Registrator<YourClass> s_registrator { Registrator<YourClass>::getRegistrator() };
// ...
// The rest of your class definition
};

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