-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingleton_config.h
496 lines (396 loc) · 16.5 KB
/
singleton_config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/**************************************************************************
* Singleton v1.0.2
*
* Singleton is a C/CPP library for creating portable singleton objects.
* It is designed to be easy to use and easy to integrate into your project
* using a single header file (stb style).
*
* This file is part of the Singleton project that is under Anti-NN License.
* https://github.com/MasterLaplace/Anti-NN_LICENSE
* Copyright © 2024 by @MasterLaplace, All rights reserved.
*
* Singleton is a free software: you can redistribute it and/or modify
* it under the terms of the Anti-NN License as published by MasterLaplace.
* See the Anti-NN License for more details.
*
* @file singleton_config.h
* @brief Compile-Time Configuration Parameters for Singleton.
*
* @author @MasterLaplace
* @version 1.0.2
* @date 2024-11-06
**************************************************************************/
// clang-format off
#ifndef SINGLETON_CONFIG_H_
#define SINGLETON_CONFIG_H_
#ifdef __cplusplus
#include <utility>
#include <type_traits>
#include <cstddef>
#include <cstdint>
#else
#include <stddef.h>
#include <stdint.h>
#endif
#ifndef LAPLACE_CONFIG_UTILS
#define LAPLACE_CONFIG_UTILS
////////////////////////////////////////////////////////////
// Define shared portable macros for various compilers
////////////////////////////////////////////////////////////
#define LPL_NEED_COMMA struct _
#define LPL_ATTRIBUTE(key) __attribute__((key))
#define LPL_UNUSED_ATTRIBUTE LPL_ATTRIBUTE(unused)
#define LPL_UNUSED(x) (void)(x)
////////////////////////////////////////////////////////////
// Define portable NULL pointer using C++11 nullptr keyword
////////////////////////////////////////////////////////////
#if defined(__cplusplus) && __cplusplus >= 201103L
#define lpl_nullptr nullptr
#elif !defined(NULL)
#define lpl_nullptr ((void*)0)
#else
#define lpl_nullptr NULL
#endif
////////////////////////////////////////////////////////////
// Define boolean type and values
////////////////////////////////////////////////////////////
#if !defined(__bool_true_false_are_defined) && !defined(__cplusplus)
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#elif !defined(__GNUC_PREREQ)
# define __GNUC_PREREQ(maj, min) 0
#endif
////////////////////////////////////////////////////////////
// Define a portable way for packing structures
////////////////////////////////////////////////////////////
/** Usage:
* @example
* LPL_PACKED(struct MyStruct
* {
* int a;
* char b;
* ...
* });
\**********************************************************/
#if defined(_MSC_VER) || defined(_MSVC_LANG)
#define LPL_PACKED( __Declaration__ ) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
#define LPL_PACKED_START __pragma(pack(push, 1))
#define LPL_PACKED_END __pragma(pack(pop))
#elif defined(__GNUC__) || defined(__GNUG__)
#define LPL_PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__))
#define LPL_PACKED_START _Pragma("pack(1)")
#define LPL_PACKED_END _Pragma("pack()")
#else
#define LPL_PACKED( __Declaration__ ) __Declaration__
#define LPL_PACKED_START
#define LPL_PACKED_END
#endif
////////////////////////////////////////////////////////////
// Helper macro to convert a macro to a string
////////////////////////////////////////////////////////////
#define LPL_STRINGIFY(x) #x
#define LPL_TOSTRING(x) LPL_STRINGIFY(x)
#endif /* !LAPLACE_CONFIG_UTILS */
#ifndef SINGLETON_DISTRIBUTION_H_
#define SINGLETON_DISTRIBUTION_H_
////////////////////////////////////////////////////////////
// Identify the Compiler
////////////////////////////////////////////////////////////
#if defined(_MSC_VER) || defined(_MSVC_LANG)
#define SINGLETON_COMPILER_MSVC
#define SINGLETON_COMPILER_STRING "MSVC"
#elif defined(__GNUC__) || defined(__GNUG__)
#define SINGLETON_COMPILER_GCC
#define SINGLETON_COMPILER_STRING "GCC"
#elif defined(__clang__) || defined(__llvm__)
#define SINGLETON_COMPILER_CLANG
#define SINGLETON_COMPILER_STRING "Clang"
#elif defined(__MINGW32__) || defined(__MINGW64__)
#define SINGLETON_COMPILER_MINGW
#define SINGLETON_COMPILER_STRING "MinGW"
#elif defined(__CYGWIN__)
#define SINGLETON_COMPILER_CYGWIN
#define SINGLETON_COMPILER_STRING "Cygwin"
#else
#error [Config@Distribution]: This compiler is not supported by SINGLETON library.
#endif
////////////////////////////////////////////////////////////
// Identify the Operating System
////////////////////////////////////////////////////////////
#if defined(_WIN32) || defined(__WIN32__) || defined(SINGLETON_COMPILER_MINGW) || defined(SINGLETON_COMPILER_CYGWIN)
#define SINGLETON_SYSTEM_WINDOWS
#define SINGLETON_SYSTEM_STRING "Windows"
// Android is based on the Linux SINGLETON, so it has to appear before Linux
#elif defined(__ANDROID__)
#define SINGLETON_SYSTEM_ANDROID
#define SINGLETON_SYSTEM_STRING "Android"
#elif defined(linux) || defined(__linux)
#define SINGLETON_SYSTEM_LINUX
#define SINGLETON_SYSTEM_STRING "Linux"
#elif defined(__unix) || defined(__unix__)
#define SINGLETON_SYSTEM_UNIX
#define SINGLETON_SYSTEM_STRING "Unix"
#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)
#define SINGLETON_SYSTEM_MACOS
#define SINGLETON_SYSTEM_STRING "MacOS"
#elif defined(__FreeBSD__) || defined(__FreeBSD_SINGLETON__)
#define SINGLETON_SYSTEM_FREEBSD
#define SINGLETON_SYSTEM_STRING "FreeBSD"
#elif defined(LAPLACE_KERNEL_PANIC)
#define SINGLETON_SYSTEM_KERNEL
#define SINGLETON_SYSTEM_STRING "Laplace Kernel"
#else
#error [Config@Distribution]: This operating system is not supported by SINGLETON library.
#endif
#ifdef __cplusplus
#define SINGLETON_EXTERN_C extern "C"
#if __cplusplus >= 202203L
#define SINGLETON_CPP23(_) _
#define SINGLETON_CPP20(_) _
#define SINGLETON_CPP17(_) _
#define SINGLETON_CPP14(_) _
#define SINGLETON_CPP11(_) _
#define SINGLETON_CPP99(_) _
#elif __cplusplus >= 202002L
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_) _
#define SINGLETON_CPP17(_) _
#define SINGLETON_CPP14(_) _
#define SINGLETON_CPP11(_) _
#define SINGLETON_CPP99(_) _
#elif __cplusplus >= 201703L
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_) _
#define SINGLETON_CPP14(_) _
#define SINGLETON_CPP11(_) _
#define SINGLETON_CPP99(_) _
#elif __cplusplus >= 201402L
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_)
#define SINGLETON_CPP14(_) _
#define SINGLETON_CPP11(_) _
#define SINGLETON_CPP99(_) _
#elif __cplusplus >= 201103L
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_)
#define SINGLETON_CPP14(_)
#define SINGLETON_CPP11(_) _
#define SINGLETON_CPP99(_) _
#elif __cplusplus >= 199711L
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_)
#define SINGLETON_CPP14(_)
#define SINGLETON_CPP11(_)
#define SINGLETON_CPP99(_) _
#else
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_)
#define SINGLETON_CPP14(_)
#define SINGLETON_CPP11(_)
#define SINGLETON_CPP99(_)
#endif
////////////////////////////////////////////////////////////
// Define a macro to handle cpp features compatibility
////////////////////////////////////////////////////////////
/** Usage:
* @example
* void func() SINGLETON_CPP14([[deprecated]]);
*
* @example
* void func() SINGLETON_CPP([[deprecated]], 14);
\**********************************************************/
#define SINGLETON_CPP(_, version) SINGLETON_CPP##version(_)
#else
#define SINGLETON_EXTERN_C extern
#define SINGLETON_CPP23(_)
#define SINGLETON_CPP20(_)
#define SINGLETON_CPP17(_)
#define SINGLETON_CPP14(_)
#define SINGLETON_CPP11(_)
#define SINGLETON_CPP99(_)
#define SINGLETON_CPP(_, version)
#endif
////////////////////////////////////////////////////////////
// Define helpers to create portable import / export macros for each module
////////////////////////////////////////////////////////////
#if defined(SINGLETON_SYSTEM_WINDOWS)
// Windows compilers need specific (and different) keywords for export and import
#define SINGLETON_API_EXPORT extern "C" __declspec(dllexport)
#define SINGLETON_API_IMPORT SINGLETON_EXTERN_C __declspec(dllimport)
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
#ifdef _MSC_VER
#pragma warning(disable : 4251)
#endif
#else // Linux, FreeBSD, Mac OS X
#if __GNUC__ >= 4
// GCC 4 has special keywords for showing/hidding symbols,
// the same keyword is used for both importing and exporting
#define SINGLETON_API_EXPORT extern "C" __attribute__ ((__visibility__ ("default")))
#define SINGLETON_API_IMPORT SINGLETON_EXTERN_C __attribute__ ((__visibility__ ("default")))
#else
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
#define SINGLETON_API_EXPORT extern "C"
#define SINGLETON_API_IMPORT SINGLETON_EXTERN_C
#endif
#endif
#ifdef SINGLETON_SYSTEM_WINDOWS
// Windows compilers use a different name for the main function
#define SINGLETON_GUI_MAIN(hInstance, hPrevInstance, lpCmdLine, nCmdShow) WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#define SINGLETON_MAIN(ac, av, env) main(int ac, char *av[], char *env[])
#elif defined(SINGLETON_SYSTEM_ANDROID)
// Android doesn't need a main function
#define SINGLETON_GUI_MAIN(app) android_main(struct android_app* app)
#define SINGLETON_MAIN
#elif defined(SINGLETON_SYSTEM_MACOS)
// On MacOS X, we use a Unix main function
#define SINGLETON_MAIN(ac, av, env, apple) main(int ac, char *av[], char *env[], char *apple[])
#else
// Other platforms should use the standard main function
#define SINGLETON_MAIN(ac, av, env) main(int ac, char *av[], char *env[])
#endif
////////////////////////////////////////////////////////////
// Define a portable debug macro
////////////////////////////////////////////////////////////
#if (defined(_DEBUG) || defined(DEBUG)) && !defined(NDEBUG)
#define SINGLETON_DEBUG
#define SINGLETON_DEBUG_STRING "Debug"
#else
#define SINGLETON_DEBUG_STRING "Release"
#endif
////////////////////////////////////////////////////////////
// Define a portable way to declare a function as deprecated
////////////////////////////////////////////////////////////
/** Usage:
* @example "for functions"
* SINGLETON_DEPRECATED void func();
* @example "for structs"
* struct SINGLETON_DEPRECATED MyStruct { ... };
* @example "for enums"
* enum SINGLETON_DEPRECATED MyEnum { ... };
* enum MyEnum {
* MyEnum1 = 0,
* MyEnum2 SINGLETON_DEPRECATED,
* MyEnum3
* };
* @example "for classes"
* class SINGLETON_DEPRECATED MyClass { ... };
\**********************************************************/
#ifdef SINGLETON_DISABLE_DEPRECATION
#define SINGLETON_DEPRECATED
#define SINGLETON_DEPRECATED_MSG(message)
#define SINGLETON_DEPRECATED_VMSG(version, message)
#elif defined(__cplusplus) && (__cplusplus >= 201402)
#define SINGLETON_DEPRECATED [[deprecated]]
#if (__cplusplus >= 201402) && (__cplusplus < 201703)
#define SINGLETON_DEPRECATED_MSG(message) [[deprecated(message)]]
#define SINGLETON_DEPRECATED_VMSG(version, message) \
[[deprecated("since " # version ". " message)]]
#else
#define SINGLETON_DEPRECATED_MSG(message) [[deprecated]]
#define SINGLETON_DEPRECATED_VMSG(version, message) [[deprecated]]
#endif
#elif defined(SINGLETON_COMPILER_MSVC) && (_MSC_VER >= 1400)
#define SINGLETON_DEPRECATED __declspec(deprecated)
#if (_MSC_VER >= 1900)
#define SINGLETON_DEPRECATED_MSG(message) __declspec(deprecated(message))
#define SINGLETON_DEPRECATED_VMSG(version, message) \
__declspec(deprecated("since " # version ". " message))
#else
#define SINGLETON_DEPRECATED_MSG(message) __declspec(deprecated)
#define SINGLETON_DEPRECATED_VMSG(version, message) __declspec(deprecated)
#endif
#elif defined(SINGLETON_COMPILER_CLANG) && defined(__has_feature)
#define SINGLETON_DEPRECATED __attribute__((deprecated))
#if __has_feature(attribute_deprecated_with_message)
#define SINGLETON_DEPRECATED_MSG(message) __attribute__((deprecated(message)))
#define SINGLETON_DEPRECATED_VMSG(version, message) \
__attribute__((deprecated("since " # version ". " message)))
#else
#define SINGLETON_DEPRECATED_MSG(message) __attribute__((deprecated))
#define SINGLETON_DEPRECATED_VMSG(version, message) __attribute__((deprecated))
#endif
#elif defined(SINGLETON_COMPILER_GCC) && defined(__GNUC__) && __GNUC_PREREQ(4, 5)
#define SINGLETON_DEPRECATED __attribute__((deprecated))
#if defined(SINGLETON_COMPILER_GCC) && defined(__GNUC__) && __GNUC_PREREQ(4, 9)
#define SINGLETON_DEPRECATED_MSG(message) __attribute__((deprecated(message)))
#define SINGLETON_DEPRECATED_VMSG(version, message) \
__attribute__((deprecated("since " # version ". " message)))
#else
#define SINGLETON_DEPRECATED_MSG(message) __attribute__((deprecated))
#define SINGLETON_DEPRECATED_VMSG(version, message) __attribute__((deprecated))
#endif
#else
#pragma message("WARNING: SINGLETON_DEPRECATED not supported on this compiler")
#define SINGLETON_DEPRECATED
#define SINGLETON_DEPRECATED_MSG(message)
#define SINGLETON_DEPRECATED_VMSG(version, message)
#endif
#endif /* !SINGLETON_DISTRIBUTION_H_ */
#ifndef SINGLETON_VERSION_H_
#define SINGLETON_VERSION_H_
////////////////////////////////////////////////////////////
// Define the SINGLETON version
////////////////////////////////////////////////////////////
#ifdef FLAG_VERSION_MAJOR
#define SINGLETON_VERSION_MAJOR FLAG_VERSION_MAJOR
#else
#define SINGLETON_VERSION_MAJOR 1
#endif
#ifdef FLAG_VERSION_MINOR
#define SINGLETON_VERSION_MINOR FLAG_VERSION_MINOR
#else
#define SINGLETON_VERSION_MINOR 0
#endif
#ifdef FLAG_VERSION_PATCH
#define SINGLETON_VERSION_PATCH FLAG_VERSION_PATCH
#else
#define SINGLETON_VERSION_PATCH 2
#endif
#ifdef FLAG_VERSION_TWEAK
#define SINGLETON_VERSION_TWEAK FLAG_VERSION_TWEAK
#else
#define SINGLETON_VERSION_TWEAK 0
#endif
////////////////////////////////////////////////////////////
// Define the SINGLETON version number
////////////////////////////////////////////////////////////
#define SINGLETON_VERSION \
(SINGLETON_VERSION_MAJOR * 1000000 + \
SINGLETON_VERSION_MINOR * 10000 + \
SINGLETON_VERSION_PATCH * 100 + \
SINGLETON_VERSION_TWEAK)
#define SINGLETON_PREREQ_VERSION(maj, min, pat) (SINGLETON_VERSION >= (maj * 1000000 + min * 10000 + pat * 100))
////////////////////////////////////////////////////////////
// Define the SINGLETON version concatenated
////////////////////////////////////////////////////////////
#define SINGLETON_VERSION_CCT SINGLETON_VERSION_MAJOR##_##SINGLETON_VERSION_MINOR##_##SINGLETON_VERSION_PATCH##_##SINGLETON_VERSION_TWEAK
////////////////////////////////////////////////////////////
// Define the SINGLETON version string
////////////////////////////////////////////////////////////
#define SINGLETON_VERSION_STRING \
LPL_TOSTRING(SINGLETON_VERSION_MAJOR) "." \
LPL_TOSTRING(SINGLETON_VERSION_MINOR) "." \
LPL_TOSTRING(SINGLETON_VERSION_PATCH) "." \
LPL_TOSTRING(SINGLETON_VERSION_TWEAK)
#endif /* !SINGLETON_VERSION_H_ */
////////////////////////////////////////////////////////////
// Compile-Time Configuration Parameters
////////////////////////////////////////////////////////////
#define SINGLETON_CONFIG_STRING \
"SINGLETON_VERSION=" SINGLETON_VERSION_STRING "\n" \
"SINGLETON_SYSTEM=" SINGLETON_SYSTEM_STRING "\n" \
"SINGLETON_COMPILER=" SINGLETON_COMPILER_STRING "\n" \
"SINGLETON_DEBUG=" SINGLETON_DEBUG_STRING "\n"
#endif /* !SINGLETON_CONFIG_H_ */
// clang-format on