TSDuck v3.38-3708
MPEG Transport Stream Toolkit
|
Helper for singleton definition. More...
Macros | |
#define | TS_DECLARE_SINGLETON(classname) |
Singleton class declaration. | |
#define | TS_DEFINE_SINGLETON(fullclassname) |
Singleton class definition. | |
#define | TS_STATIC_INSTANCE(ObjectClass, ObjectArgs, StaticInstanceClass) |
Local declaration of a static object regardless of modules initialization order. | |
Helper for singleton definition.
#define TS_DECLARE_SINGLETON | ( | classname | ) |
Singleton class declaration.
The macro TS_DECLARE_SINGLETON must be used inside the singleton class declaration.
classname | Name of the singleton class, without namespace or outer class name. |
Example code:
The class becomes a singleton. The default contructor is private. Use static Instance() method to get the instance of the singleton.
#define TS_DEFINE_SINGLETON | ( | fullclassname | ) |
Singleton class definition.
The macro TS_DEFINE_SINGLETON must be used in the implementation of a singleton class.
fullclassname | Fully qualified name of the singleton class. |
Example code:
#define TS_STATIC_INSTANCE | ( | ObjectClass, | |
ObjectArgs, | |||
StaticInstanceClass | |||
) |
Local declaration of a static object regardless of modules initialization order.
This macro is a variant of the singleton pattern. Instead of being part of a user-defined class, this macro instantiates an object of an existing class. The constructor arguments are passed to the macro.
The macro TS_STATIC_INSTANCE creates a static object inside the anonymous namespace of the module where it is expanded.
Example using the std::string
type: Two static objects Foo1
and Foo2
are created. Remember that Foo1
and Foo2
are not the name of objects but the names of the encapsulating classes of the objects. The first static object is initialized by the default constructor and the parameter ObjectArgs of the macro is simply the empty argument list ()
. The second static object is built by the constructor std::string (size_t, char)
and the parameter ObjectArgs is a list of two parameters (4, '=')
.
ObjectClass | The name of the class of the static object. This must be an existing class. |
ObjectArgs | The initializer list, enclosed within parentheses, of the constructor of the static instance. Use () if there is no initializer. |
StaticInstanceClass | The name of the new class which encapsulates the static instance. This class is declared by the expansion of the macro. |