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