ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
bootstrap.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
24#if ALIB_DEBUG && !DOXYGEN
25# if defined(__GNUC__) || defined(__clang__)
26# include <cxxabi.h>
27# include <cassert>
28# endif
29# include <cstdlib>
30# if defined(_WIN32)
31# include <cstring>
32# endif
33#endif
34
35#if !DOXYGEN
37# if (ALIB_DEBUG)
38# include <cassert>
39# include <cstring>
40# if defined( _WIN32 ) && !defined(_STRING_)
41# include <string>
42# endif
43# endif
44
45#endif // !DOXYGEN
46
47#include <iostream>
48#include <iomanip>
49
50#if (ALIB_SINGLE_THREADED && ALIB_EXT_LIB_THREADS_AVAILABLE)
51# include <thread>
52#endif
53
54// =========================================== Module ==========================================
55#if ALIB_C20_MODULES
56 module ALib.Bootstrap;
57 import ALib.Lang;
58 import ALib.Time;
59 import ALib.Threads;
60# if ALIB_MONOMEM
61 import ALib.Monomem;
62# endif
63# if ALIB_STRINGS
64 import ALib.Strings;
65# endif
66# if ALIB_SINGLETONS
67 import ALib.Singletons;
68# endif
69# if ALIB_BOXING
70 import ALib.Boxing;
71# endif
72# if ALIB_ENUMRECORDS
74# endif
75# if ALIB_THREADMODEL
76 import ALib.ThreadModel;
77# endif
78# if ALIB_EXCEPTIONS
79 import ALib.Exceptions;
80# endif
81# if ALIB_SYSTEM
82 import ALib.System;
83# endif
84# if ALIB_FORMAT
85 import ALib.Format;
89# endif
90# if ALIB_CAMP
91 import ALib.Camp;
92 import ALib.Camp.Base;
93 import ALib.Resources;
94 import ALib.Variables;
95# endif
96# if ALIB_BITBUFFER
97 import ALib.BitBuffer;
98# endif
99# if ALIB_ALOX
100 import ALib.ALox;
101 import ALib.ALox.Impl;
102# endif
103# if ALIB_EXPRESSIONS
104 import ALib.Expressions;
105# endif
106# if ALIB_CLI
107 import ALib.CLI;
108# endif
109# if ALIB_FILES
110 import ALib.Files;
111# endif
112
113#else
114# include "ALib.Lang.H"
115# include "ALib.Time.H"
116# include "ALib.Threads.H"
117# include "ALib.Monomem.H"
118# include "ALib.Strings.H"
119# include "ALib.Singletons.H"
120# include "ALib.Boxing.H"
122# include "ALib.ThreadModel.H"
123# include "ALib.Exceptions.H"
124# include "ALib.System.H"
125# include "ALib.Format.H"
129# include "ALib.Variables.H"
130# include "ALib.BitBuffer.H"
131# include "ALib.Camp.H"
132# include "ALib.Camp.Base.H"
133# include "ALib.Bootstrap.H"
134# include "ALib.CLI.H"
135# include "ALib.Expressions.H"
136# include "ALib.ALox.Impl.H"
137# include "ALib.Files.H"
138#endif
139
140// ====================================== Implementation =======================================
141# include "ALib.Lang.CIFunctions.H"
142namespace alib {
143
144//==================================================================================================
145//=== Version and compilation flag verification
146//==================================================================================================
147
149unsigned char REVISION = ALIB_REVISION;
150TCompilationFlags COMPILATION_FLAGS = {ALIB_COMPILATION_FLAGS};
151
153 { 0, "ALOX" }, // modules
154 { 1, "BITBUFFER" },
155 { 2, "BOXING" },
156 { 3, "CAMP" },
157 { 4, "CONTAINERS" },
158 { 5, "CLI" },
159 { 6, "ENUMRECORDS" },
160 { 7, "EXCEPTIONS" },
161
162 { 8, "EXPRESSIONS" },
163 { 9, "FILES" },
164 { 10, "FORMAT" },
165 { 11, "MONOMEM" },
166 { 12, "RESOURCES" },
167 { 13, "SINGLETONS" },
168 { 14, "STRINGS" },
169 { 15, "SYSTEM" },
170
171 { 16, "THREADMODEL" },
172 { 17, "VARIABLES" },
173 { 18, "DEBUG" }, // debug features
174 { 19, "ALIB_DEBUG_ARRAY_COMPRESSION" },
175 { 20, "ALIB_DEBUG_ALLOCATIONS" },
176 { 21, "ALIB_DEBUG_BOXING" },
177 { 22, "ALIB_DEBUG_CONTAINERS" },
178 { 23, "ALIB_DEBUG_CRITICAL_SECTIONS" },
179
180 { 24, "ALIB_DEBUG_MEMORY" },
181 { 25, "ALIB_DEBUG_STRINGS" },
182 { 26, "ALIB_DEBUG_RESOURCES" },
183 { 27, "ALIB_C20_MODULES" }, // other features
184 { 28, "ALIB_SINGLE_THREADED" },
185 { 29, "FEAT_SINGLETON_MAPPED" },
186 { 30, "CHARACTERS_WIDE" },
187 { 31, "CHARACTERS_WCHAR_IS_4" },
188
189 { 32, "FEAT_BOXING_BIJECTIVE_INTEGRALS" },
190 { 33, "FEAT_BOXING_BIJECTIVE_CHARACTERS" },
191 { 34, "FEAT_BOXING_BIJECTIVE_FLOATS" },
192 { 35, "ALIB_FEAT_BOOST_REGEX" },
193 { 36, "DBG_LOG" },
194 { 37, "DBG_LOG_CI" },
195 { 38, "REL_LOG" },
196 { 39, "REL_LOG_CI" },
197};
198
199
200void AssertALibVersionAndFlags( int alibVersion, int alibRevision, TCompilationFlags compilationFlags )
201{
202 // verify requested ALib version is met
203 if (VERSION != alibVersion || REVISION != alibRevision )
204 {
205 std::cerr << "!!! Error in ALox library compilation: linked against wrong version of ALib" << std::endl;
206 std::cerr << "!!! ALib library version: " << VERSION << "R" << int(REVISION) << std::endl;
207 std::cerr << "!!! ALib requested version: " << alibVersion << "R" << alibRevision << std::endl;
208 std::cerr << "!!! Exiting with exit(-1)" << std::endl;
209 exit(1);
210 }
211
212 // verify the flags
213 if ( compilationFlags.bits[0] == COMPILATION_FLAGS.bits[0]
214 && compilationFlags.bits[1] == COMPILATION_FLAGS.bits[1]
215 && compilationFlags.bits[2] == COMPILATION_FLAGS.bits[2]
216 && compilationFlags.bits[3] == COMPILATION_FLAGS.bits[3] )
217 return;
218
219 std::cerr << "!!! Error in ALib library compilation: linked library of ALib has "
220 "different compiler-symbols set than the using executable (or library)." << std::endl;
221
222 // dump out the flags
223 std::cerr << std::left << std::setw(35) << "Symbol" << '|' << std::setw(5) << " Lib" <<'|' << " Comp. Unit" << std::endl;
224 std::cerr<< std::setw(62) << std::setfill('-') << ' ' << std::endl << std::setfill(' ');
225
226 for( auto& p : COMPILATION_FLAG_MEANINGS )
227 {
228 bool libFlag= (COMPILATION_FLAGS.bits[p.Flag/8] & (1 << (p.Flag % 8))) != 0;
229 bool reqFlag= (compilationFlags.bits[p.Flag/8] & (1 << (p.Flag % 8))) != 0;
230
231 std::cerr << std::setw(35) << p.Name << '|' << std::setw(5) << (libFlag ? " On" : " Off")
232 << "|" << std::setw(5) << (reqFlag ? " On" : " Off")
233 << ( libFlag != reqFlag ? " <-- Mismatch! " : "")
234 << std::endl;
235 }
236
237 // we just quit!
238 std::cerr << "!!! Exiting with exit(-1)" << std::endl;
239 exit(1);
240}
241
243
244
245//==================================================================================================
246//================================ Non-Camp Version =======================================
247//==================================================================================================
248#if !ALIB_CAMP
249void Bootstrap( int alibVersion, int alibRevision, TCompilationFlags compilationFlags )
250{
251 // verify ALib
252 AssertALibVersionAndFlags( alibVersion, alibRevision, compilationFlags );
253
254 #if ALIB_MONOMEM
255 // if the global allocator was not initialized from outside, then we have to do it.
256 if (!monomem::GLOBAL_ALLOCATOR.IsInitialized())
257 new (&monomem::GLOBAL_ALLOCATOR) MonoAllocator(ALIB_DBG("Global",) 128);
258 #endif
259
261 IF_ALIB_BOXING ( boxing ::bootstrap(); )
263
264 #if ALIB_FORMAT
265 Formatter::Default .InsertDerived<FormatterPythonStyle>();
266 Formatter::Default->Next.InsertDerived<FormatterJavaStyle >();
267 # if !ALIB_SINGLE_THREADED
268 Formatter::DefaultLock.Dbg.Name= "DefaultFormatter";
269 # if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
271 Formatter::DefaultLock.Dbg.Name= "DefaultFormatter";
272 # endif
273 # endif
274 #endif
275
276 //------------------------------------------------------------------------------------------
277 //--- Non-resourced versions of enum records
278 //------------------------------------------------------------------------------------------
279#if ALIB_ENUMRECORDS
280
281DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS])
283{
284 { lang::Bool::True , A_CHAR("False"), 1 },
285 { lang::Bool::False, A_CHAR("True" ), 1 },
286 { lang::Bool::True , A_CHAR("0" ), 1 },
287 { lang::Bool::False, A_CHAR("1" ), 1 },
288 { lang::Bool::True , A_CHAR("No" ), 1 },
289 { lang::Bool::False, A_CHAR("Yes" ), 1 },
290 { lang::Bool::True , A_CHAR("Off" ), 2 },
291 { lang::Bool::False, A_CHAR("On" ), 2 },
292 { lang::Bool::True , A_CHAR("-" ), 1 },
293 { lang::Bool::False, A_CHAR("Ok" ), 2 }
294} );
295DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS])
296
298{
299 { lang::Case::Sensitive, A_CHAR("Sensitive"), 1 },
300 { lang::Case::Ignore , A_CHAR("Ignore" ), 1 },
301} );
302
303DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS_2])
305{
306 { lang::ContainerOp::Insert , A_CHAR("Insert" ), 1 }, // integral 0
307 { lang::ContainerOp::Remove , A_CHAR("Remove" ), 1 }, // integral 1
308 { lang::ContainerOp::GetCreate, A_CHAR("GetCreate"), 4 }, // integral 3 <-- Switched order
309 { lang::ContainerOp::Get , A_CHAR("Get" ), 1 }, // integral 2 <--
310 { lang::ContainerOp::Create , A_CHAR("Create" ), 1 }, // integral 4
311} );
312DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS_2])
313
315{
316 { lang::Switch::Off , A_CHAR("Off") , 2 },
317 { lang::Switch::On , A_CHAR("On" ) , 2 },
318} );
319
321{
322 { lang::Alignment::Left , A_CHAR("Left" ) , 1 },
323 { lang::Alignment::Right , A_CHAR("Right" ) , 1 },
324 { lang::Alignment::Center , A_CHAR("Center") , 1 },
325} );
326
328{
329 { lang::SortOrder::Ascending , A_CHAR("Ascending" ) , 1 },
330 { lang::SortOrder::Descending , A_CHAR("Descending") , 1 },
331} );
332
334{
335 { lang::Inclusion::Include , A_CHAR("Include") , 1 },
336 { lang::Inclusion::Exclude , A_CHAR("Exclude") , 1 },
337} );
338
340{
341 { lang::Reach::Global , A_CHAR("Global") , 1 },
342 { lang::Reach::Local , A_CHAR("Local" ) , 1 },
343} );
344
346{
347 { lang::CurrentData::Keep , A_CHAR("Keep" ) , 1 },
348 { lang::CurrentData::Clear , A_CHAR("Clear") , 1 },
349} );
350
352{
353 { lang::SourceData::Copy , A_CHAR("Copy") , 1 },
354 { lang::SourceData::Move , A_CHAR("Move") , 1 },
355} );
356
357
359{
360 { lang::Safeness::Safe , A_CHAR("Safe" ) , 1 },
361 { lang::Safeness::Unsafe , A_CHAR("Unsafe") , 1 },
362} );
363
365{
366 { lang::Responsibility::KeepWithSender , A_CHAR("KeepWithSender"), 1 },
367 { lang::Responsibility::Transfer , A_CHAR("Transfer" ), 1 },
368} );
369
371{
372 { lang::Side::Left , A_CHAR("Left" ) , 1 },
373 { lang::Side::Right , A_CHAR("Right") , 1 },
374} );
375
377{
378 { lang::Timezone::Local , A_CHAR("v" ) , 1 },
379 { lang::Timezone::UTC , A_CHAR("UTC") , 1 },
380} );
381
383{
384 { lang::Whitespaces::Trim , A_CHAR("Trim") , 1 },
385 { lang::Whitespaces::Keep , A_CHAR("Keep") , 1 },
386} );
387
389{
390 { lang::Propagation::Omit , A_CHAR("Omit" ) , 1 },
391 { lang::Propagation::ToDescendants , A_CHAR("ToDescendants") , 1 },
392} );
393
395{
396 { lang::Phase::Begin , A_CHAR("Begin") , 1 },
397 { lang::Phase::End , A_CHAR("End" ) , 1 },
398} );
399
401{
402 { lang::Initialization::Suppress , A_CHAR("Suppress" ) , 1 },
403 { lang::Initialization::Default , A_CHAR("Default" ) , 1 },
404 { lang::Initialization::Nulled , A_CHAR("Nulled" ) , 1 },
405 { lang::Initialization::Suppress , A_CHAR("None" ) , 2 },
406 { lang::Initialization::Default , A_CHAR("Initialize") , 1 },
407 { lang::Initialization::Nulled , A_CHAR("Zero" ) , 1 },
408} );
409
411{
412 { lang::Timing::Async , A_CHAR("Async" ) , 1 },
413 { lang::Timing::Sync , A_CHAR("Sync" ) , 1 },
414 { lang::Timing::Async , A_CHAR("Asynchronous") , 1 },
415 { lang::Timing::Sync , A_CHAR("Synchronous" ) , 1 },
416 { lang::Timing::Sync , A_CHAR("Synchronized") , 1 },
417} );
418
420{
421 { lang::Caching::Disabled , A_CHAR("Disabled") , 1 },
422 { lang::Caching::Enabled , A_CHAR("Enabled" ) , 1 },
423 { lang::Caching::Auto , A_CHAR("Auto" ) , 1 },
424} );
425
426// Threads
427#if !ALIB_SINGLE_THREADED
429{
435} );
436
437#endif
438
439#if ALIB_SYSTEM
441 { system::SystemFolders::Root , A_CHAR("Root" ) , 1 },
442 { system::SystemFolders::Current , A_CHAR("Current" ) , 1 },
443 { system::SystemFolders::HomeConfig , A_CHAR("HomeConfig") , 5 },
444 { system::SystemFolders::Home , A_CHAR("Home" ) , 1 },
445 { system::SystemFolders::Module , A_CHAR("Module" ) , 1 },
446 { system::SystemFolders::Temp , A_CHAR("Temp" ) , 1 },
447 { system::SystemFolders::VarTemp , A_CHAR("VarTemp" ) , 1 },
448} );
449#endif
450
451#if ALIB_FORMAT
464} );
465
467 { format::ByteSizeUnits::B , A_CHAR("B" ) , 3 },
468 { format::ByteSizeUnits::KiB , A_CHAR("KiB" ) , 3 },
469 { format::ByteSizeUnits::MiB , A_CHAR("MiB" ) , 3 },
470 { format::ByteSizeUnits::GiB , A_CHAR("GiB" ) , 3 },
471 { format::ByteSizeUnits::TiB , A_CHAR("TiB" ) , 3 },
472 { format::ByteSizeUnits::PiB , A_CHAR("PiB" ) , 3 },
473 { format::ByteSizeUnits::EiB , A_CHAR("EiB" ) , 3 },
474 { format::ByteSizeUnits::ZiB , A_CHAR("ZiB" ) , 3 },
475 { format::ByteSizeUnits::YiB , A_CHAR("YiB" ) , 3 },
476 { format::ByteSizeUnits::RiB , A_CHAR("RiB" ) , 3 },
477 { format::ByteSizeUnits::QiB , A_CHAR("QiB" ) , 3 },
478 { format::ByteSizeUnits::B , A_CHAR("B" ) , 1 },
479 { format::ByteSizeUnits::kB , A_CHAR("kB" ) , 2 },
480 { format::ByteSizeUnits::MB , A_CHAR("MB" ) , 2 },
481 { format::ByteSizeUnits::GB , A_CHAR("GB" ) , 2 },
482 { format::ByteSizeUnits::TB , A_CHAR("TB" ) , 2 },
483 { format::ByteSizeUnits::PB , A_CHAR("PB" ) , 2 },
484 { format::ByteSizeUnits::EB , A_CHAR("EB" ) , 2 },
485 { format::ByteSizeUnits::ZB , A_CHAR("ZB" ) , 2 },
486 { format::ByteSizeUnits::YB , A_CHAR("YB" ) , 2 },
487 { format::ByteSizeUnits::RB , A_CHAR("RB" ) , 2 },
488 { format::ByteSizeUnits::QB , A_CHAR("QB" ) , 2 },
489} );
490
492{
493 A_CHAR(
494 // general formatter errors
495 "11,ArgumentIndexIs0," "Argument index 0 not allowed.\n"
496 "In: {!Q}\n >{!FillC-}^"
497 "," "12,ArgumentIndexOutOfBounds," "Argument index #{} is out of bounds. {} arguments are available.\n"
498 "In: {!Q}\n >{!FillC-}^"
499 "," "13,IncompatibleTypeCode," "Detected placeholder type does not match given argument.\n"
500 "Placeholder number: {}\n"
501 "Placeholder type: {} ({})"
502 "Placeholder type: {} ({})\n"
503 "Deduced argument type: {!Q}\n"
504 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}> ")
505 "In: {!Q}\n >{!FillC-}^"
506
507 "," "101,MissingClosingBracket," "Closing bracket '}}' of placeholder not found (or syntax error).\n"
508 "In: {!Q}\n >{!FillC-}^"
509 "," "102,MissingPrecisionValuePS," "Missing precision value after '.' character."
510 "\nIn: {!Q}\n >{!FillC-}^"
511 "," "103,DuplicateTypeCode," "Duplicate type code {!Q'} given (previous was {!Q'})."
512 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}> ")
513 "\nIn: {!Q}\n >{!FillC-}^"
514 "," "104,UnknownTypeCode," "Unknown type code {!Q'} given."
515 "\nIn: {!Q}\n >{!FillC-}^"
516 ALIB_REL_DBG( "{!X}" ,"\nNative argument type: <{}>")
517 "," "105,ExclamationMarkExpected," "Expected '!' in continuation of placeholder."
518 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}>")
519 "\nIn: {!Q}\n >{!FillC-}^"
520 "," "106,UnknownConversionPS," "Unknown conversion \"!{}\"."
521 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}>")
522 "\nIn: {!Q}\n >{!FillC-}^"
523 "," "107,PrecisionSpecificationWithInteger," "Precision not allowed with integer format."
524 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}>")
525 "\nIn: {!Q}\n >{!FillC-}^"
526 "," "108,MissingReplacementStrings," "Missing pair of replacement strings \"<src><repl>\" after \"!Replace\"."
527 ALIB_REL_DBG( "{!X}" , "\nNative argument type: <{}>")
528 "\nIn: {!Q}\n >{!FillC-}^"
529
530 "," "201,NegativeValuesInBracketsNotSupported," "Brackets for negative values not implemented/supported."
531 "\nIn: {!Q}\n >{!FillC-}^"
532 "," "202,MissingPrecisionValueJS," "Missing precision value after '.' character."
533 "\nIn: {!Q}\n >{!FillC-}^"
534 "," "203,HexadecimalFloatFormatNotSupported," "Hexadecimal float format not implemented/supported."
535 "\nIn: {!Q}\n >{!FillC-}^"
536 "," "204,NoAlternateFormOfConversion," "Alternate form '#' not supported with conversion {!Q}."
537 "\nIn: {!Q}\n >{!FillC-}^"
538 "," "205,NoPrecisionWithConversion," "Precision specification (\".{}\") is not supported with conversion {!Q}."
539 "\nIn: {!Q}\n >{!FillC-}^"
540 "," "206,UnknownDateTimeConversionSuffix," "Unknown date/time conversion suffix {!Q'}."
541 "\nIn: {!Q}\n >{!FillC-}^"
542 "," "207,UnknownConversionJS," "Unknown conversion character {!Q'}."
543 "\nIn: {!Q}\n >{!FillC-}^"
544
545 "," "501,UnknownPropertyInFormatString," "Unknown property identifier \"{}{}\" in format string.\n"
546 "Format string: {!Q}.\n"
547 "Allowed identifiers:"
548 "," "502,ErrorInResultingFormatString," "Error in resulting format string.\nSource format: {!Q}."
549 "," "510,MissingConfigurationVariable," "Missing or empty configuration variable {!Q} containing user-defined format string."
550
551 "," "601,UnknownMarker," "Unknown marker at position {}.\n"
552 " Marked text: {!Q}.\n"
553 " >{!FillC-}^"
554 "," "602,EndmarkerWithoutStart," "Found an end-marker without a start marker at position {}.\n"
555 " Marked text: {!Q}.\n"
556 " >{!FillC-}^"
557 )
558});
559#endif
560
561#if ALIB_VARIABLES
563 { variables::Priority::NONE , A_CHAR("NONE" ) , 1 },
564 { variables::Priority::AutoDetected , A_CHAR("AutoDetected" ) , 1 },
565 { variables::Priority::DefaultValues , A_CHAR("DefaultValues") , 1 },
566 { variables::Priority::Standard , A_CHAR("Standard" ) , 1 },
567 { variables::Priority::ConfigFile , A_CHAR("ConfigFile" ) , 2 },
568 { variables::Priority::Environment , A_CHAR("Environment" ) , 1 },
569 { variables::Priority::SessionFile , A_CHAR("SessionFile" ) , 8 },
570 { variables::Priority::CLI , A_CHAR("CLI" ) , 2 },
571 { variables::Priority::Session , A_CHAR("Session" ) , 2 },
572 { variables::Priority::Protected , A_CHAR("Protected" ) , 1 },
573});
574#endif
575
576#if ALIB_BITBUFFER
586});
587#endif
588
589#if ALIB_THREADMODEL
591{
592 { threadmodel::Priority::Lowest , A_CHAR("Lowest" ), 4 },
593 { threadmodel::Priority::DeferredDeletion, A_CHAR("DeferredDeletion" ), 1 },
594 { threadmodel::Priority::Low , A_CHAR("Low" ), 1 },
595 { threadmodel::Priority::Standard , A_CHAR("Standard" ), 1 },
596 { threadmodel::Priority::Highest , A_CHAR("Highest" ), 5 },
597 { threadmodel::Priority::High , A_CHAR("High" ), 1 },
598} );
599#endif
600
601
602//------------------------------------------------------------------------------------------
603//--- END: Non-resourced versions of enum records
604//------------------------------------------------------------------------------------------
605#endif // ALIB_ENUMRECORDS
606
608 }
609
610DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK])
611#if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
612 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock=
614
615 monomem::GLOBAL_ALLOCATOR_LOCK.Dbg.Name= "GlobalAllocator";
616#endif
617DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK])
618}
619
620
621void Shutdown()
622{
623 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
624 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= nullptr;
625 #if ALIB_FORMAT
626 Formatter::Default->DCSLock= nullptr;
627 #endif
628 #endif
629
630 IF_ALIB_THREADS ( alib::threads ::shutdown(); )
632 IF_ALIB_BOXING ( alib::boxing ::shutdown(); )
633 IF_ALIB_SINGLETONS ( alib::singletons ::shutdown(); )
634
635 #if ALIB_FORMAT
636 ALIB_ASSERT_WARNING( Formatter::Default.UseCount() == 1, "ALIB",
637 "DefaultFormatter still shared more than once: ", Formatter::Default.UseCount() )
638 Formatter::Default= nullptr;
639 #endif
640
642}
643
644#else
645//==================================================================================================
646//================================== Camp Version =========================================
647//==================================================================================================
648
649#if !DOXYGEN
651# include "ALib.Lang.CIFunctions.H"
652#endif
653
655{
656 // if the global allocator was not initialized from outside, then we have to do it.
657 if (!monomem::GLOBAL_ALLOCATOR.IsInitialized())
658 new (&monomem::GLOBAL_ALLOCATOR) MonoAllocator(ALIB_DBG("Global",) 128);
659
660 ALIB_ASSERT_ERROR( CAMPS.empty(), "CAMPS", "List CAMPS already set." )
661
662 CAMPS.push_back( &BASECAMP );
663 IF_ALIB_ALOX( CAMPS.push_back( &ALOX ); )
664 IF_ALIB_CLI( CAMPS.push_back( &CLI ); )
665 IF_ALIB_EXPRESSIONS( CAMPS.push_back( &EXPRESSIONS ); )
666 IF_ALIB_FILES( CAMPS.push_back( &FILES ); )
667}
668
669void Bootstrap( BootstrapPhases targetPhase,
670 camp::Camp* targetCamp,
671 int alibVersion, int alibRevision, TCompilationFlags compilationFlags )
672{
673 // verify ALib
674 AssertALibVersionAndFlags( alibVersion, alibRevision, compilationFlags );
675
676 // if not customized, create default module list
677 if( CAMPS.empty() )
679
680 if( targetCamp == nullptr )
681 targetCamp= CAMPS.back();
682
683 //std::cout << "Camp::Bootstrap called on: '" << this->ResourceCategory << "', target phase: " << int(targetPhase) << std::endl;
684
685 // Initialize non-camp modules once
687 {
688 IF_ALIB_BOXING ( boxing ::bootstrap(); )
689 IF_ALIB_THREADS( threads ::bootstrap(); )
690
691 #if ALIB_FORMAT
692 Formatter::Default .InsertDerived<FormatterPythonStyle>();
693 Formatter::Default->Next.InsertDerived<FormatterJavaStyle >();
694DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
695#if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
697#endif
698DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
699 #endif
701 }
702
703 // find target camp in the list of camps
704 auto targetCampIt= CAMPS.rbegin();
705 while(targetCampIt != CAMPS.rend() &&
706 *targetCampIt != targetCamp )
707 ++targetCampIt;
708
709 ALIB_ASSERT_ERROR(targetCampIt != CAMPS.rend(), "CAMPS",
710 "Target camp given to function alib::Bootstrap() is not included in list alib::CAMPS.\n"
711 "Resource category of the target camp: ", targetCamp->ResourceCategory )
712
713
714 // loop over all phases
715 for ( int phaseIntegral= int(targetCamp->GetBootstrapState()) + 1 ;
716 phaseIntegral <= int( targetPhase ) ;
717 ++phaseIntegral )
718 {
719 BootstrapPhases actualPhase = BootstrapPhases( phaseIntegral );
720
721 // phase 1: distribute a resource pool
722 if ( actualPhase == BootstrapPhases::PrepareResources )
723 {
724 bool skipOne= false;
725
726 // create a resource pool?
727 if ( targetCamp->GetResourcePool() == nullptr )
728 {
731 resources::LocalResourcePool* lPool= dynamic_cast<resources::LocalResourcePool*>(spPool.Get());
732
733 // \releasetask{Update resource numbers numbers. Create resource reference dox for that}
734 integer expectedSize= 102 // [ALib]
735 IF_ALIB_ALOX( + 48 )
736 IF_ALIB_CLI ( + 17 )
737 IF_ALIB_EXPRESSIONS ( + 256 )
738 IF_ALIB_FILES ( + 49 ) ;
739
740 auto& hashMap= lPool->BootstrapGetInternalHashMap();
741 hashMap.BaseLoadFactor( 2.0 );
742 hashMap.MaxLoadFactor ( 5.0 );
743 hashMap.Reserve ( expectedSize, lang::ValueReference::Absolute );
744
745 targetCamp->BootstrapSetResourcePool( spPool );
746 skipOne= true;
747 }
748
749 // loop in reverse order over modules, start with this module
750 auto actPool = targetCamp->GetResourcePool();
751 for(auto campIt= targetCampIt ; campIt != CAMPS.rend() ; ++campIt ) {
752 if ( skipOne ) { skipOne= false; continue; }
753
754 // if a different resources object is set, then use that one from now on
755 if( (*campIt)->GetResourcePool() != nullptr
756 && (*campIt)->GetResourcePool() != actPool )
757 {
758 actPool= (*campIt)->GetResourcePool();
759 continue;
760 }
761
762 (*campIt)->BootstrapSetResourcePool( actPool );
763
764 } // resources distribution loop
765 }
766
767 // phase 2: create and distribute a configuration
768 else if ( actualPhase == BootstrapPhases::PrepareConfig)
769 {
770 // create a configuration?
771 bool skipOne= false;
772 if ( targetCamp->GetConfig() == nullptr )
773 {
774 targetCamp->BootstrapSetConfig(SharedConfiguration(16u));
775 #if ALIB_DEBUG_CRITICAL_SECTIONS
776 targetCamp->GetConfig()->NodeTable().dcs.DCSName= "Camp.Config-bootstrap-created";
777 #endif
778 #if !ALIB_SINGLE_THREADED && ALIB_DEBUG
779 targetCamp->GetConfig().GetLock().Dbg.Name= "Camp.Config.Lock-bootstrap-created";
780 #endif
781 skipOne= true;
782 }
783
784 // loop in reverse order over modules, start with this module
785 SharedConfiguration* actConfig= &targetCamp->GetConfig();
786 for(auto module= targetCampIt ; module != CAMPS.rend() ; ++module )
787 {
788 if ( skipOne ) { skipOne= false; continue; }
789
790 // if a different config object is set, then use that one from now on
791 if( (*module)->GetConfig() != nullptr && (*module)->GetConfig() != *actConfig)
792 actConfig = &(*module)->GetConfig();
793 else
794 (*module)->BootstrapSetConfig( *actConfig );
795
796 } // resources distribution loop
797 }
798
799 // initialize modules on this phase
800 ALIB_DBG( bool foundThisModuleInList = false; )
801 for ( auto* camp : CAMPS )
802 {
803 // bootstrap camp
804 if(int(camp->GetBootstrapState()) >= int(actualPhase ) )
805 continue;
806
807 //std::cout << "Camp::Bootstrap '" << module->ResourceCategory << "', phase: " << int(actualPhase) << std::endl;
808
809 ALIB_ASSERT_ERROR( int(camp->GetBootstrapState()) == phaseIntegral - 1,
810 "With this invocation of Bootstrap() a camp skips a bootstrap phase.\n"
811 "Resource category of the target camp: ", camp->ResourceCategory )
812 camp->BootstrapSetPhase(actualPhase);
813 camp->Bootstrap();
814
815 // stop if this is us
816 if (camp == targetCamp )
817 {
818 ALIB_DBG( foundThisModuleInList = true );
819 break;
820 }
821 }
822 ALIB_ASSERT_ERROR( foundThisModuleInList, "CAMPS",
823 "The target camp of function Bootstrap is not included in list alib::CAMPS "
824 "or was already bootstrapped for this phase!\n"
825 "Resource category of the target camp: ", targetCamp->ResourceCategory )
826 }
827
828 // Are all camps finalized?
829 if ( targetPhase == BootstrapPhases::Final && targetCamp == CAMPS.back() )
830 {
831 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
832 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= &monomem::GLOBAL_ALLOCATOR_LOCK;
833 monomem::GLOBAL_ALLOCATOR_LOCK.Dbg.Name= "GlobalAllocator";
834 #endif
835 }
836}
837
838void Shutdown( ShutdownPhases targetPhase, camp::Camp* targetCamp )
839{
840 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
841 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= nullptr;
842 Formatter::Default->DCSLock= nullptr;
843 #endif
844
845 ALIB_ASSERT_ERROR( CAMPS.IsNotEmpty(), "CAMPS",
846 "Empty camp list on shutdown. Shutdown invoked twice?" )
847 if( targetCamp == nullptr )
848 targetCamp= CAMPS.front();
849
850 //std::cout << "Camp::Shutdown called on'" << targetCamp->ResourceCategory << "', target phase: " << int(targetPhase) << std::endl;
851
852 // find target camp in the list of camps
853 auto targetCampIt= CAMPS.begin();
854 while( targetCampIt != CAMPS.end()
855 && *targetCampIt != targetCamp )
856 ++targetCampIt;
857 ALIB_ASSERT_ERROR(targetCampIt != CAMPS.end(), "CAMPS",
858 "Target camp given to function alib::Shutdown() is not included in list alib::CAMPS.\n"
859 "Resource category of the target camp: ", targetCamp->ResourceCategory )
860
861
862 ALIB_DBG( bool foundThisModuleInList= false );
863 // loop over all (both) termination levels
864 for( int phaseIntegral= int( ShutdownPhases::Announce )
865 ; phaseIntegral<= int( targetPhase )
866 ; ++phaseIntegral )
867 {
868 ShutdownPhases actualPhase = ShutdownPhases( phaseIntegral );
869
870 // shutdown in reverse order
871 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt )
872 {
873 ALIB_ASSERT_ERROR( int(( *campIt )->GetBootstrapState()) < 0
874 || int(( *campIt )->GetBootstrapState()) == int(BootstrapPhases::Final),
875 "CAMPS", "Trying to terminate a not (fully) initialized module. "
876 "Module Name (resource category): ", targetCamp->ResourceCategory )
877
878 // shutdown module
879 if (int(( *campIt )->GetBootstrapState()) > -int(actualPhase) )
880 {
881 //std::cout << "Camp::Shutdown '" << (*campIt)->ResourceCategory << "', phase: " << int(actualPhase) << std::endl;
882
883 ALIB_ASSERT_ERROR( ( int(( *campIt )->GetBootstrapState()) == 3 && phaseIntegral == 1 )
884 || ( int(( *campIt )->GetBootstrapState()) == -1 && phaseIntegral == 2 ),
885 "CAMPS", "With this invocation of Bootstrap(), a camp skips a bootstrap phase \n"
886 "Resource category of the target camp: ", ( *campIt )->ResourceCategory )
887
888
889 ( *campIt )->Shutdown(actualPhase );
890 ( *campIt )->BootstrapSetPhase(BootstrapPhases(-int(actualPhase )) );
891
892 ALIB_DBG( if(( *campIt ) == targetCamp )
893 foundThisModuleInList= true; )
894 }
895
896 if(( *campIt ) == targetCamp )
897 break;
898 }
899 }
900 ALIB_ASSERT_ERROR( foundThisModuleInList, "CAMPS",
901 "The target camp of function Shutdown is not included in list alib::CAMPS "
902 "or was already shutdown for this phase!\n"
903 "Resource category of the target camp: ", targetCamp->ResourceCategory )
904
905
906 #if ALIB_DEBUG_CRITICAL_SECTIONS
907 // deactivate assertions for non-locked access to configuration
908 if( targetPhase == ShutdownPhases::Announce)
909 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt )
910 (*campIt)->GetConfig()->NodeTable().dcs.DCSLock= nullptr;
911 #endif
912
913 // delete resources/config
914 if( targetPhase == ShutdownPhases::Destruct)
915 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt )
916 {
917 ( *campIt )->BootstrapSetResourcePool(nullptr);
918 ( *campIt )->BootstrapSetConfig(nullptr);
919
920 if(( *campIt ) == targetCamp )
921 break;
922 }
923
924 if( targetPhase == ShutdownPhases::Destruct
925 && targetCamp == CAMPS.front() )
926 {
927 IF_ALIB_THREADS( threads ::shutdown(); )
929 IF_ALIB_BOXING( boxing ::shutdown(); )
930 IF_ALIB_SINGLETONS( singletons ::shutdown(); )
931
932 ALIB_ASSERT_WARNING( Formatter::Default.UseCount() == 1, "ALIB",
933 "DefaultFormatter still shared more than once: ", Formatter::Default.UseCount() )
934 Formatter::Default= nullptr;
935
936 CAMPS.Reset();
938 }
939}
940
941#endif // ALIB_CAMP
942} // namespace [alib]
943
944
945
946# include "ALib.Lang.CIMethods.H"
947
948
949
950
951
@ Huffman
Huffman encoding (byte based).
Definition ac.inl:270
@ Incremental
Only distances of the values are written.
Definition ac.inl:267
@ ALL
All compression methods selected.
Definition ac.inl:250
@ Sparse
Writes '1' if next value is equal to previous, '0' plus next value otherwise.
Definition ac.inl:261
@ MinMax
Stores the differences between the minimum and maximum value found.
Definition ac.inl:258
@ VerySparse
Writes the number of following equal or non equal values.
Definition ac.inl:264
@ NONE
No compression method selected.
Definition ac.inl:247
NCString ResourceCategory
Definition camp.inl:113
BootstrapPhases GetBootstrapState()
Definition camp.inl:176
SharedConfiguration & GetConfig()
Definition camp.inl:215
SharedPtr< resources::ResourcePool, MonoAllocator > SPResourcePool
Definition camp.inl:86
void BootstrapSetConfig(const SharedConfiguration &pConfig)
Definition camp.inl:205
void BootstrapSetResourcePool(const SPResourcePool &pResourcePool)
Definition camp.inl:232
SPResourcePool & GetResourcePool()
Definition camp.inl:243
void InsertDerived(TArgs &&... args)
@ Float
Outputs a number in floating point format.
@ IntBinary
Outputs a given number in base 2.
@ IntBase10
Outputs a given number in base 10. The default.
@ IntHex
Outputs a given number in base 16.
@ IntOctal
Outputs a given number in base 8.
static ALIB_DLL threads::RecursiveLock DefaultLock
static ALIB_DLL SPFormatter Default
lang::Placeholder< lang::DbgCriticalSections > DbgCriticalSectionsPH
TLock & GetLock() const noexcept
@ Running
The thread's Run method is currently processed.
Definition thread.inl:141
@ Started
Method Start was invoked but not running, yet.
Definition thread.inl:140
@ Terminated
The thread is terminated.
Definition thread.inl:144
#define IF_ALIB_FILES(...)
Definition alib.inl:353
#define IF_ALIB_BOXING(...)
Definition alib.inl:273
#define IF_ALIB_CLI(...)
Definition alib.inl:313
#define ALIB_REVISION
Definition alib.inl:21
#define IF_ALIB_THREADS(...)
Definition alib.inl:401
#define A_CHAR(STR)
#define ALIB_VERSION
Definition alib.inl:20
#define IF_ALIB_ALOX(...)
Definition alib.inl:257
#define IF_ALIB_SINGLETONS(...)
Definition alib.inl:369
#define ALIB_ASSERT_WARNING(cond, domain,...)
Definition alib.inl:1050
#define IF_ALIB_ENUMRECORDS(...)
Definition alib.inl:337
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
#define IF_ALIB_EXPRESSIONS(...)
Definition alib.inl:345
#define ALIB_REL_DBG(releaseCode,...)
Definition alib.inl:838
#define ALIB_FORMAT
Definition alib.inl:227
void Bootstrap(camp::Camp &camp, const NString &name, character innerDelim=',', character outerDelim=',')
Definition camp.inl:329
@ Ascending
Chooses ascending sort oder.
@ Descending
Chooses descending sort oder.
@ Right
Denotes the right side of something.
@ Left
Denotes the left side of something.
@ Copy
Chooses not to clear existing data.
@ Move
Chooses to clear existing data.
@ Global
Denotes global reach.
@ Local
Denotes local reach.
@ Center
Chooses centered alignment.
@ Right
Chooses right alignment.
@ Left
Chooses left alignment.
@ False
False value.
@ Remove
Denotes removals.
@ GetCreate
Denotes to create data if not found.
@ Create
Denotes to create data.
@ Insert
Denotes insertions.
@ Get
Denotes to search data.
@ On
Switch it on, switched on, etc.
@ Off
Switch it off, switched off, etc.
@ Begin
The start of a transaction.
@ End
The end of a transaction.
@ Keep
Chooses not no clear existing data.
@ Clear
Chooses to clear existing data.
@ Keep
Keep whitespaces in string.
@ Trim
Trim whitespaces away.
@ Enabled
Caching is enabled.
@ Auto
Auto/default mode.
@ Disabled
Caching is disabled.
@ KeepWithSender
Keeps responsibility, e.g., when passing an object.
@ Transfer
Transfers responsibility to the receiving party.
@ Omit
Do not propagate changes.
@ ToDescendants
Propagate changes to descendants/children/subcomponents.
@ Absolute
Referring to an absolute value.
@ Safe
Do it or treat it with safety.
@ Unsafe
Omit checks or perform unsafe operations.
@ Exclude
Chooses exclusion.
@ Include
Chooses inclusion.
@ Local
Denotes local time.
@ UTC
Denotes UTC (coordinated universal time).
ALIB_DLL TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
ALIB_DLL RecursiveLock GLOBAL_ALLOCATOR_LOCK
void bootstrap()
Definition thread.cpp:138
CompilationFlagMeaningsEntry COMPILATION_FLAG_MEANINGS[40]
format::FormatterJavaStyle FormatterJavaStyle
Type alias in namespace alib.
void AssertALibVersionAndFlags(int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
unsigned char REVISION
BootstrapPhases
Definition camp.inl:15
@ Final
The final initialization phase. Here, camps are initializing their custom setup.
Definition camp.inl:35
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class Basecamp.
Definition basecamp.cpp:81
void BootstrapAddDefaultCamps()
ShutdownPhases
Termination levels usable with Bootstrapping ALib Camps.
Definition camp.inl:42
@ Destruct
The main phase of termination that destructs everything.
Definition camp.inl:46
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
cli::CliCamp CLI
The singleton instance of ALib Camp class CliCamp.
Definition clicamp.cpp:42
variables::TSharedConfiguration< SharedLock > SharedConfiguration
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
void Bootstrap(BootstrapPhases targetPhase, camp::Camp *targetCamp, int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
int VERSION
format::Formatter Formatter
Type alias in namespace alib.
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class ALoxCamp.
Definition aloxcamp.cpp:53
bool NonCampModulesInitialized
files::FilesCamp FILES
The singleton instance of ALib Camp class FilesCamp.
Definition filescamp.cpp:47
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class ExpressionsCamp.
TCompilationFlags COMPILATION_FLAGS
ALIB_DLL void Shutdown()
containers::List< TAllocator, T, TRecycling > List
Type alias in namespace alib.
Definition list.inl:746
ALIB_DLL List< MonoAllocator, camp::Camp * > CAMPS
This is a struct composing an entry in COMPILATION_FLAG_MEANINGS.
Definition bootstrap.mpp:69
unsigned char bits[5]
Definition lang.mpp:62