7#ifndef NETWORKMANAGERQT_MACROS_H
8#define NETWORKMANAGERQT_MACROS_H
10#define NM_GLOBAL_STATIC_STRUCT_NAME(NAME)
11typedef void (*NmCleanUpFunction)();
12class NmCleanUpGlobalStatic
15 NmCleanUpFunction func;
17 inline ~NmCleanUpGlobalStatic()
23#define NM_GLOBAL_STATIC(TYPE, NAME) NM_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
26#define NM_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
27 static QBasicAtomicPointer<TYPE > _nm_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \
28 static bool _nm_static_##NAME##_destroyed; \
29 static struct NM_GLOBAL_STATIC_STRUCT_NAME(NAME) \
31 inline bool isDestroyed() const \
33 return _nm_static_##NAME##_destroyed; \
35 inline bool exists() const \
37 return _nm_static_##NAME != 0; \
39 inline operator TYPE*() \
41 return operator->(); \
43 inline TYPE *operator->() \
45 if (!_nm_static_##NAME) { \
46 if (isDestroyed()) { \
47 qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
48 "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \
50 TYPE *x = new TYPE ARGS; \
51 if (!_nm_static_##NAME.testAndSetOrdered(0, x) \
52 && _nm_static_##NAME != x ) { \
55 static NmCleanUpGlobalStatic cleanUpObject = { destroy }; \
58 return _nm_static_##NAME; \
60 inline TYPE &operator*() \
62 return *operator->(); \
64 static void destroy() \
66 _nm_static_##NAME##_destroyed = true; \
67 TYPE *x = _nm_static_##NAME; \
68 _nm_static_##NAME = 0; \
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:13 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.