ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7///
8/// This header does not belong to a module of \alib, but is
9/// included in any \alibbuild.
10/// Its purposes are:
11/// - To identify given #"alib_macros_config" related to module selection and enable
12/// corresponding configuration macros (that may be not given) of mandatory dependent modules.
13/// - Detect and assert C++ language version.
14/// - Define preprocessor utilities as needed throughout \alib.
15//==================================================================================================
16#ifndef INL_ALIB
17#define INL_ALIB 1
18#pragma once
19
20#define ALIB_VERSION 2511
21#define ALIB_REVISION 0
22
23#ifndef DOXYGEN
24# define DOXYGEN 0
25#else
26 //##############################################################################################
27 //### Definitions of Configuration Macros needed by doxygen
28 //##############################################################################################
29# define ALIB_BASE_DIR
30# define ALIB_GCC
31# define ALIB_EXT_LIB_THREADS_AVAILABLE
32# define ALIB_C20_MODULES
33
34# define ALIB_API_IS_DLL
35# define ALIB_API_NO_DLL
36
37# define ALIB_CPP_STANDARD
38
39# define ALIB_DEBUG
40# define ALIB_SINGLE_THREADED
41
42# define ALIB_SIZEOF_INTGAP
43# define ALIB_INTGAP_TYPE
44# define ALIB_SIZEOF_LONGDOUBLE_REPORTED
45# define ALIB_SIZEOF_LONGDOUBLE_WRITTEN
46
47# define ALIB_GTEST
48# define ALIB_DEBUG_ASSERTION_PRINTABLES
49# define DOXYGEN
50# define ALIB_PRECOMPILED_HEADER
51
52
53# define ALIB_FEAT_SINGLETON_MAPPED 1
54# define ALIB_DEBUG_ALLOCATIONS 1
55# define ALIB_DEBUG_BOXING 1
56# define ALIB_DEBUG_STRINGS 1
57# define ALIB_DEBUG_CONTAINERS 1
58# define ALIB_DEBUG_CRITICAL_SECTIONS 1
59# define ALIB_DEBUG_MEMORY 1
60# define ALIB_DEBUG_ARRAY_COMPRESSION 1
61# define ALIB_DEBUG_RESOURCES 1
62# define ALIB_FEAT_BOOST_REGEX 1
63# define ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS 1
64# define ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS 1
65# define ALIB_FEAT_BOXING_BIJECTIVE_FLOATS 1
66# define ALOX_DBG_LOG 1
67# define ALOX_REL_LOG 1
68# define ALOX_DBG_LOG_CI 1
69# define ALOX_REL_LOG_CI 1
70
71#endif
72
73
74#include <version>
75#include <concepts>
76#include <type_traits>
77
78#if !DOXYGEN
79
80//##################################################################################################
81// Single-threaded library?
82//##################################################################################################
83#if !defined( ALIB_SINGLE_THREADED )
84# define ALIB_SINGLE_THREADED 0
85#endif
86#if ALIB_SINGLE_THREADED
87# define IF_ALIB_SINGLE_THREADED(...) __VA_ARGS__
88# define IFNOT_ALIB_SINGLE_THREADED(...)
89#else
90# define IF_ALIB_SINGLE_THREADED(...)
91# define IFNOT_ALIB_SINGLE_THREADED(...) __VA_ARGS__
92#endif
93
94//##################################################################################################
95// No module selection macro given but threads? -> choose ALL
96//##################################################################################################
97#if !defined( ALIB_ALOX ) \
98 && !defined( ALIB_APP ) \
99 && !defined( ALIB_BITBUFFER ) \
100 && !defined( ALIB_BOXING ) \
101 && !defined( ALIB_CAMP ) \
102 && !defined( ALIB_CLI ) \
103 && !defined( ALIB_VARIABLES ) \
104 && !defined( ALIB_CONTAINERS ) \
105 && !defined( ALIB_ENUMRECORDS ) \
106 && !defined( ALIB_EXCEPTIONS ) \
107 && !defined( ALIB_EXPRESSIONS ) \
108 && !defined( ALIB_FILES ) \
109 && !defined( ALIB_FORMAT ) \
110 && !defined( ALIB_MONOMEM ) \
111 && !defined( ALIB_RESOURCES ) \
112 && !defined( ALIB_SINGLETONS ) \
113 && !defined( ALIB_STRINGS ) \
114 && !defined( ALIB_SYSTEM ) \
115 && !defined( ALIB_THREADMODEL )
116# define ALIB_APP 1
117# define ALIB_BITBUFFER 1
118# define ALIB_EXPRESSIONS 1
119# define ALIB_FILES 1
120# if !ALIB_SINGLE_THREADED
121# define ALIB_THREADMODEL 1
122# endif
123#elif defined(ALIB_THREADMODEL ) && ALIB_SINGLE_THREADED
124# error "ALib Module THREADMODEL requested, while configuration macro ALIB_SINGLE_THREADED is set"
125#endif
126
127#if !defined(ALIB_ALOX )
128# define ALIB_ALOX 0
129#endif
130#if !defined(ALIB_APP )
131# define ALIB_APP 0
132#endif
133#if !defined(ALIB_BITBUFFER )
134# define ALIB_BITBUFFER 0
135#endif
136#if !defined(ALIB_BOXING )
137# define ALIB_BOXING 0
138#endif
139#if !defined(ALIB_CAMP )
140# define ALIB_CAMP 0
141#endif
142#if !defined(ALIB_CLI )
143# define ALIB_CLI 0
144#endif
145#if !defined(ALIB_CONTAINERS )
146# define ALIB_CONTAINERS 0
147#endif
148#if !defined(ALIB_ENUMRECORDS )
149# define ALIB_ENUMRECORDS 0
150#endif
151#if !defined(ALIB_EXCEPTIONS )
152# define ALIB_EXCEPTIONS 0
153#endif
154#if !defined(ALIB_EXPRESSIONS )
155# define ALIB_EXPRESSIONS 0
156#endif
157#if !defined(ALIB_FILES )
158# define ALIB_FILES 0
159#endif
160#if !defined(ALIB_FORMAT )
161# define ALIB_FORMAT 0
162#endif
163#if !defined(ALIB_MONOMEM )
164# define ALIB_MONOMEM 0
165#endif
166#if !defined(ALIB_RESOURCES )
167# define ALIB_RESOURCES 0
168#endif
169#if !defined(ALIB_SINGLETONS )
170# define ALIB_SINGLETONS 0
171#endif
172#if !defined(ALIB_STRINGS )
173# define ALIB_STRINGS 0
174#endif
175#if !defined(ALIB_SYSTEM )
176# define ALIB_SYSTEM 0
177#endif
178#if !defined( ALIB_THREADMODEL )
179# define ALIB_THREADMODEL 0
180#endif
181#if !defined(ALIB_VARIABLES)
182# define ALIB_VARIABLES 0
183#endif
184
185//##################################################################################################
186// Resolve module dependencies
187//##################################################################################################
188#if ALIB_APP
189# undef ALIB_ALOX
190# define ALIB_ALOX 1
191# undef ALIB_CLI
192# define ALIB_CLI 1
193#endif
194#if ALIB_EXPRESSIONS
195# undef ALIB_CAMP
196# define ALIB_CAMP 1
197#endif
198#if ALIB_CLI
199# undef ALIB_CAMP
200# define ALIB_CAMP 1
201#endif
202#if ALIB_FILES
203# undef ALIB_CAMP
204# define ALIB_CAMP 1
205#endif
206#if ALIB_ALOX
207# undef ALIB_CAMP
208# define ALIB_CAMP 1
209#endif
210#if ALIB_CAMP
211# undef ALIB_FORMAT
212# define ALIB_FORMAT 1
213# undef ALIB_VARIABLES
214# define ALIB_VARIABLES 1
215#endif
216#if ALIB_VARIABLES
217# undef ALIB_CONTAINERS
218# define ALIB_CONTAINERS 1
219# undef ALIB_MONOMEM
220# define ALIB_MONOMEM 1
221# undef ALIB_SYSTEM
222# define ALIB_SYSTEM 1
223#endif
224#if ALIB_FORMAT
225# undef ALIB_EXCEPTIONS
226# define ALIB_EXCEPTIONS 1
227#endif
228#if ALIB_EXCEPTIONS
229# undef ALIB_BOXING
230# define ALIB_BOXING 1
231# undef ALIB_ENUMRECORDS
232# define ALIB_ENUMRECORDS 1
233# undef ALIB_RESOURCES
234# define ALIB_RESOURCES 1
235#endif
236#if ALIB_THREADMODEL
237# undef ALIB_BOXING
238# define ALIB_BOXING 1
239# undef ALIB_CONTAINERS
240# define ALIB_CONTAINERS 1
241# undef ALIB_MONOMEM
242# define ALIB_MONOMEM 1
243#endif
244#if ALIB_SYSTEM
245# undef ALIB_BOXING
246# define ALIB_BOXING 1
247# undef ALIB_ENUMRECORDS
248# define ALIB_ENUMRECORDS 1
249#endif
250#if ALIB_BITBUFFER
251# undef ALIB_CONTAINERS
252# define ALIB_CONTAINERS 1
253# undef ALIB_MONOMEM
254# define ALIB_MONOMEM 1
255#endif
256#if ALIB_RESOURCES
257# undef ALIB_CONTAINERS
258# define ALIB_CONTAINERS 1
259# undef ALIB_MONOMEM
260# define ALIB_MONOMEM 1
261# undef ALIB_STRINGS
262# define ALIB_STRINGS 1
263#endif
264#if ALIB_ENUMRECORDS
265# undef ALIB_SINGLETONS
266# define ALIB_SINGLETONS 1
267# undef ALIB_STRINGS
268# define ALIB_STRINGS 1
269#endif
270#if ALIB_BOXING
271# undef ALIB_SINGLETONS
272# define ALIB_SINGLETONS 1
273#endif
274
275//##################################################################################################
276// if !DOXYGEN
277//##################################################################################################
278#else
279#define ALIB_ALOX 1
280#define ALIB_APP 1
281#define ALIB_BITBUFFER 1
282#define ALIB_BOXING 1
283#define ALIB_CAMP 1
284#define ALIB_FORMAT 1
285#define ALIB_EXCEPTIONS 1
286#define ALIB_SYSTEM 1
287#define ALIB_RESOURCES 1
288#define ALIB_CLI 1
289#define ALIB_VARIABLES 1
290#define ALIB_CONTAINERS 1
291#define ALIB_ENUMRECORDS 1
292#define ALIB_EXPRESSIONS 1
293#define ALIB_FILES 1
294#define ALIB_MONOMEM 1
295#define ALIB_SINGLETONS 1
296#define ALIB_STRINGS 1
297#define ALIB_THREADMODEL 1
298#endif //!DOXYGEN
299
300//##################################################################################################
301// Macros for checking availability of modules
302//##################################################################################################
303#define ALIB_DOCUMENTATION_URL "https://alib.dev/"
304
305#define ALIB_ASSERT_MODULE(modulename) \
306static_assert( ALIB_ ## modulename, \
307 "This module is not included in the ALib Build. " \
308 "See " ALIB_DOCUMENTATION_URL "alib_manual.html for more information" ); \
309
310//##################################################################################################
311// Macros to select code (without using #if/#endif)
312//##################################################################################################
313#if ALIB_ALOX
314# define IF_ALIB_ALOX(...) __VA_ARGS__
315# define IFNOT_ALIB_ALOX(...)
316#else
317# define IF_ALIB_ALOX(...)
318# define IFNOT_ALIB_ALOX(...) __VA_ARGS__
319#endif
320
321#if ALIB_APP
322# define IF_ALIB_APP(...) __VA_ARGS__
323# define IFNOT_ALIB_APP(...)
324#else
325# define IF_ALIB_APP(...)
326# define IFNOT_ALIB_APP(...) __VA_ARGS__
327#endif
328
329#if ALIB_BITBUFFER
330# define IF_ALIB_BITBUFFER(...) __VA_ARGS__
331# define IFNOT_ALIB_BITBUFFER(...)
332#else
333# define IF_ALIB_BITBUFFER(...)
334# define IFNOT_ALIB_BITBUFFER(...) __VA_ARGS__
335#endif
336
337#if ALIB_BOXING
338# define IF_ALIB_BOXING(...) __VA_ARGS__
339# define IFNOT_ALIB_BOXING(...)
340#else
341# define IF_ALIB_BOXING(...)
342# define IFNOT_ALIB_BOXING(...) __VA_ARGS__
343#endif
344
345#if ALIB_FORMAT
346# define IF_ALIB_FORMAT(...) __VA_ARGS__
347# define IFNOT_ALIB_FORMAT(...)
348#else
349# define IF_ALIB_FORMAT(...)
350# define IFNOT_ALIB_FORMAT(...) __VA_ARGS__
351#endif
352
353#if ALIB_EXCEPTIONS
354# define IF_ALIB_EXCEPTIONS(...) __VA_ARGS__
355# define IFNOT_ALIB_EXCEPTIONS(...)
356#else
357# define IF_ALIB_EXCEPTIONS(...)
358# define IFNOT_ALIB_EXCEPTIONS(...) __VA_ARGS__
359#endif
360
361#if ALIB_SYSTEM
362# define IF_ALIB_SYSTEM(...) __VA_ARGS__
363# define IFNOT_ALIB_SYSTEM(...)
364#else
365# define IF_ALIB_SYSTEM(...)
366# define IFNOT_ALIB_SYSTEM(...) __VA_ARGS__
367#endif
368
369#if ALIB_RESOURCES
370# define IF_ALIB_RESOURCES(...) __VA_ARGS__
371# define IFNOT_ALIB_RESOURCES(...)
372#else
373# define IF_ALIB_RESOURCES(...)
374# define IFNOT_ALIB_RESOURCES(...) __VA_ARGS__
375#endif
376
377#if ALIB_CLI
378# define IF_ALIB_CLI(...) __VA_ARGS__
379# define IFNOT_ALIB_CLI(...)
380#else
381# define IF_ALIB_CLI(...)
382# define IFNOT_ALIB_CLI(...) __VA_ARGS__
383#endif
384
385#if ALIB_VARIABLES
386# define IF_ALIB_VARIABLES(...) __VA_ARGS__
387# define IFNOT_ALIB_VARIABLES(...)
388#else
389# define IF_ALIB_VARIABLES(...)
390# define IFNOT_ALIB_VARIABLES(...) __VA_ARGS__
391#endif
392
393#if ALIB_CONTAINERS
394# define IF_ALIB_CONTAINERS(...) __VA_ARGS__
395# define IFNOT_ALIB_CONTAINERS(...)
396#else
397# define IF_ALIB_CONTAINERS(...)
398# define IFNOT_ALIB_CONTAINERS(...) __VA_ARGS__
399#endif
400
401#if ALIB_ENUMRECORDS
402# define IF_ALIB_ENUMRECORDS(...) __VA_ARGS__
403# define IFNOT_ALIB_ENUMRECORDS(...)
404#else
405# define IF_ALIB_ENUMRECORDS(...)
406# define IFNOT_ALIB_ENUMRECORDS(...) __VA_ARGS__
407#endif
408
409#if ALIB_EXPRESSIONS
410# define IF_ALIB_EXPRESSIONS(...) __VA_ARGS__
411# define IFNOT_ALIB_EXPRESSIONS(...)
412#else
413# define IF_ALIB_EXPRESSIONS(...)
414# define IFNOT_ALIB_EXPRESSIONS(...) __VA_ARGS__
415#endif
416
417#if ALIB_FILES
418# define IF_ALIB_FILES(...) __VA_ARGS__
419# define IFNOT_ALIB_FILES(...)
420#else
421# define IF_ALIB_FILES(...)
422# define IFNOT_ALIB_FILES(...) __VA_ARGS__
423#endif
424
425#if ALIB_MONOMEM
426# define IF_ALIB_MONOMEM(...) __VA_ARGS__
427# define IFNOT_ALIB_MONOMEM(...)
428#else
429# define IF_ALIB_MONOMEM(...)
430# define IFNOT_ALIB_MONOMEM(...) __VA_ARGS__
431#endif
432
433#if ALIB_SINGLETONS
434# define IF_ALIB_SINGLETONS(...) __VA_ARGS__
435# define IFNOT_ALIB_SINGLETONS(...)
436#else
437# define IF_ALIB_SINGLETONS(...)
438# define IFNOT_ALIB_SINGLETONS(...) __VA_ARGS__
439#endif
440
441#if ALIB_STRINGS
442# define IF_ALIB_STRINGS(...) __VA_ARGS__
443# define IFNOT_ALIB_STRINGS(...)
444#else
445# define IF_ALIB_STRINGS(...)
446# define IFNOT_ALIB_STRINGS(...) __VA_ARGS__
447#endif
448
449#if ALIB_CAMP
450# define IF_ALIB_CAMP(...) __VA_ARGS__
451# define IFNOT_ALIB_CAMP(...)
452#else
453# define IF_ALIB_CAMP(...)
454# define IFNOT_ALIB_CAMP(...) __VA_ARGS__
455#endif
456
457#if ALIB_THREADMODEL
458# define IF_ALIB_THREADMODEL(...) __VA_ARGS__
459# define IFNOT_ALIB_THREADMODEL(...)
460#else
461# define IF_ALIB_THREADMODEL(...)
462# define IFNOT_ALIB_THREADMODEL(...) __VA_ARGS__
463#endif
464
465#if !ALIB_SINGLE_THREADED
466# define IF_ALIB_THREADS(...) __VA_ARGS__
467# define IFNOT_ALIB_THREADS(...)
468#else
469# define IF_ALIB_THREADS(...)
470# define IFNOT_ALIB_THREADS(...) __VA_ARGS__
471#endif
472
473//##################################################################################################
474// Compiler detection and specifics
475//##################################################################################################
476#if !DOXYGEN
477 #define DOX_MARKER(marker)
478#endif
479
480// GCC Compiler detection
481#if defined(__clang__)
482#elif defined(__INTEL_COMPILER) //never tested
483#elif defined(_MSC_VER)
484#elif defined(__GNUC__)
485# define ALIB_GCC 1
486#endif
487
488
489
490// --- C++ standard: set ALIB_CPP_STANDARD ---
491
492// deduce && disallow < 20
493#if defined ( _MSC_VER )
494# if defined(_MSVC_LANG)
495# if _MSVC_LANG <= 201703L
496# error "ALib needs C++ standard 20. Wrong compilation settings given."
497# elif _MSVC_LANG == 202002L
498# define ALIB_INTERNAL_DEDUCED_CPPVER 20
499# elif _MSVC_LANG > 202002L
500# define ALIB_INTERNAL_DEDUCED_CPPVER 23
501# endif
502# endif
503
504
505#elif defined(__cplusplus)
506# if __cplusplus < 202002L
507# error "ALib needs C++20. Compilation aborted"
508# else
509# define ALIB_INTERNAL_DEDUCED_CPPVER 20
510# endif
511# if __cplusplus > 202002L
512# undef ALIB_INTERNAL_DEDUCED_CPPVER
513# define ALIB_INTERNAL_DEDUCED_CPPVER 23
514# endif
515#endif
516
517// check whether detected, given or given falsely
518#if !defined(ALIB_CPP_STANDARD)
519# if defined(ALIB_INTERNAL_DEDUCED_CPPVER)
520# define ALIB_CPP_STANDARD ALIB_INTERNAL_DEDUCED_CPPVER
521# else
522# error "Unknown compiler/toolchain. Can't deduce ALIB_CPP_STANDARD. Please provide this configuration macro 'manually' to the compiler."
523# endif
524#else
525# if defined(ALIB_INTERNAL_DEDUCED_CPPVER)
526# if (ALIB_CPP_STANDARD != ALIB_INTERNAL_DEDUCED_CPPVER)
527# error "ALIB_CPP_STANDARD was explicitly passed to the compiler, but does not match the language standard deduced by ALib_"
528# endif
529# elif ALIB_CPP_STANDARD < 20
530# error "ALIB_CPP_STANDARD must be set to at least 20."
531# endif
532#endif
533
534// final internal check
535#if ALIB_CPP_STANDARD < 20
536# error "Error in header. This must never happen."
537#endif
538
539// Inline code selection dependent on C++ Version
540#if ALIB_CPP_STANDARD >= 23
541# define ALIB_CPP_23(...) __VA_ARGS__
542# define ALIB_CPP_BEFORE_23(...)
543#else
544# define ALIB_CPP_23(...)
545# define ALIB_CPP_BEFORE_23(...) __VA_ARGS__
546#endif
547
548// Disallow C++-module compilation (deprecated)
549#if defined(ALIB_C20_MODULES) || DOXYGEN
550# if ALIB_C20_MODULES != 0
551# error "Configuration MACRO ALIB_C20_MODULES must not be specified. C+20 module support is deprecated."
552# endif
553#else
554# define ALIB_C20_MODULES 0
555#endif
556#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
557# error "Configuration MACRO ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
558#endif
559#if ALIB_C20_MODULES
560# define ALIB_EXPORT export
561#else
562# define ALIB_EXPORT
563#endif
564
565// Windows DLL Import/Export
566#if defined( _MSC_VER ) && !defined( ALIB_API_NO_DLL )
567 #ifdef ALIB_API_IS_DLL
568 #define ALIB_DLL __declspec(dllexport)
569 #else
570 #define ALIB_DLL __declspec(dllimport)
571 #endif
572#else
573 #define ALIB_DLL
574#endif
575
576
577// Warnings
578#if defined(ALIB_GCC)
579
580 #define ALIB_ALLOW_UNINITIALIZED \
581 _Pragma("GCC diagnostic push") \
582 _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") \
583
584 #define ALIB_ALLOW_NULL_POINTER_PASSING \
585 _Pragma("GCC diagnostic push") \
586 _Pragma("GCC diagnostic ignored \"-Wnonnull\"") \
587
588 #define ALIB_ALLOW_UNREACHABLE_CODE \
589 _Pragma("GCC diagnostic push") \
590
591 #define ALIB_ALLOW_MACRO_REDEFINITION \
592 _Pragma("GCC diagnostic push") \
593
594 #define ALIB_ALLOW_MISSING_FIELD_INITIALIZERS \
595 _Pragma("GCC diagnostic push") \
596 _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \
597
598 #define ALIB_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
599 _Pragma("GCC diagnostic push") \
600
601 #define ALIB_ALLOW_UNUSED_MACRO \
602 _Pragma("GCC diagnostic push") \
603 _Pragma("GCC diagnostic ignored \"-Wunused-macros\"") \
604
605 #define ALIB_ALLOW_MACROS_WITH_RESERVED_NAME \
606 _Pragma("GCC diagnostic push") \
607
608 #define ALIB_ALLOW_OVERLOADED_VIRTUALS \
609 _Pragma("GCC diagnostic push") \
610
611 #define ALIB_ALLOW_SPARSE_ENUM_SWITCH \
612 _Pragma("GCC diagnostic push") \
613 _Pragma("GCC diagnostic ignored \"-Wswitch\"") \
614
615 #define ALIB_ALLOW_BITWISE_SWITCH \
616 _Pragma("GCC diagnostic push") \
617 _Pragma("GCC diagnostic ignored \"-Wswitch\"") \
618
619 #define ALIB_ALLOW_SWITCH_WITHOUT_DEFAULT \
620 _Pragma("gcc diagnostic push") \
621 _Pragma("gcc diagnostic ignored \"-Wswitch-default\"") \
622
623 #define ALIB_ALLOW_SHIFT_COUNT_OVERFLOW \
624 _Pragma("GCC diagnostic push") \
625 _Pragma("GCC diagnostic ignored \"-Wshift-count-overflow\"") \
626
627 #define ALIB_ALLOW_DEPRECATED \
628 _Pragma("GCC diagnostic push") \
629 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
630
631 #define ALIB_ALLOW_UNUSED_PARAMETER \
632 _Pragma("GCC diagnostic push") \
633 _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
634
635 #define ALIB_ALLOW_UNUSED_VARIABLE \
636 _Pragma("GCC diagnostic push") \
637 _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") \
638
639 #define ALIB_ALLOW_UNUSED_FUNCTION \
640 _Pragma("GCC diagnostic push") \
641 _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \
642
643 #define ALIB_ALLOW_UNUSED_LAMBDA_CAPTURE \
644 _Pragma("GCC diagnostic push") \
645
646 #define ALIB_ALLOW_FUNCTION_TEMPLATE \
647 _Pragma("GCC diagnostic push") \
648
649 #define ALIB_ALLOW_NOT_ELIDING_COPY_ON_RETURN \
650 _Pragma("GCC diagnostic push") \
651
652 #define ALIB_ALLOW_NOTHING_RETURNED \
653 _Pragma("GCC diagnostic push") \
654 _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
655
656 #define ALIB_ALLOW_INTEGRAL_CONSTANT_OVERFLOW \
657 _Pragma("GCC diagnostic push") \
658
659 #define ALIB_ALLOW_RESERVED_IDENTIFIER \
660 _Pragma("GCC diagnostic push") \
661
662 #define ALIB_ALLOW_DOCS \
663 _Pragma("GCC diagnostic push") \
664
665 #define ALIB_ALLOW_SIGN_CONVERSION \
666 _Pragma("GCC diagnostic push") \
667 _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \
668
669 #define ALIB_ALLOW_INTEGER_OVERFLOW \
670 _Pragma("GCC diagnostic push") \
671 _Pragma("GCC diagnostic ignored \"-Wshift-count-overflow\"") \
672
673 #define ALIB_POP_ALLOWANCE \
674 _Pragma("GCC diagnostic pop")
675
676 #if __GNUC__ < 7
677 #define ALIB_FALLTHROUGH
678 #else
679 #define ALIB_FALLTHROUGH [[gnu::fallthrough]];
680 #endif
681
682#elif defined(__clang__)
683
684 #define ALIB_ALLOW_UNINITIALIZED \
685 _Pragma("clang diagnostic push") \
686 _Pragma("clang diagnostic ignored \"-Wuninitialized\"") \
687 _Pragma("clang diagnostic ignored \"-Wconditional-uninitialized\"") \
688
689 #define ALIB_ALLOW_NULL_POINTER_PASSING \
690 _Pragma("clang diagnostic push") \
691
692 #define ALIB_ALLOW_UNREACHABLE_CODE \
693 _Pragma("clang diagnostic push") \
694 _Pragma("clang diagnostic ignored \"-Wunreachable-code\"") \
695
696 #define ALIB_ALLOW_OVERLOADED_VIRTUALS \
697 _Pragma("clang diagnostic push") \
698 _Pragma("clang diagnostic ignored \"-Woverloaded-virtual\"") \
699
700 #define ALIB_ALLOW_MACRO_REDEFINITION \
701 _Pragma("clang diagnostic push") \
702 _Pragma("clang diagnostic ignored \"-Wmacro-redefined\"") \
703
704 #define ALIB_ALLOW_MISSING_FIELD_INITIALIZERS \
705 _Pragma("clang diagnostic push") \
706 _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") \
707
708 #define ALIB_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
709 _Pragma("clang diagnostic push") \
710 _Pragma("clang diagnostic ignored \"-Wunused-macros\"") \
711
712
713 #define ALIB_ALLOW_UNUSED_MACRO \
714 _Pragma("clang diagnostic push") \
715 _Pragma("clang diagnostic ignored \"-Wunused-macros\"") \
716
717 #define ALIB_ALLOW_MACROS_WITH_RESERVED_NAME \
718 _Pragma("clang diagnostic push") \
719 _Pragma("clang diagnostic ignored \"-Wreserved-macro-identifier\"") \
720
721 #define ALIB_ALLOW_SPARSE_ENUM_SWITCH \
722 _Pragma("clang diagnostic push") \
723 _Pragma("clang diagnostic ignored \"-Wswitch\"") \
724 _Pragma("clang diagnostic ignored \"-Wswitch-enum\"") \
725
726 #define ALIB_ALLOW_BITWISE_SWITCH \
727 _Pragma("clang diagnostic push") \
728 _Pragma("clang diagnostic ignored \"-Wswitch\"") \
729 _Pragma("clang diagnostic ignored \"-Wcovered-switch-default\"") \
730
731 #define ALIB_ALLOW_SWITCH_WITHOUT_DEFAULT \
732 _Pragma("clang diagnostic push") \
733 _Pragma("clang diagnostic ignored \"-Wswitch-default\"") \
734
735
736 #define ALIB_ALLOW_SHIFT_COUNT_OVERFLOW \
737 _Pragma("clang diagnostic push") \
738 _Pragma("clang diagnostic ignored \"-Wshift-count-overflow\"") \
739
740 #define ALIB_ALLOW_DEPRECATED \
741 _Pragma("clang diagnostic push") \
742 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
743
744 #define ALIB_ALLOW_UNUSED_PARAMETER \
745 _Pragma("clang diagnostic push") \
746 _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") \
747
748 #define ALIB_ALLOW_UNUSED_VARIABLE \
749 _Pragma("clang diagnostic push") \
750 _Pragma("clang diagnostic ignored \"-Wunused-variable\"") \
751
752 #define ALIB_ALLOW_UNUSED_FUNCTION \
753 _Pragma("clang diagnostic push") \
754 _Pragma("clang diagnostic ignored \"-Wunused-function\"") \
755 _Pragma("clang diagnostic ignored \"-Wunused-member-function\"") \
756 _Pragma("clang diagnostic ignored \"-Wunused-template\"") \
757
758 #define ALIB_ALLOW_UNUSED_LAMBDA_CAPTURE \
759 _Pragma("clang diagnostic push") \
760 _Pragma("clang diagnostic ignored \"-Wunused-lambda-capture\"") \
761
762 #define ALIB_ALLOW_FUNCTION_TEMPLATE \
763 _Pragma("clang diagnostic push") \
764 _Pragma("clang diagnostic ignored \"-Wunused-template\"") \
765
766 #define ALIB_ALLOW_NOT_ELIDING_COPY_ON_RETURN \
767 _Pragma("clang diagnostic push") \
768 _Pragma("clang diagnostic ignored \"-Wnrvo\"") \
769
770 #define ALIB_ALLOW_NOTHING_RETURNED \
771 _Pragma("clang diagnostic push") \
772 _Pragma("clang diagnostic ignored \"-Wreturn-type\"") \
773
774 #define ALIB_ALLOW_INTEGRAL_CONSTANT_OVERFLOW \
775 _Pragma("clang diagnostic push") \
776
777 #define ALIB_ALLOW_DOCS \
778 _Pragma("clang diagnostic push") \
779 _Pragma("clang diagnostic ignored \"-Wdocumentation\"") \
780
781 #define ALIB_ALLOW_RESERVED_IDENTIFIER \
782 _Pragma("clang diagnostic push") \
783 _Pragma("clang diagnostic ignored \"-Wreserved-identifier\"") \
784
785 #define ALIB_ALLOW_INTEGER_OVERFLOW \
786 _Pragma("clang diagnostic push") \
787 _Pragma("clang diagnostic ignored \"-Winteger-overflow\"") \
788
789 #define ALIB_ALLOW_SIGN_CONVERSION \
790 _Pragma("clang diagnostic push") \
791 _Pragma("clang diagnostic ignored \"-Wsign-conversion\"") \
792
793
794 #define ALIB_POP_ALLOWANCE \
795 _Pragma("clang diagnostic pop") \
796
797 #define ALIB_FALLTHROUGH [[clang::fallthrough]];
798
799
800#elif defined(_MSC_VER)
801 #define ALIB_ALLOW_UNINITIALIZED \
802 __pragma(warning( push )) \
803 __pragma(warning( disable : 4701 )) \
804
805 #define ALIB_ALLOW_NULL_POINTER_PASSING \
806 __pragma(warning( push )) \
807
808 #define ALIB_ALLOW_UNREACHABLE_CODE \
809 __pragma(warning( push )) \
810
811 #define ALIB_ALLOW_UNUSED_MACRO \
812 __pragma(warning( push )) \
813
814 #define ALIB_ALLOW_MACROS_WITH_RESERVED_NAME \
815 __pragma(warning( push )) \
816
817 #define ALIB_ALLOW_OVERLOADED_VIRTUALS \
818 __pragma(warning( push )) \
819
820 #define ALIB_ALLOW_SPARSE_ENUM_SWITCH \
821 __pragma(warning( push )) \
822
823 #define ALIB_ALLOW_SPARSE_ENUM_SWITCH \
824 __pragma(warning( push )) \
825
826 #define ALIB_ALLOW_MACRO_REDEFINITION \
827 __pragma(warning( push )) \
828 __pragma(warning( disable : 4005 )) \
829
830 #define ALIB_ALLOW_MACRO_REDEFINITION \
831 __pragma(warning( push )) \
832
833 #define ALIB_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
834 __pragma(warning( push )) \
835 __pragma(warning( disable : 4996 )) \
836
837 #define ALIB_ALLOW_BITWISE_SWITCH \
838 __pragma(warning( push )) \
839
840 #define ALIB_ALLOW_SWITCH_WITHOUT_DEFAULT \
841 __pragma(warning( push )) \
842
843 #define ALIB_ALLOW_SHIFT_COUNT_OVERFLOW \
844 __pragma(warning( push )) \
845
846 #define ALIB_ALLOW_DEPRECATED \
847 __pragma(warning( push )) \
848
849 #define ALIB_ALLOW_UNUSED_PARAMETER \
850 __pragma(warning( push )) \
851
852 #define ALIB_ALLOW_UNUSED_VARIABLE \
853 __pragma(warning( push )) \
854
855 #define ALIB_ALLOW_UNUSED_FUNCTION \
856 __pragma(warning( push )) \
857
858 #define ALIB_ALLOW_UNUSED_LAMBDA_CAPTURE \
859 __pragma(warning( push )) \
860
861 #define ALIB_ALLOW_FUNCTION_TEMPLATE \
862 __pragma(warning( push )) \
863
864 #define ALIB_ALLOW_NOT_ELIDING_COPY_ON_RETURN \
865 __pragma(warning( push )) \
866
867 #define ALIB_ALLOW_NOTHING_RETURNED \
868 __pragma(warning( push )) \
869 __pragma(warning( disable : 4715 )) \
870
871 #define ALIB_ALLOW_INTEGRAL_CONSTANT_OVERFLOW \
872 __pragma(warning( push )) \
873 __pragma(warning( disable : 4305 )) \
874 __pragma(warning( disable : 4307 )) \
875 __pragma(warning( disable : 4309 )) \
876 __pragma(warning( disable : 4310 )) \
877 __pragma(warning( disable : 4293 )) \
878
879 #define ALIB_ALLOW_INTEGER_OVERFLOW \
880 __pragma(warning( push )) \
881 __pragma(warning( disable : 4293 )) \
882
883 #define ALIB_ALLOW_RESERVED_IDENTIFIER \
884 __pragma(warning( push )) \
885
886 #define ALIB_ALLOW_DOCS \
887 __pragma(warning( push )) \
888
889 #define ALIB_ALLOW_SIGN_CONVERSION \
890 __pragma(warning( push )) \
891
892 #define ALIB_ALLOW_DOCS \
893 __pragma(warning( push )) \
894
895 #define ALIB_POP_ALLOWANCE \
896 __pragma(warning( pop )) \
897
898 #define ALIB_FALLTHROUGH
899
900#else
901 #define ALIB_POP_ALLOWANCE
902 #define ALIB_FALLTHROUGH
903#endif
904
905//##################################################################################################
906// Availability of external libraries
907//##################################################################################################
908#if !defined(ALIB_EXT_LIB_THREADS_AVAILABLE)
909# define ALIB_EXT_LIB_THREADS_AVAILABLE 1
910#endif
911#if ALIB_EXT_LIB_THREADS_AVAILABLE
912# include <thread>
913#endif
914
915#if !defined(ALIB_FEAT_BOOST_REGEX)
916# define ALIB_FEAT_BOOST_REGEX 0
917#endif
918
919//##################################################################################################
920// Debug or release compilation
921//##################################################################################################
922#if !defined(ALIB_DEBUG)
923# if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG)
924# define ALIB_DEBUG 1
925# else
926# define ALIB_DEBUG 0
927# endif
928#endif
929
930#if ALIB_DEBUG
931 #define ALIB_DBG(...) __VA_ARGS__
932 #define ALIB_REL(...)
933 #define ALIB_REL_DBG(releaseCode, ...) __VA_ARGS__
934#else
935 #define ALIB_DBG(...)
936 #define ALIB_REL(...) __VA_ARGS__
937 #define ALIB_REL_DBG(releaseCode, ...) releaseCode
938#endif
939
940
941
942//##################################################################################################
943// ALib Feature detection
944// (Note: this has to be done outside the module code, because the features are used with
945// the compilation verification flags below)
946//##################################################################################################
947
948// ALIB_CHARACTERS_WIDE, ALIB_SIZEOF_WCHAR_T
949#if defined(__WCHAR_MAX__)
950 #if __WCHAR_MAX__ == 0x7FFFFFFF \
951 || __WCHAR_MAX__ == 0xFFFFFFFF
952 #define ALIB_SIZEOF_WCHAR_T 4
953 #else
954 #define ALIB_SIZEOF_WCHAR_T 2
955 #endif
956#elif defined(_MSC_VER)
957 #define ALIB_SIZEOF_WCHAR_T 2
958#else
959# define ALIB_SIZEOF_WCHAR_T 4 // guessing, will be checked below
960#endif
961
962static_assert( sizeof(wchar_t) == ALIB_SIZEOF_WCHAR_T, "Error: Platform not supported" );
963
964#if !defined(ALIB_CHARACTERS_WIDE)
965# if defined(_MSC_VER)
966# define ALIB_CHARACTERS_WIDE 1
967# else
968# define ALIB_CHARACTERS_WIDE 0
969# endif
970#endif
971
972#if !defined(ALIB_CHARACTERS_SIZEOF_WCHAR)
973# define ALIB_CHARACTERS_SIZEOF_WCHAR ALIB_SIZEOF_WCHAR_T
974#elif (ALIB_CHARACTERS_SIZEOF_WCHAR != 2) && (ALIB_CHARACTERS_SIZEOF_WCHAR != 4 )
975# error "Illegal value for symbol ALIB_CHARACTERS_SIZEOF_WCHAR given. Allowed is 2 or 4."
976#endif
977
978// ALIB_DEBUG_CRITICAL_SECTIONS
979#if !defined(ALIB_DEBUG_CRITICAL_SECTIONS)
980# define ALIB_DEBUG_CRITICAL_SECTIONS 0
981#elif !ALIB_DEBUG && ALIB_DEBUG_CRITICAL_SECTIONS
982# undef ALIB_DEBUG_CRITICAL_SECTIONS
983# define ALIB_DEBUG_CRITICAL_SECTIONS 0
984# pragma message "Symbol ALIB_DEBUG_CRITICAL_SECTIONS set (from outside!) while ALIB_DEBUG is not. The symbol got disabled."
985#elif ALIB_SINGLE_THREADED && ALIB_DEBUG_CRITICAL_SECTIONS
986# undef ALIB_DEBUG_CRITICAL_SECTIONS
987# define ALIB_DEBUG_CRITICAL_SECTIONS 0
988# pragma message "Symbol ALIB_DEBUG_CRITICAL_SECTIONS set (from outside!) while symbol ALIB_SINGLE_THREADED is set in the ALib Build. The symbol got disabled."
989#endif
990
991// ALIB_DEBUG_ALLOCATIONS
992#if !defined(ALIB_DEBUG_ALLOCATIONS)
993# define ALIB_DEBUG_ALLOCATIONS 0
994#elif !ALIB_DEBUG && ALIB_DEBUG_ALLOCATIONS
995# undef ALIB_DEBUG_ALLOCATIONS
996# define ALIB_DEBUG_ALLOCATIONS 0
997# pragma message "Symbol ALIB_DEBUG_ALLOCATIONS set (from outside!) while ALIB_DEBUG is not. The symbol got disabled."
998#endif
999
1000// ALIB_DEBUG_MEMORY
1001#if !defined(ALIB_DEBUG_MEMORY)
1002# define ALIB_DEBUG_MEMORY 0
1003#elif !ALIB_DEBUG && ALIB_DEBUG_MEMORY
1004# undef ALIB_DEBUG_MEMORY
1005# define ALIB_DEBUG_MEMORY 0
1006# pragma message "Symbol ALIB_DEBUG_MEMORY set (from outside!) while ALIB_DEBUG is not. The symbol got disabled."
1007#endif
1008
1009
1010//##################################################################################################
1011// Preprocessor tools
1012//##################################################################################################
1013#if DOXYGEN
1014# define ALIB_NSTRINGIFY(a)
1015# define ALIB_STRINGIFY(a)
1016#else
1017# define ALIB_STRINGIFY_X(a) A_CHAR( #a )
1018# define ALIB_STRINGIFY(a) ALIB_STRINGIFY_X(a)
1019# define ALIB_NSTRINGIFY_X(a) #a
1020# define ALIB_NSTRINGIFY(a) ALIB_NSTRINGIFY_X(a)
1021#endif
1022
1023// Note: The double expansion ensures that if another macro is given, e.g., "__LINE__", it is
1024// expanded before it is concatenated.
1025#if !DOXYGEN
1026#define ALIB_CONCAT_IMPL(a,b) a ## b
1027#endif
1028#define ALIB_CONCAT(a,b) ALIB_CONCAT_IMPL(a,b)
1029
1030#if defined(__clang__)
1031# define ALIB_IDENTIFIER(prefix) ALIB_ALLOW_RESERVED_IDENTIFIER \
1032 ALIB_CONCAT(prefix, __LINE__) \
1033 ALIB_POP_ALLOWANCE
1034#else
1035# define ALIB_IDENTIFIER(prefix) ALIB_CONCAT(prefix, __LINE__)
1036#endif
1037
1038#define ALIB_EMPTY
1039
1040
1041#define ALIB_COMMA ,
1042#if ALIB_DEBUG
1043# define ALIB_COMMA_DBG ,
1044#else
1045# define ALIB_COMMA_DBG
1046#endif
1047
1048// Macros for writing "nicer" static_assert messages
1049#define ALIB_STATIC_ASSERT( CondVariable, Cond, Message ) \
1050{ constexpr bool CondVariable= Cond; \
1051 static_assert( CondVariable, Message ); } \
1052
1053#define ALIB_STATIC_DENY( CondVariable, Cond, Message ) \
1054{ constexpr bool CondVariable= !(Cond); \
1055 static_assert( CondVariable, Message ); } \
1056
1057//==================================================================================================
1058// Used by the macro ALIB_ASSERT_GLOBAL_NAMESPACE for testing.
1059//==================================================================================================
1060struct ALibTestGlobalNamespace;
1061#define ALIB_ASSERT_GLOBAL_NAMESPACE \
1062struct ALibTestGlobalNamespace; \
1063static_assert(std::is_same<ALibTestGlobalNamespace, ::ALibTestGlobalNamespace>::value, \
1064 "This is not the global namespace!");
1065
1066
1067//##################################################################################################
1068// Other tools
1069//##################################################################################################
1070#define ALIB_STACK_ALLOCATED_TYPE(T) \
1071private: void* operator new (size_t); \
1072 void* operator new (size_t, void*); \
1073 void* operator new[](size_t); \
1074 void* operator new[](size_t, void*); \
1075 T(const T& ); \
1076 T( T&& ); \
1077 void operator=(const T& ); \
1078 void operator=( T&& );
1079
1080// Template tool macros
1081#define ALIB_TVALUE(T) std::remove_cv_t<std::remove_pointer_t<std::remove_reference_t<T>>>
1082
1083#define ALIB_HAS_METHOD(T,Method,...) \
1084 !std::same_as< lang::UnknownTag, decltype(std::declval<T>(). Method( __VA_ARGS__ ))>
1085
1086
1087
1088// Macros for passing source code information
1089#if defined ( _MSC_VER )
1090# define ALIB_CALLER_FUNC __FUNCTION__
1091#else
1092# define ALIB_CALLER_FUNC __func__
1093#endif
1094
1095#if ALIB_EXT_LIB_THREADS_AVAILABLE
1096# define ALIB_CALLER {__FILE__,__LINE__,ALIB_CALLER_FUNC,::std::this_thread::get_id(),&typeid(*this)}
1097#else
1098# define ALIB_CALLER {__FILE__,__LINE__,ALIB_CALLER_FUNC,&typeid(*this)}
1099#endif
1100
1101#if ALIB_DEBUG
1102# define ALIB_CALLER_PRUNED ALIB_CALLER
1103# define ALIB_COMMA_CALLER_PRUNED , ALIB_CALLER
1104# define ALIB_CALLER_PRUNED_COMMA ALIB_CALLER ,
1105# define ALIB_CALLER_NULLED ALIB_CALLER
1106# define ALIB_COMMA_CALLER_NULLED , ALIB_CALLER
1107# define ALIB_CALLER_NULLED_COMMA ALIB_CALLER ,
1108# define ALIB_DBG_TAKE_CI const CallerInfo& ci
1109#else
1110# define ALIB_CALLER_PRUNED
1111# define ALIB_COMMA_CALLER_PRUNED
1112# define ALIB_CALLER_PRUNED_COMMA
1113# if ALIB_EXT_LIB_THREADS_AVAILABLE
1114# define ALIB_CALLER_NULLED {nullptr,0,nullptr,::std::thread::id(), nullptr}
1115# define ALIB_COMMA_CALLER_NULLED , {nullptr,0,nullptr,::std::thread::id(), nullptr}
1116# define ALIB_CALLER_NULLED_COMMA {nullptr,0,nullptr,::std::thread::id(), nullptr} ,
1117# else
1118# define ALIB_CALLER_NULLED {nullptr,0,nullptr,nullptr}
1119# define ALIB_COMMA_CALLER_NULLED , {nullptr,0,nullptr,nullptr}
1120# define ALIB_CALLER_NULLED_COMMA {nullptr,0,nullptr,nullptr} ,
1121# endif
1122# define ALIB_DBG_TAKE_CI
1123#endif
1124
1125//##################################################################################################
1126// Debug Messages and Assertions
1127//##################################################################################################
1128#if ALIB_DEBUG
1129# if !defined(ALIB_DEBUG_ASSERTION_PRINTABLES)
1130# define ALIB_DEBUG_ASSERTION_PRINTABLES 0
1131# endif
1132# if !DOXYGEN
1133# if ALIB_DEBUG_ASSERTION_PRINTABLES
1134# define ALIB_DEBUG_ASSERTION_PRINTABLES_DO(...) alib::assert::CheckArgs(ALIB_CALLER_PRUNED, __VA_ARGS__);
1135# else
1136# define ALIB_DEBUG_ASSERTION_PRINTABLES_DO(...)
1137# endif
1138# endif
1139
1140# define ALIB_ERROR( domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) alib::assert::Raise( ALIB_CALLER_PRUNED, 0, domain, __VA_ARGS__ ); }
1141# define ALIB_WARNING( domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) alib::assert::Raise( ALIB_CALLER_PRUNED, 1, domain, __VA_ARGS__ ); }
1142# define ALIB_MESSAGE( domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) alib::assert::Raise( ALIB_CALLER_PRUNED, 2, domain, __VA_ARGS__ ); }
1143# define ALIB_ASSERT(cond, domain) { if( !( cond)) ALIB_ERROR( domain, "Assertion Failed" ); }
1144# define ALIB_ASSERT_ERROR( cond, domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) if( !( cond)) ALIB_ERROR( domain, __VA_ARGS__ ) }
1145# define ALIB_ASSERT_WARNING( cond, domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) if( !( cond)) ALIB_WARNING( domain, __VA_ARGS__ ) }
1146# define ALIB_ASSERT_MESSAGE( cond, domain, ...) { ALIB_DEBUG_ASSERTION_PRINTABLES_DO(__VA_ARGS__) if( !( cond)) ALIB_MESSAGE( domain, __VA_ARGS__ ) }
1147
1148#else // ALIB_DEBUG
1149 #define ALIB_ERROR( ... ) {}
1150 #define ALIB_WARNING( ... ) {}
1151 #define ALIB_MESSAGE( ... ) {}
1152 #define ALIB_ASSERT( ... ) {}
1153 #define ALIB_ASSERT_ERROR( ...) {}
1154 #define ALIB_ASSERT_WARNING(...) {}
1155 #define ALIB_ASSERT_MESSAGE(...) {}
1156#endif
1157
1158
1159#if ALIB_DEBUG
1160# include <assert.h>
1161 #define ALIB_ASSERT_RESULT_EQUALS( func, value ) { auto result= func; assert(result == value); ((void) result); }
1162 #define ALIB_ASSERT_RESULT_NOT_EQUALS( func, value ) { auto result= func; assert(result != value); ((void) result); }
1163 #define ALIB_ASSERT_RESULT_GREATER_THAN(func, value ) { auto result= func; assert(result > value); ((void) result); }
1164 #define ALIB_ASSERT_RESULT_LESS_THAN( func, value ) { auto result= func; assert(result < value); ((void) result); }
1165#else
1166 #define ALIB_ASSERT_RESULT_EQUALS( func, value ) { func; }
1167 #define ALIB_ASSERT_RESULT_NOT_EQUALS( func, value ) { func; }
1168 #define ALIB_ASSERT_RESULT_GREATER_THAN(func, value ) { func; }
1169 #define ALIB_ASSERT_RESULT_LESS_THAN( func, value ) { func; }
1170#endif
1171
1172//##################################################################################################
1173// Macro introduced by lang::integer, and similar basics
1174//##################################################################################################
1175//----------------------------- One of the 5 configuration macros given from outside? ---------------------------
1176#if defined(ALIB_SIZEOF_INTEGER ) \
1177 || defined(ALIB_SIZEOF_INTGAP ) \
1178 || defined(ALIB_INTGAP_TYPE ) \
1179 || defined(ALIB_SIZEOF_LONGDOUBLE_REPORTED) \
1180 || defined(ALIB_SIZEOF_LONGDOUBLE_WRITTEN)
1181
1182 // just check if all are given, that's it for now
1183 #if !defined(ALIB_SIZEOF_INTEGER) \
1184 || !defined(ALIB_SIZEOF_INTGAP) \
1185 || !defined(ALIB_INTGAP_TYPE) \
1186 || !defined(ALIB_SIZEOF_LONGDOUBLE_REPORTED) \
1187 || !defined(ALIB_SIZEOF_LONGDOUBLE_WRITTEN)
1188
1189 #error "If one of the Configuration Macros \
1190'ALIB_SIZEOF_INTEGER', \
1191'ALIB_SIZEOF_INTGAP', \
1192'ALIB_INTGAP_TYPE', \
1193'ALIB_SIZEOF_LONGDOUBLE_REPORTED' or \
1194'ALIB_SIZEOF_LONGDOUBLE_WRITTEN' \
1195is given (instead of letting ALib detect them), then the whole group has to be given!"
1196 #endif
1197
1198
1199//------------------- None of the 5 configuration macros given from outside: Platform detection -----------------
1200#else
1201
1202 // 64-Bit platforms
1203 #if (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8 ) || defined(_WIN64)
1204
1205 #define ALIB_SIZEOF_INTEGER 8
1206
1207 #if defined(_WIN32)
1208 #define ALIB_INTGAP_TYPE long;
1209 #define ALIB_SIZEOF_INTGAP 4
1210
1211 #elif defined(__APPLE__)
1212 #define ALIB_INTGAP_TYPE long;
1213 #define ALIB_SIZEOF_INTGAP 8
1214
1215 #elif defined(__GNUC__) || defined(__clang__)
1216 #define ALIB_INTGAP_TYPE long long;
1217 #define ALIB_SIZEOF_INTGAP 8
1218 #else
1219 # error "Cannot detect compilation platform. Please provide Symbols \
1220'ALIB_SIZEOF_INTEGER', \
1221'ALIB_SIZEOF_INTGAP', \
1222'ALIB_INTGAP_TYPE', \
1223'ALIB_SIZEOF_LONGDOUBLE_REPORTED' or \
1224'ALIB_SIZEOF_LONGDOUBLE_WRITTEN' \
1225as documented with ALib User Manual at https://alib.dev"
1226
1227 #endif
1228
1229 #if defined(_MSC_VER) || defined(__APPLE__)
1230 # define ALIB_SIZEOF_LONGDOUBLE_REPORTED 8
1231 #else
1232 # define ALIB_SIZEOF_LONGDOUBLE_REPORTED 16
1233 #endif
1234
1235 // 32-Bit platforms
1236 #elif (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4 ) || defined(_WIN32) || defined( __arm__)
1237
1238 #define ALIB_SIZEOF_INTEGER 4
1239
1240 #if defined(__APPLE__)
1241 #define ALIB_INTGAP_TYPE long;
1242 #define ALIB_SIZEOF_INTGAP 4
1243
1244 #elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
1245 #define ALIB_INTGAP_TYPE long;
1246 #define ALIB_SIZEOF_INTGAP 4
1247 #else
1248 #error "Cannot detect compilation platform. Please provide Symbols \
1249'ALIB_SIZEOF_INTEGER', \
1250'ALIB_SIZEOF_INTGAP', \
1251'ALIB_INTGAP_TYPE', \
1252'ALIB_SIZEOF_LONGDOUBLE_REPORTED' or \
1253'ALIB_SIZEOF_LONGDOUBLE_WRITTEN' \
1254as documented with ALib User Manual at https://alib.dev"
1255
1256 #endif
1257
1258 #if defined(_MSC_VER) || defined( __arm__)
1259 # define ALIB_SIZEOF_LONGDOUBLE_REPORTED 8
1260 #elif defined(__APPLE__)
1261 # define ALIB_SIZEOF_LONGDOUBLE_REPORTED 16
1262 #else
1263 # define ALIB_SIZEOF_LONGDOUBLE_REPORTED 12
1264 #endif
1265
1266 // unrecognized platform
1267 #else
1268 #error "Cannot detect compilation platform. Please provide Symbols \
1269'ALIB_SIZEOF_INTEGER', \
1270'ALIB_SIZEOF_INTGAP', \
1271'ALIB_INTGAP_TYPE', \
1272'ALIB_SIZEOF_LONGDOUBLE_REPORTED' or \
1273'ALIB_SIZEOF_LONGDOUBLE_WRITTEN' \
1274as documented with ALib User Manual at https://alib.dev"
1275
1276 #endif //64, 32, unrecognized
1277
1278 // deduct stuff
1279 #if (ALIB_SIZEOF_LONGDOUBLE_REPORTED == 8)
1280 # define ALIB_SIZEOF_LONGDOUBLE_WRITTEN 8
1281 #elif defined(__aarch64__)
1282 # define ALIB_SIZEOF_LONGDOUBLE_WRITTEN 16
1283 #else
1284 # define ALIB_SIZEOF_LONGDOUBLE_WRITTEN 10
1285 #endif
1286#endif
1287
1288//##################################################################################################
1289// Macro introduced by alib::characters
1290//##################################################################################################
1291#if defined(ALIB_CHARACTERS_NATIVE_WCHAR)
1292# error "Configuration macro ALIB_CHARACTERS_NATIVE_WCHAR must not be passed to the compiler. It is deduced in ALib headers."
1293#endif
1294
1295#define A_NCHAR(STR) STR
1296#if ALIB_CHARACTERS_SIZEOF_WCHAR == ALIB_SIZEOF_WCHAR_T
1297
1298 # define ALIB_CHARACTERS_NATIVE_WCHAR 1
1299 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 2
1300 #define A_WCHAR(STR) L ## STR
1301 #define A_XCHAR(STR) U ## STR
1302 #define A_SCHAR(STR) U ## STR
1303 # else
1304 #define A_WCHAR(STR) L ## STR
1305 #define A_XCHAR(STR) u ## STR
1306 #define A_SCHAR(STR) u ## STR
1307 # endif
1308
1309 #else
1310
1311 # define ALIB_CHARACTERS_NATIVE_WCHAR 0
1312
1313 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 2
1314 #define A_WCHAR(STR) u ## STR
1315 #define A_XCHAR(STR) L ## STR
1316 #define A_SCHAR(STR) L ## STR
1317 # else
1318 #define A_WCHAR(STR) U ## STR
1319 #define A_XCHAR(STR) L ## STR
1320 #define A_SCHAR(STR) L ## STR
1321 # endif
1322#endif
1323
1324#if !ALIB_CHARACTERS_WIDE || DOXYGEN
1325 #define A_CHAR(STR) STR
1326 #define A_CCHAR(STR) A_WCHAR(STR)
1327 #define ALIB_CHAR_TYPE_ID_CHARACTER 1
1328 #define ALIB_CHAR_TYPE_ID_COMPLEMENT 2
1329 #define ALIB_CHAR_TYPE_ID_STRANGE 3
1330#else
1331 #define A_CHAR(STR) A_WCHAR(STR)
1332 #define A_CCHAR(STR) STR
1333
1334 #define ALIB_CHAR_TYPE_ID_CHARACTER 2
1335 #define ALIB_CHAR_TYPE_ID_COMPLEMENT 1
1336 #define ALIB_CHAR_TYPE_ID_STRANGE 3
1337#endif
1338
1339#define ALIB_CHAR_TYPE_ID_N 1
1340#define ALIB_CHAR_TYPE_ID_W 2
1341#define ALIB_CHAR_TYPE_ID_X 3
1342
1343
1344//###################### Helper macros to specialize ArrayTraits/ZTArrayTraits #####################
1345#if !DOXYGEN
1346#define ALIB_CHARACTER_ARRAY_internal( PREFIX, T, TChar, Const, pAccess, pConstruction) \
1347template<> struct PREFIX ## ArrayTraits<T, TChar> { \
1348 static constexpr Policy Access= Policy:: pAccess; \
1349 static constexpr Policy Construction= Policy:: pConstruction; \
1350 static inline const TChar* Buffer( T Const & src ); \
1351 static inline integer Length( T Const & src ); \
1352 static inline T Construct( const TChar* array, integer length ); \
1353};
1354#endif
1355
1356#define ALIB_CHARACTER_ARRAY( T, TChar, Access , Construction ) \
1357ALIB_CHARACTER_ARRAY_internal( , T, TChar, const, Access , Construction )
1358
1359#define ALIB_CHARACTER_ARRAY_MUTABLE( T, TChar, Construction ) \
1360ALIB_CHARACTER_ARRAY_internal( , T, TChar, , MutableOnly, Construction )
1361
1362#define ALIB_CHARACTER_ZT_ARRAY( T, TChar, Access , Construction ) \
1363ALIB_CHARACTER_ARRAY_internal( ZT, T, TChar, const, Access , Construction )
1364
1365#define ALIB_CHARACTER_ZT_ARRAY_MUTABLE( T, TChar, Construction ) \
1366ALIB_CHARACTER_ARRAY_internal( ZT, T, TChar, , MutableOnly, Construction )
1367
1368
1369
1370#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER( T, TChar, ... ) \
1371const TChar* ArrayTraits<T,TChar>::Buffer(T const& src ) { __VA_ARGS__ }
1372
1373#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH( T, TChar, ... ) \
1374integer ArrayTraits<T,TChar>::Length(T const& src ) { __VA_ARGS__ }
1375
1376#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER_MUTABLE( T, TChar, ... ) \
1377const TChar* ArrayTraits<T,TChar>::Buffer(T & src ) { __VA_ARGS__ }
1378
1379#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH_MUTABLE( T, TChar, ... ) \
1380integer ArrayTraits<T,TChar>::Length(T & src ) { __VA_ARGS__ }
1381
1382#define ALIB_CHARACTER_ARRAY_IMPL_CONSTRUCT( T, TChar, ... ) \
1383 T ArrayTraits <T,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ }
1384
1385#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER( T, TChar, ... ) \
1386const TChar* ZTArrayTraits<T,TChar>::Buffer( T const& src ) { __VA_ARGS__ }
1387
1388#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH( T, TChar, ... ) \
1389integer ZTArrayTraits<T,TChar>::Length( T const& src ) { __VA_ARGS__ }
1390
1391#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER_MUTABLE(T, TChar, ... ) \
1392const TChar* ZTArrayTraits<T,TChar>::Buffer( T & src ) { __VA_ARGS__ }
1393
1394#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH_MUTABLE(T, TChar, ... ) \
1395integer ZTArrayTraits<T,TChar>::Length( T & src ) { __VA_ARGS__ }
1396
1397#define ALIB_CHARACTER_ZT_ARRAY_IMPL_CONSTRUCT( T, TChar, ... ) \
1398 T ZTArrayTraits<T,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ }
1399
1400
1401//##################################################################################################
1402// Macro introduced by lang::Owner
1403//##################################################################################################
1404#define ALIB_OWN( ownable) alib::lang::Owner <decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
1405#define ALIB_OWN_RECURSIVE(ownable) alib::lang::OwnerRecursive<decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
1406#define ALIB_OWN_SHARED( ownable) alib::lang::OwnerShared <decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
1407
1408// Thread-related aliases (placed here to achieve code agnostic from availability of module Threads)
1409#if !ALIB_SINGLE_THREADED
1410# define ALIB_LOCK ALIB_OWN(*this)
1411# define ALIB_LOCK_RECURSIVE ALIB_OWN_RECURSIVE(*this)
1412# define ALIB_LOCK_SHARED ALIB_OWN_SHARED(*this)
1413# define ALIB_LOCK_WITH(lock) ALIB_OWN(lock)
1414# define ALIB_LOCK_RECURSIVE_WITH(lock) ALIB_OWN_RECURSIVE(lock)
1415# define ALIB_LOCK_SHARED_WITH(lock) ALIB_OWN_SHARED(lock)
1416#else
1417# if ALIB_DEBUG
1418# define ALIB_LOCK { alib::assert::SingleThreaded(); }
1419# define ALIB_LOCK_RECURSIVE { alib::assert::SingleThreaded(); }
1420# define ALIB_LOCK_SHARED { alib::assert::SingleThreaded(); }
1421# define ALIB_LOCK_WITH(VOID) { alib::assert::SingleThreaded(); }
1422# define ALIB_LOCK_RECURSIVE_WITH(VOID) { alib::assert::SingleThreaded(); }
1423# define ALIB_LOCK_SHARED_WITH(VOID) { alib::assert::SingleThreaded(); }
1424# else
1425# define ALIB_LOCK {}
1426# define ALIB_LOCK_RECURSIVE {}
1427# define ALIB_LOCK_SHARED {}
1428# define ALIB_LOCK_WITH(VOID) {}
1429# define ALIB_LOCK_RECURSIVE_WITH(VOID) {}
1430# define ALIB_LOCK_SHARED_WITH(VOID) {}
1431# endif
1432#endif // ALIB_SINGLE_THREADED
1433
1434
1435// Recursive invocation detection
1436#if ALIB_DEBUG
1437#define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS_MEMBER_DECL \
1438bool dbgRecursionDetectionFlag = false;
1439
1440#define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS \
1441struct RecursionDetection \
1442{ \
1443 bool& TestMember; \
1444 RecursionDetection( bool& testMember ) : TestMember(testMember) {} \
1445 \
1446 void Acquire( const lang::CallerInfo& ci ) \
1447 { \
1448 ALIB_ASSERT_ERROR(TestMember==false,"FSOWNER","Forbidden recursive use of method ", ci.Func)\
1449 TestMember= true; \
1450 } \
1451 void Release() { TestMember= false; } \
1452}; \
1453RecursionDetection dbgRecursionDetection( dbgRecursionDetectionFlag ); \
1454ALIB_OWN(dbgRecursionDetection);
1455#else
1456# define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS_MEMBER_DECL
1457# define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS
1458#endif
1459
1460//##################################################################################################
1461// Macro introduced by lang::DbgCriticalSections
1462//##################################################################################################
1463
1464#if ALIB_DEBUG
1465# if !ALIB_SINGLE_THREADED && ALIB_DEBUG_CRITICAL_SECTIONS
1466# define ALIB_DCS ALIB_OWN(*this)
1467# define ALIB_DCS_SHARED ALIB_OWN_SHARED(*this)
1468# define ALIB_DCS_WITH(CS) ALIB_OWN(CS)
1469# define ALIB_DCS_SHARED_WITH(CS) ALIB_OWN_SHARED(CS)
1470# define ALIB_DCS_ACQUIRE Acquire(ALIB_CALLER);
1471# define ALIB_DCS_RELEASE Release(ALIB_CALLER);
1472# define ALIB_DCS_ACQUIRE_WITH(CS) CS.Acquire(ALIB_CALLER);
1473# define ALIB_DCS_RELEASE_WITH(CS) CS.Release(ALIB_CALLER);
1474# define ALIB_DCS_ACQUIRE_SHARED AcquireShared(ALIB_CALLER);
1475# define ALIB_DCS_RELEASE_SHARED ReleaseShared(ALIB_CALLER);
1476# define ALIB_DCS_ACQUIRE_SHARED_WITH(CS) CS.AcquireShared(ALIB_CALLER);
1477# define ALIB_DCS_RELEASE_SHARED_WITH(CS) CS.ReleaseShared(ALIB_CALLER);
1478# else
1479# define ALIB_DCS { alib::assert::SingleThreaded(); }
1480# define ALIB_DCS_SHARED { alib::assert::SingleThreaded(); }
1481# define ALIB_DCS_WITH(...) { alib::assert::SingleThreaded(); }
1482# define ALIB_DCS_RECURSIVE_WITH(...) { alib::assert::SingleThreaded(); }
1483# define ALIB_DCS_SHARED_WITH(...) { alib::assert::SingleThreaded(); }
1484# define ALIB_DCS_ACQUIRE { alib::assert::SingleThreaded(); }
1485# define ALIB_DCS_RELEASE {}
1486# define ALIB_DCS_ACQUIRE_WITH(CS) { alib::assert::SingleThreaded(); }
1487# define ALIB_DCS_RELEASE_WITH(CS) {}
1488# define ALIB_DCS_ACQUIRE_SHARED { alib::assert::SingleThreaded(); }
1489# define ALIB_DCS_RELEASE_SHARED {}
1490# define ALIB_DCS_ACQUIRE_SHARED_WITH(CS) { alib::assert::SingleThreaded(); }
1491# define ALIB_DCS_RELEASE_SHARED_WITH(CS) {}
1492# endif
1493#else
1494# define ALIB_DCS {}
1495# define ALIB_DCS_SHARED {}
1496# define ALIB_DCS_WITH(...) {}
1497# define ALIB_DCS_RECURSIVE_WITH(...) {}
1498# define ALIB_DCS_SHARED_WITH(...) {}
1499# define ALIB_DCS_ACQUIRE {}
1500# define ALIB_DCS_RELEASE {}
1501# define ALIB_DCS_ACQUIRE_WITH(CS) {}
1502# define ALIB_DCS_RELEASE_WITH(CS) {}
1503# define ALIB_DCS_ACQUIRE_SHARED {}
1504# define ALIB_DCS_RELEASE_SHARED {}
1505# define ALIB_DCS_ACQUIRE_SHARED_WITH(CS) {}
1506# define ALIB_DCS_RELEASE_SHARED_WITH(CS) {}
1507#endif
1508
1509#define bitsof(type) int(sizeof(type) * 8)
1510
1511#endif // INL_ALIB
#define ALIB_SIZEOF_WCHAR_T
Definition alib.inl:952