TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Helper for singleton definition. More...
Namespaces | |
namespace | ts |
TSDuck namespace, containing all TSDuck classes and functions. | |
Macros | |
#define | TS_DECLARE_GLOBAL(constness, objtype, objname) |
Global object declaration. | |
#define | TS_DECLARE_GLOBAL_WRAPPER(exportness, constness, objtype, objname) |
Support macro for TS_DECLARE_GLOBAL, do not use directly. | |
#define | TS_DECLARE_SINGLETON(classname) |
Singleton class declaration. | |
#define | TS_DECLARE_SINGLETON_BASE(constness, objtype) |
Support macro for TS_DECLARE_SINGLETON, do not use directly. | |
#define | TS_DEFINE_GLOBAL(constness, objtype, fullobjname, initializer) |
Global object definition. | |
#define | TS_DEFINE_GLOBAL_ATEXIT(constness, objtype, fullobjname, initializer, atexitfunction) |
Global object definition, with specific atexit() function. | |
#define | TS_DEFINE_SINGLETON(fullclassname) |
Singleton class definition. | |
#define | TS_DEFINE_SINGLETON_ATEXIT(fullclassname, atexitfunction) |
Singleton class definition, with specific atexit() function. | |
#define | TS_DEFINE_SINGLETON_BASE(fullclassname, constness, objtype, initializer, atexitfunction) |
Support macro for TS_DEFINE_SINGLETON, do not use directly. | |
#define | TS_STATIC_INSTANCE(constness, objtype, objname, initializer) |
Local declaration of a static object regardless of modules initialization order. | |
#define | TS_STATIC_INSTANCE_ATEXIT(constness, objtype, objname, initializer, atexitfunction) |
Local declaration of a static object regardless of modules initialization order, with specific atexit() function. | |
Functions | |
int | ts::atexit (void(*func)()) |
Register a function to execute when the application exits. | |
void | ts::atexit (void(*func)(void *), void *param=nullptr) |
Register a function to execute when the application exits (with a parameter). | |
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 constructor 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. |
#define TS_DEFINE_SINGLETON_ATEXIT | ( | fullclassname, | |
atexitfunction | |||
) |
Singleton class definition, with specific atexit() function.
fullclassname | Fully qualified name of the singleton class. |
atexitfunction | The atexit() function to use to register the destructor. Typical values are ts::atexit, std::atexit, OPENSSL_atexit. |
#define TS_DECLARE_GLOBAL | ( | constness, | |
objtype, | |||
objname | |||
) |
Global object declaration.
The macros TS_DECLARE_GLOBAL and TS_DEFINE_GLOBAL are used to declare a global object of a known type. This kind of object cannot be simply statically declared with something like "extern const Foo obj" if it requires a dynamic constructor. Because of the undefined initialization order in the list of modules, the object could be used before being initialized. These macros ensure that the object is dynamically created the first time it is used (thread-safe).
The actual object is wrapped into a singleton and can be accessed using the operators "*" and "->".
constness | Either "const" or empty. |
objtype | Fully qualified type name of the actual object. This object is wrapped into a singleton. |
objname | Name of the global object. Use operators "*" and "->" to access the objtype object. |
Example code:
#define TS_DEFINE_GLOBAL | ( | constness, | |
objtype, | |||
fullobjname, | |||
initializer | |||
) |
Global object definition.
constness | Either "const" or empty. |
objtype | Fully qualified type name of the actual object. This object is wrapped into a singleton. |
fullobjname | Fully qualified name of the global object, including namespace if necessary. |
initializer | The initializer list, enclosed within parentheses, of the constructor of the static instance. Use "()" if there is no initializer. |
#define TS_DEFINE_GLOBAL_ATEXIT | ( | constness, | |
objtype, | |||
fullobjname, | |||
initializer, | |||
atexitfunction | |||
) |
Global object definition, with specific atexit() function.
constness | Either "const" or empty. |
objtype | Fully qualified type name of the actual object. This object is wrapped into a singleton. |
fullobjname | Fully qualified name of the global object, including namespace if necessary. |
initializer | The initializer list, enclosed within parentheses, of the constructor of the static instance. Use "()" if there is no initializer. |
atexitfunction | The atexit() function to use to register the destructor. Typical values are ts::atexit, std::atexit, OPENSSL_atexit. |
#define TS_STATIC_INSTANCE | ( | constness, | |
objtype, | |||
objname, | |||
initializer | |||
) |
Local declaration of a static object regardless of modules initialization order.
This macro is a variant of the TS_DECLARE_GLOBAL / TS_DEFINE_GLOBAL pattern.//! 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, '=')
.
constness | Either TS_VARIABLE or TS_CONST (if the object is constant and fully defined by its initializer). |
objtype | Fully qualified type name of the actual object. This object is wrapped into a singleton. |
objname | Name of the static object. Use operators "*" and "->" to access the objtype object. |
initializer | The initializer list, enclosed within parentheses, of the constructor of the static instance. Use "()" if there is no initializer. |
#define TS_STATIC_INSTANCE_ATEXIT | ( | constness, | |
objtype, | |||
objname, | |||
initializer, | |||
atexitfunction | |||
) |
Local declaration of a static object regardless of modules initialization order, with specific atexit() function.
constness | Either TS_VARIABLE or TS_CONST (if the object is constant and fully defined by its initializer). |
objtype | Fully qualified type name of the actual object. This object is wrapped into a singleton. |
objname | Name of the static object. Use operators "*" and "->" to access the objtype object. |
initializer | The initializer list, enclosed within parentheses, of the constructor of the static instance. Use "()" if there is no initializer. |
atexitfunction | The atexit() function to use to register the destructor. Typical values are ts::atexit, std::atexit, OPENSSL_atexit. |