GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
Design Patterns

Reusable singleton, factory, and locking helpers. More...

Classes

class  gmp::dp::spin_lock
 A minimal spin lock built on std::atomic_flag. More...
 
class  gmp::object_factory< AbstractProduct, ConstructorArgs >
 A singleton-backed runtime factory that creates products by string key. More...
 
class  gmp::singleton< T, LongLifeTime >
 CRTP-based singleton helper with optional dead-reference recovery. More...
 
class  gmp::singleton< T, false >
 Default singleton specialization using a function-local static object. More...
 
class  gmp::singleton< T, true >
 Singleton specialization with dead-reference recovery support. More...
 

Macros

#define GMP_FACTORY_REGISTER_WITH_ARGS(AbstractProduct, ConstructorArgs, ConcreteProduct)
 
#define GMP_FACTORY_REGISTER_NO_ARGS(AbstractProduct, ConcreteProduct)
 
#define GMP_FACTORY_REGISTER(AbstractProduct, ConstructorArgs, ...)
 Register one or more concrete product types with an object factory.
 
#define GMP_DISABLE_CONSTRUCTION(Class)
 Prevent direct public construction of a singleton-derived type.
 

Variables

static T * gmp::singleton< T, true >::pInstance_
 
static bool gmp::singleton< T, true >::destroyed_
 

Detailed Description

Macro Definition Documentation

◆ GMP_DISABLE_CONSTRUCTION

#define GMP_DISABLE_CONSTRUCTION (   Class)

This macro grants gmp::singleton<Class> friendship and makes the default constructor private, which is a common pattern for CRTP singleton types.

Parameters
ClassThe singleton-derived class type.
Example
struct logger : gmp::singleton<logger> {
};
CRTP-based singleton helper with optional dead-reference recovery.
Definition singleton.hpp:54
#define GMP_DISABLE_CONSTRUCTION(Class)
Prevent direct public construction of a singleton-derived type.

Definition at line 181 of file singleton.hpp.

◆ GMP_FACTORY_REGISTER

#define GMP_FACTORY_REGISTER (   AbstractProduct,
  ConstructorArgs,
  ... 
)

This macro creates static registration objects for gmp::object_factory<AbstractProduct, ...>. It supports both single constructor-argument forms and tuple forms, and it also supports explicit (key, type) registration pairs.

Parameters
AbstractProductThe abstract product base type managed by the factory.
ConstructorArgsEither a single constructor argument type or a tuple of types.
...Concrete product registrations. Each item can be:
  • a concrete type name, using that type name as the registration key
  • a tuple (key, ConcreteType) for an explicit string key
Example
GMP_FACTORY_REGISTER(shape, (), circle, square)
GMP_FACTORY_REGISTER(shape, (), ("round", circle), ("box", square))
GMP_FACTORY_REGISTER(widget, (int, std::string), basic_widget, fancy_widget)
#define GMP_FACTORY_REGISTER(AbstractProduct, ConstructorArgs,...)
Register one or more concrete product types with an object factory.

Definition at line 184 of file object_factory.hpp.

◆ GMP_FACTORY_REGISTER_NO_ARGS

#define GMP_FACTORY_REGISTER_NO_ARGS (   AbstractProduct,
  ConcreteProduct 
)

Definition at line 158 of file object_factory.hpp.

◆ GMP_FACTORY_REGISTER_WITH_ARGS

#define GMP_FACTORY_REGISTER_WITH_ARGS (   AbstractProduct,
  ConstructorArgs,
  ConcreteProduct 
)

Definition at line 155 of file object_factory.hpp.

Variable Documentation

◆ destroyed_

template<typename T >
bool gmp::singleton< T, true >::destroyed_
staticprotected

Definition at line 158 of file singleton.hpp.

◆ pInstance_

template<typename T >
T * gmp::singleton< T, true >::pInstance_
staticprotected

Definition at line 157 of file singleton.hpp.