File indexing completed on 2024-05-19 04:25:10

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KISSTATICINITIALIZER_H
0007 #define KISSTATICINITIALIZER_H
0008 
0009 #ifndef CONCAT
0010 #define CONCAT(a, b) CONCAT_IMPL(a, b)
0011 #define CONCAT_IMPL(a, b) a ## b
0012 #endif
0013 
0014 #define KIS_DECLARE_STATIC_INITIALIZER_IMPL(uniqueId)  \
0015     static void CONCAT(initializerFunc, uniqueId)(); \
0016 \
0017     class CONCAT(InitializerStruct, uniqueId) \
0018     { \
0019         public: \
0020         CONCAT(InitializerStruct, uniqueId)(void (*initializer)()) { \
0021             initializer(); \
0022         } \
0023     }; \
0024 \
0025     static CONCAT(InitializerStruct, uniqueId) CONCAT(__initializerVariable, uniqueId)(&CONCAT(initializerFunc, uniqueId)); \
0026 \
0027     void CONCAT(initializerFunc, uniqueId)()
0028 
0029 /**
0030  * Sometimes we need to declare a static object that performs some actions on Krita
0031  * loading, e.g. to register Qt's metatype for a Krita type. This macro helps with that:
0032  *
0033  * KIS_DECLARE_STATIC_INITIALIZER {
0034  *     qRegisterMetaType<KoResourceSP>("KoResourceSP");
0035  * }
0036  */
0037 
0038 #define KIS_DECLARE_STATIC_INITIALIZER KIS_DECLARE_STATIC_INITIALIZER_IMPL(__COUNTER__)
0039 
0040 
0041 #endif // KISSTATICINITIALIZER_H