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