ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
bootstrap.cpp
2namespace alib {
3
4//==================================================================================================
5//=== Version and compilation flag verification
6//==================================================================================================
7
9unsigned char REVISION = ALIB_REVISION;
11
13 { 0, "ALOX" }, // modules
14 { 1, "APP" },
15 { 2, "BITBUFFER" },
16 { 3, "BOXING" },
17 { 4, "CAMP" },
18 { 5, "CONTAINERS" },
19 { 6, "ENUMRECORDS" },
20 { 7, "EXCEPTIONS" },
21
22 { 8, "EXPRESSIONS" },
23 { 9, "FILETREE" },
24 { 10, "FORMAT" },
25 { 11, "MONOMEM" },
26 { 12, "RESOURCES" },
27 { 13, "SINGLETONS" },
28 { 14, "STRINGS" },
29 { 15, "SYSTEM" },
30
31 { 16, "THREADMODEL" },
32 { 17, "VARIABLES" },
33 { 18, "DEBUG" }, // debug features
34 { 19, "ALIB_DEBUG_ARRAY_COMPRESSION" },
35 { 20, "ALIB_DEBUG_ALLOCATIONS" },
36 { 21, "ALIB_DEBUG_BOXING" },
37 { 22, "ALIB_DEBUG_CONTAINERS" },
38 { 23, "ALIB_DEBUG_CRITICAL_SECTIONS" },
39
40 { 24, "ALIB_DEBUG_MEMORY" },
41 { 25, "ALIB_DEBUG_STRINGS" },
42 { 26, "ALIB_DEBUG_RESOURCES" },
43 { 27, "ALIB_C20_MODULES" }, // other features
44 { 28, "ALIB_SINGLE_THREADED" },
45 { 29, "FEAT_SINGLETON_MAPPED" },
46 { 30, "CHARACTERS_WIDE" },
47 { 31, "CHARACTERS_WCHAR_IS_4" },
48
49 { 32, "FEAT_BOXING_BIJECTIVE_INTEGRALS" },
50 { 33, "FEAT_BOXING_BIJECTIVE_CHARACTERS" },
51 { 34, "FEAT_BOXING_BIJECTIVE_FLOATS" },
52 { 35, "ALIB_FEAT_BOOST_REGEX" },
53 { 36, "DBG_LOG" },
54 { 37, "DBG_LOG_CI" },
55 { 38, "REL_LOG" },
56 { 39, "REL_LOG_CI" },
57};
58
59
60void AssertALibVersionAndFlags( int alibVersion, int alibRevision,
61 TCompilationFlags compilationFlags ) {
62 // verify requested ALib version is met
63 if (VERSION != alibVersion || REVISION != alibRevision ) {
64 std::cerr << "!!! Error in ALox library compilation: linked against wrong version of ALib" << std::endl;
65 std::cerr << "!!! ALib library version: " << VERSION << "R" << int(REVISION) << std::endl;
66 std::cerr << "!!! ALib requested version: " << alibVersion << "R" << alibRevision << std::endl;
67 std::cerr << "!!! Exiting with exit(-1)" << std::endl;
68 exit(1);
69 }
70
71 // verify the flags
72 if ( compilationFlags.bits[0] == COMPILATION_FLAGS.bits[0]
73 && compilationFlags.bits[1] == COMPILATION_FLAGS.bits[1]
74 && compilationFlags.bits[2] == COMPILATION_FLAGS.bits[2]
75 && compilationFlags.bits[3] == COMPILATION_FLAGS.bits[3] )
76 return;
77
78 std::cerr << "!!! Error in ALib library compilation: linked library of ALib has "
79 "different configuration macros set than the using executable (or library)." << std::endl;
80
81 // dump out the flags
82 std::cerr << std::left << std::setw(35) << "Symbol" << '|' << std::setw(5) << " Lib" <<'|' << " Comp. Unit" << std::endl;
83 std::cerr<< std::setw(62) << std::setfill('-') << ' ' << std::endl << std::setfill(' ');
84
85 for( auto& p : COMPILATION_FLAG_MEANINGS ) {
86 bool libFlag= (COMPILATION_FLAGS.bits[p.Flag/8] & (1 << (p.Flag % 8))) != 0;
87 bool reqFlag= (compilationFlags.bits[p.Flag/8] & (1 << (p.Flag % 8))) != 0;
88
89 std::cerr << std::setw(35) << p.Name << '|' << std::setw(5) << (libFlag ? " On" : " Off")
90 << "|" << std::setw(5) << (reqFlag ? " On" : " Off")
91 << ( libFlag != reqFlag ? " <-- Mismatch! " : "")
92 << std::endl;
93 }
94
95 // we just quit!
96 std::cerr << "!!! Exiting with exit(-1)" << std::endl;
97 exit(1);
98}
99
101
102
103//==================================================================================================
104//========================================= Non-Camp Version =======================================
105//==================================================================================================
106#if !ALIB_CAMP
107void Bootstrap( int alibVersion, int alibRevision, TCompilationFlags compilationFlags )
108{
109 // verify ALib
110 AssertALibVersionAndFlags( alibVersion, alibRevision, compilationFlags );
111
112 #if ALIB_MONOMEM
113 // if the global allocator was not initialized from outside, then we have to do it.
114 if (!monomem::GLOBAL_ALLOCATOR.IsInitialized())
115 new (&monomem::GLOBAL_ALLOCATOR) MonoAllocator(ALIB_DBG("Global",) 128);
116 #endif
117
119 IF_ALIB_BOXING ( boxing ::bootstrap(); )
121
122 #if ALIB_FORMAT
123 Formatter::DEFAULT .InsertDerived<FormatterPythonStyle>();
124 Formatter::DEFAULT->Next.InsertDerived<FormatterJavaStyle >();
125 # if !ALIB_SINGLE_THREADED
126 ALIB_DBG(Formatter::DEFAULT_LOCK.Dbg.Name= "DefaultFormatter";)
127 # if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
129 Formatter::DEFAULT_LOCK.Dbg.Name= "DefaultFormatter";
130 # endif
131 # endif
132 #endif
133
134 //--------------------------------------------------------------------------------------------
135 //--- Non-resourced versions of enum records
136 //--------------------------------------------------------------------------------------------
137#if ALIB_ENUMRECORDS
138
139// CodeMarker_CommonEnums
140
142 { lang::Alignment::Left , A_CHAR("Left" ) , 1 },
143 { lang::Alignment::Right , A_CHAR("Right" ) , 1 },
144 { lang::Alignment::Center , A_CHAR("Center") , 1 },
145} );
146
147DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS])
149 { lang::Bool::False, A_CHAR("False"), 1 },
150 { lang::Bool::True , A_CHAR("True" ), 1 },
151 { lang::Bool::False, A_CHAR("0" ), 1 },
152 { lang::Bool::True , A_CHAR("1" ), 1 },
153 { lang::Bool::False, A_CHAR("No" ), 1 },
154 { lang::Bool::True , A_CHAR("Yes" ), 1 },
155 { lang::Bool::False, A_CHAR("Off" ), 2 },
156 { lang::Bool::True , A_CHAR("On" ), 2 },
157 { lang::Bool::False, A_CHAR("-" ), 1 },
158 { lang::Bool::True , A_CHAR("Ok" ), 2 }
159} );
160DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS])
161
163 { lang::Caching::Disabled , A_CHAR("Disabled") , 1 },
164 { lang::Caching::Enabled , A_CHAR("Enabled" ) , 1 },
165 { lang::Caching::Auto , A_CHAR("Auto" ) , 1 },
166} );
167
169 { lang::Case::Sensitive, A_CHAR("Sensitive"), 1 },
170 { lang::Case::Ignore , A_CHAR("Ignore" ), 1 },
171} );
172
173DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS_2])
175 { lang::ContainerOp::Insert , A_CHAR("Insert" ), 1 }, // integral 0
176 { lang::ContainerOp::Remove , A_CHAR("Remove" ), 1 }, // integral 1
177 { lang::ContainerOp::GetCreate, A_CHAR("GetCreate"), 4 }, // integral 3 <-- Switched order
178 { lang::ContainerOp::Get , A_CHAR("Get" ), 1 }, // integral 2 <--
179 { lang::ContainerOp::Create , A_CHAR("Create" ), 1 }, // integral 4
180} );
181DOX_MARKER([DOX_ENUMS_MULTIPLE_RECORDS_2])
182
184 { lang::CreateDefaults::No , A_CHAR("False"), 1 },
185 { lang::CreateDefaults::Yes, A_CHAR("True" ), 1 },
186 { lang::CreateDefaults::No , A_CHAR("0" ), 1 },
187 { lang::CreateDefaults::Yes, A_CHAR("1" ), 1 },
188 { lang::CreateDefaults::No , A_CHAR("No" ), 1 },
189 { lang::CreateDefaults::Yes, A_CHAR("Yes" ), 1 },
190 { lang::CreateDefaults::No , A_CHAR("Off" ), 2 },
191 { lang::CreateDefaults::Yes, A_CHAR("On" ), 2 },
192 { lang::CreateDefaults::No , A_CHAR("-" ), 1 },
193 { lang::CreateDefaults::Yes, A_CHAR("Ok" ), 2 }
194} );
195
197 { lang::CreateIfNotExists::No , A_CHAR("False"), 1 },
198 { lang::CreateIfNotExists::Yes, A_CHAR("True" ), 1 },
199 { lang::CreateIfNotExists::No , A_CHAR("0" ), 1 },
201 { lang::CreateIfNotExists::No , A_CHAR("No" ), 1 },
202 { lang::CreateIfNotExists::Yes, A_CHAR("Yes" ), 1 },
203 { lang::CreateIfNotExists::No , A_CHAR("Off" ), 2 },
205 { lang::CreateIfNotExists::No , A_CHAR("-" ), 1 },
207} );
208
210 { lang::CurrentData::Keep , A_CHAR("Keep" ) , 1 },
211 { lang::CurrentData::Clear , A_CHAR("Clear") , 1 },
212} );
213
215 { lang::Inclusion::Include , A_CHAR("Include") , 1 },
216 { lang::Inclusion::Exclude , A_CHAR("Exclude") , 1 },
217} );
218
220 { lang::Initialization::Suppress , A_CHAR("Suppress" ) , 1 },
221 { lang::Initialization::Default , A_CHAR("Default" ) , 1 },
222 { lang::Initialization::Nulled , A_CHAR("Nulled" ) , 1 },
223 { lang::Initialization::Suppress , A_CHAR("None" ) , 2 },
224 { lang::Initialization::Default , A_CHAR("Initialize") , 1 },
225 { lang::Initialization::Nulled , A_CHAR("Zero" ) , 1 },
226} );
227
229 { lang::LineFeeds::None , A_CHAR("None" ) , 1 },
230 { lang::LineFeeds::Ignore , A_CHAR("Ignore" ) , 1 },
231 { lang::LineFeeds::Unix , A_CHAR("Unix" ) , 1 },
232 { lang::LineFeeds::WindowsOS , A_CHAR("WindowsOS") , 1 },
233 { lang::LineFeeds::Platform , A_CHAR("Platform" ) , 1 },
234} );
235
237 { lang::Phase::Begin , A_CHAR("Begin") , 1 },
238 { lang::Phase::End , A_CHAR("End" ) , 1 },
239} );
240
242 { lang::Propagation::Omit , A_CHAR("Omit" ) , 1 },
243 { lang::Propagation::ToDescendants , A_CHAR("ToDescendants") , 1 },
244} );
245
247 { lang::Reach::Global , A_CHAR("Global") , 1 },
248 { lang::Reach::Local , A_CHAR("Local" ) , 1 },
249} );
250
252 { lang::Recursive::No , A_CHAR("False"), 1 },
253 { lang::Recursive::Yes, A_CHAR("True" ), 1 },
254 { lang::Recursive::No , A_CHAR("0" ), 1 },
255 { lang::Recursive::Yes, A_CHAR("1" ), 1 },
256 { lang::Recursive::No , A_CHAR("No" ), 1 },
257 { lang::Recursive::Yes, A_CHAR("Yes" ), 1 },
258 { lang::Recursive::No , A_CHAR("Off" ), 2 },
259 { lang::Recursive::Yes, A_CHAR("On" ), 2 },
260 { lang::Recursive::No , A_CHAR("-" ), 1 },
261 { lang::Recursive::Yes, A_CHAR("Ok" ), 2 }
262} );
263
265 { lang::Responsibility::KeepWithSender , A_CHAR("KeepWithSender") , 1 },
266 { lang::Responsibility::Transfer , A_CHAR("Transfer" ) , 1 },
267} );
268
270 { lang::Safeness::Safe , A_CHAR("Safe" ) , 1 },
271 { lang::Safeness::Unsafe , A_CHAR("Unsafe") , 1 },
272} );
273
275 { lang::Side::Left , A_CHAR("Left" ) , 1 },
276 { lang::Side::Right , A_CHAR("Right") , 1 },
277} );
278
280 { lang::SortOrder::Ascending , A_CHAR("Ascending" ) , 1 },
281 { lang::SortOrder::Descending , A_CHAR("Descending") , 1 },
282} );
283
285 { lang::SourceData::Copy , A_CHAR("Copy") , 1 },
286 { lang::SourceData::Move , A_CHAR("Move") , 1 },
287} );
288
290 { lang::Switch::Off , A_CHAR("Off") , 2 },
291 { lang::Switch::On , A_CHAR("On" ) , 2 },
292} );
293
295 { lang::Timezone::Local , A_CHAR("Local" ) , 1 },
296 { lang::Timezone::UTC , A_CHAR("UTC") , 1 },
297} );
298
300 { lang::Timing::Async , A_CHAR("Async" ) , 1 },
301 { lang::Timing::Sync , A_CHAR("Sync" ) , 1 },
302 { lang::Timing::Async , A_CHAR("Asynchronous") , 1 },
303 { lang::Timing::Sync , A_CHAR("Synchronous" ) , 1 },
304 { lang::Timing::Sync , A_CHAR("Synchronized") , 1 },
305} );
306
308 { lang::ValueReference::Absolute , A_CHAR("Absolute") , 1 },
309 { lang::ValueReference::Relative , A_CHAR("Relative") , 1 },
310} );
311
313 { lang::Whitespaces::Trim , A_CHAR("Trim") , 1 },
314 { lang::Whitespaces::Keep , A_CHAR("Keep") , 1 },
315} );
316
317
318// Threads
319#if !ALIB_SINGLE_THREADED
326} );
327
328#endif
329
330#if ALIB_SYSTEM
332 { system::SystemFolders::Root , A_CHAR("Root" ) , 1 },
333 { system::SystemFolders::Current , A_CHAR("Current" ) , 1 },
334 { system::SystemFolders::HomeConfig , A_CHAR("HomeConfig") , 5 },
335 { system::SystemFolders::Home , A_CHAR("Home" ) , 1 },
336 { system::SystemFolders::Module , A_CHAR("Module" ) , 1 },
337 { system::SystemFolders::Temp , A_CHAR("Temp" ) , 1 },
338 { system::SystemFolders::VarTemp , A_CHAR("VarTemp" ) , 1 },
339} );
340#endif
341
342#if ALIB_FORMAT
355} );
356
358 { format::ByteSizeUnits::B , A_CHAR("B" ) , 3 },
359 { format::ByteSizeUnits::KiB , A_CHAR("KiB" ) , 3 },
360 { format::ByteSizeUnits::MiB , A_CHAR("MiB" ) , 3 },
361 { format::ByteSizeUnits::GiB , A_CHAR("GiB" ) , 3 },
362 { format::ByteSizeUnits::TiB , A_CHAR("TiB" ) , 3 },
363 { format::ByteSizeUnits::PiB , A_CHAR("PiB" ) , 3 },
364 { format::ByteSizeUnits::EiB , A_CHAR("EiB" ) , 3 },
365 { format::ByteSizeUnits::ZiB , A_CHAR("ZiB" ) , 3 },
366 { format::ByteSizeUnits::YiB , A_CHAR("YiB" ) , 3 },
367 { format::ByteSizeUnits::RiB , A_CHAR("RiB" ) , 3 },
368 { format::ByteSizeUnits::QiB , A_CHAR("QiB" ) , 3 },
369 { format::ByteSizeUnits::B , A_CHAR("B" ) , 1 },
370 { format::ByteSizeUnits::kB , A_CHAR("kB" ) , 2 },
371 { format::ByteSizeUnits::MB , A_CHAR("MB" ) , 2 },
372 { format::ByteSizeUnits::GB , A_CHAR("GB" ) , 2 },
373 { format::ByteSizeUnits::TB , A_CHAR("TB" ) , 2 },
374 { format::ByteSizeUnits::PB , A_CHAR("PB" ) , 2 },
375 { format::ByteSizeUnits::EB , A_CHAR("EB" ) , 2 },
376 { format::ByteSizeUnits::ZB , A_CHAR("ZB" ) , 2 },
377 { format::ByteSizeUnits::YB , A_CHAR("YB" ) , 2 },
378 { format::ByteSizeUnits::RB , A_CHAR("RB" ) , 2 },
379 { format::ByteSizeUnits::QB , A_CHAR("QB" ) , 2 },
380} );
381
383 A_CHAR(
384 // general formatter errors
385 "11,ArgumentIndexIs0," "Argument index 0 not allowed.\n"
386 "In: {!Q}\n >{!FillC-}^"
387 "," "12,ArgumentIndexOutOfBounds," "Argument index #{} is out of bounds. {} arguments are available.\n"
388 "In: {!Q}\n >{!FillC-}^"
389 "," "13,IncompatibleTypeCode," "Detected placeholder type does not match given argument.\n"
390 "Placeholder number: {}\n"
391 "Placeholder type: {} ({})"
392 "Placeholder type: {} ({})\n"
393 "Deduced argument type: {!Q}\n"
394 "In: {!Q}\n >{!FillC-}^"
395
396 "," "101,MissingClosingBracket," "Closing bracket '}}' of placeholder not found (or syntax error).\n"
397 "In: {!Q}\n >{!FillC-}^"
398 "," "102,MissingPrecisionValuePS," "Missing precision value after '.' character."
399 "\nIn: {!Q}\n >{!FillC-}^"
400 "," "103,DuplicateTypeCode," "Duplicate type code {!Q'} given (previous was {!Q'})."
401 "\nIn: {!Q}\n >{!FillC-}^"
402 "," "104,UnknownTypeCode," "Unknown type code {!Q'} given."
403 "\nIn: {!Q}\n >{!FillC-}^"
404 "," "105,ExclamationMarkExpected," "Expected '!' in continuation of placeholder."
405 "\nIn: {!Q}\n >{!FillC-}^"
406 "," "106,UnknownConversionPS," "Unknown conversion \"!{}\"."
407 "\nIn: {!Q}\n >{!FillC-}^"
408 "," "107,PrecisionSpecificationWithInteger," "Precision not allowed with integer format."
409 "\nIn: {!Q}\n >{!FillC-}^"
410 "," "108,MissingReplacementStrings," "Missing pair of replacement strings \"<src><repl>\" after \"!Replace\"."
411 "\nIn: {!Q}\n >{!FillC-}^"
412
413 "," "201,NegativeValuesInBracketsNotSupported," "Brackets for negative values not implemented/supported."
414 "\nIn: {!Q}\n >{!FillC-}^"
415 "," "202,MissingPrecisionValueJS," "Missing precision value after '.' character."
416 "\nIn: {!Q}\n >{!FillC-}^"
417 "," "203,HexadecimalFloatFormatNotSupported," "Hexadecimal float format not implemented/supported."
418 "\nIn: {!Q}\n >{!FillC-}^"
419 "," "204,NoAlternateFormOfConversion," "Alternate form '#' not supported with conversion {!Q}."
420 "\nIn: {!Q}\n >{!FillC-}^"
421 "," "205,NoPrecisionWithConversion," "Precision specification (\".{}\") is not supported with conversion {!Q}."
422 "\nIn: {!Q}\n >{!FillC-}^"
423 "," "206,UnknownDateTimeConversionSuffix," "Unknown date/time conversion suffix {!Q'}."
424 "\nIn: {!Q}\n >{!FillC-}^"
425 "," "207,UnknownConversionJS," "Unknown conversion character {!Q'}."
426 "\nIn: {!Q}\n >{!FillC-}^"
427
428 "," "501,UnknownPropertyInFormatString," "Unknown property identifier \"{}{}\" in format string.\n"
429 "Format string: {!Q}.\n"
430 "Allowed identifiers:"
431 "," "502,ErrorInResultingFormatString," "Error in resulting format string.\nSource format: {!Q}."
432 "," "510,MissingConfigurationVariable," "Missing or empty configuration variable {!Q} containing user-defined format string."
433
434 "," "601,UnknownMarker," "Unknown marker at position {}.\n"
435 " Marked text: {!Q}.\n"
436 " >{!FillC-}^"
437 "," "602,EndmarkerWithoutStart," "Found an end-marker without a start marker at position {}.\n"
438 " Marked text: {!Q}.\n"
439 " >{!FillC-}^"
440 )
441});
442#endif
443
444#if ALIB_VARIABLES
446 { variables::Priority::NONE , A_CHAR("NONE" ) , 1 },
447 { variables::Priority::AutoDetected , A_CHAR("AutoDetected" ) , 1 },
448 { variables::Priority::DefaultValues , A_CHAR("DefaultValues") , 1 },
449 { variables::Priority::Standard , A_CHAR("Standard" ) , 1 },
450 { variables::Priority::ConfigFile , A_CHAR("ConfigFile" ) , 2 },
451 { variables::Priority::Environment , A_CHAR("Environment" ) , 1 },
452 { variables::Priority::SessionFile , A_CHAR("SessionFile" ) , 8 },
453 { variables::Priority::CLI , A_CHAR("CLI" ) , 2 },
454 { variables::Priority::Session , A_CHAR("Session" ) , 2 },
455 { variables::Priority::Protected , A_CHAR("Protected" ) , 1 },
456});
457#endif
458
459#if ALIB_BITBUFFER
469});
470#endif
471
472#if ALIB_THREADMODEL
474 { threadmodel::Priority::Lowest , A_CHAR("Lowest" ), 4 },
475 { threadmodel::Priority::DeferredDeletion, A_CHAR("DeferredDeletion" ), 1 },
476 { threadmodel::Priority::Low , A_CHAR("Low" ), 1 },
477 { threadmodel::Priority::Standard , A_CHAR("Standard" ), 1 },
478 { threadmodel::Priority::Highest , A_CHAR("Highest" ), 5 },
479 { threadmodel::Priority::High , A_CHAR("High" ), 1 },
480} );
481#endif
482
483
484//--------------------------------------------------------------------------------------------------
485//--- END: Non-resourced versions of enum records
486//--------------------------------------------------------------------------------------------------
487#endif // ALIB_ENUMRECORDS
488
490 }
491
492DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK])
493#if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
494 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock=
496
497 monomem::GLOBAL_ALLOCATOR_LOCK.Dbg.Name= "GlobalAllocator";
498#endif
499DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK])
500}
501
502
503void Shutdown()
504{
505 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
506 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= nullptr;
507 #if ALIB_FORMAT
508 Formatter::DEFAULT->DCSLock= nullptr;
509 #endif
510 #endif
511
512 IF_ALIB_THREADS ( alib::threads ::shutdown(); )
514 IF_ALIB_BOXING ( alib::boxing ::shutdown(); )
515 IF_ALIB_SINGLETONS ( alib::singletons ::shutdown(); )
516
517 #if ALIB_FORMAT
518 ALIB_ASSERT_WARNING( Formatter::DEFAULT.UseCount() == 1, "ALIB",
519 "DefaultFormatter still shared more than once: ", Formatter::DEFAULT.UseCount() )
520 Formatter::DEFAULT= nullptr;
521 #endif
522
524}
525
526#else
527//==================================================================================================
528//=========================================== Camp Version =========================================
529//==================================================================================================
530
531#if !DOXYGEN
533# include "ALib.Lang.CIFunctions.H"
534#endif
535
537 // if the global allocator was not initialized from outside, then we have to do it.
538 if (!monomem::GLOBAL_ALLOCATOR.IsInitialized())
539 new (&monomem::GLOBAL_ALLOCATOR) MonoAllocator(ALIB_DBG("Global",) 128);
540
541 ALIB_ASSERT_ERROR( CAMPS.empty(), "CAMPS", "List CAMPS already set." )
542
543 CAMPS.push_back( &BASECAMP );
544 IF_ALIB_ALOX( CAMPS.push_back( &ALOX ); )
545 IF_ALIB_APP( CAMPS.push_back( &APP ); )
546 IF_ALIB_EXPRESSIONS( CAMPS.push_back( &EXPRESSIONS ); )
547 IF_ALIB_FILETREE( CAMPS.push_back( &FILETREE ); )
548}
549
550void Bootstrap( BootstrapPhases targetPhase,
551 camp::Camp* targetCamp,
552 int alibVersion, int alibRevision, TCompilationFlags compilationFlags ) {
553 // verify ALib
554 AssertALibVersionAndFlags( alibVersion, alibRevision, compilationFlags );
555
556 // if not customized, create default module list
557 if( CAMPS.empty() )
559
560 // check for doubly added camps
561 #if ALIB_DEBUG
562 {
564 MonoAllocator::Resetter resetter(monomem::GLOBAL_ALLOCATOR);
566 std::ranges::copy(CAMPS.begin(), CAMPS.end(), std::back_inserter(dedup) );
567 std::ranges::sort(dedup);
568 for(auto it= dedup.begin() + 1; it != dedup.end(); ++it)
569 ALIB_ASSERT_ERROR( *it != *(it -1), "CAMPS",
570 "Duplicate entry in CAMPS list. ResourceCategory of duplicated camp is: ",
571 (*it)->ResourceCategory )
572 }
573 #endif
574
575
576 if( targetCamp == nullptr )
577 targetCamp= CAMPS.back();
578
579 //std::cout << "Camp::Bootstrap called on: '" << this->ResourceCategory << "', target phase: " << int(targetPhase) << std::endl;
580
581 // Initialize non-camp modules once
583 IF_ALIB_BOXING ( boxing ::bootstrap(); )
584 IF_ALIB_THREADS( threads ::bootstrap(); )
585
586 #if ALIB_FORMAT
587 Formatter::DEFAULT .InsertDerived<FormatterPythonStyle>();
588 Formatter::DEFAULT->Next.InsertDerived<FormatterJavaStyle >();
589DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
590#if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
592#endif
593DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
594 #endif
596 }
597
598 // find target camp in the list of camps
599 auto targetCampIt= CAMPS.rbegin();
600 while(targetCampIt != CAMPS.rend() &&
601 *targetCampIt != targetCamp )
602 ++targetCampIt;
603
604 ALIB_ASSERT_ERROR(targetCampIt != CAMPS.rend(), "CAMPS",
605 "Target camp given to function alib::Bootstrap() is not included in list alib::CAMPS.\n"
606 "Resource category of the target camp: ", targetCamp->ResourceCategory )
607
608
609 // loop over all phases
610 for ( int phaseIntegral= int(targetCamp->GetBootstrapState()) + 1 ;
611 phaseIntegral <= int( targetPhase ) ;
612 ++phaseIntegral )
613 {
614 BootstrapPhases actualPhase = BootstrapPhases( phaseIntegral );
615
616 // phase 1: distribute a resource pool
617 if ( actualPhase == BootstrapPhases::PrepareResources ) {
618 bool skipOne= false;
619
620 // create a resource pool?
621 if ( !targetCamp->HasPool() ) {
624 resources::LocalResourcePool* lPool= dynamic_cast<resources::LocalResourcePool*>(spPool.Get());
625
626 // \releasetask{Update resource numbers with ALIB_DEBUG_RESOURCES. Create resource reference dox for that.}
627 integer expectedSize= 108 // [ALib]
628 IF_ALIB_ALOX( + 50 )
629 IF_ALIB_APP ( + 60 ) //
630 IF_ALIB_EXPRESSIONS ( + 257 )
631 IF_ALIB_FILETREE ( + 49 ) ;
632
633 auto& hashMap= lPool->BootstrapGetInternalHashMap();
634 hashMap.BaseLoadFactor( 2.0 );
635 hashMap.MaxLoadFactor ( 5.0 );
636 hashMap.Reserve ( expectedSize, lang::ValueReference::Absolute );
637
638 targetCamp->BootstrapSetResourcePool( spPool );
639 skipOne= true;
640 }
641
642 // loop in reverse order over modules, start with this module
643 auto& actPoolSP = targetCamp->GetResourcePoolSP();
644 for(auto campIt= targetCampIt ; campIt != CAMPS.rend() ; ++campIt ) {
645 if ( skipOne ) { skipOne= false; continue; }
646
647 // if a different resources object is set, then use that one from now on
648 if( (*campIt)->GetResourcePoolSP() != nullptr
649 && (*campIt)->GetResourcePoolSP() != actPoolSP )
650 {
651 actPoolSP= (*campIt)->GetResourcePoolSP();
652 continue;
653 }
654
655 (*campIt)->BootstrapSetResourcePool( actPoolSP );
656
657 } // resources distribution loop
658 }
659
660 // phase 2: create and distribute a configuration
661 else if ( actualPhase == BootstrapPhases::PrepareConfig) {
662 // create a configuration?
663 bool skipOne= false;
664 if ( targetCamp->GetConfig() == nullptr ) {
665 targetCamp->BootstrapSetConfig(SharedConfiguration(16u));
666 #if ALIB_DEBUG_CRITICAL_SECTIONS
667 targetCamp->GetConfig()->NodeTable().dcs.DCSName= "Camp.Config-bootstrap-created";
668 #endif
669 #if !ALIB_SINGLE_THREADED && ALIB_DEBUG
670 targetCamp->GetConfig().GetLock().Dbg.Name= "Camp.Config.Lock-bootstrap-created";
671 #endif
672 skipOne= true;
673 }
674
675 // loop in reverse order over modules, start with this module
676 SharedConfiguration* actConfig= &targetCamp->GetConfig();
677 for(auto moduleIt= targetCampIt ; moduleIt != CAMPS.rend() ; ++moduleIt ) {
678 if ( skipOne ) { skipOne= false; continue; }
679
680 // if a different config object is set, then use that one from now on
681 if( (*moduleIt)->GetConfig() != nullptr && (*moduleIt)->GetConfig() != *actConfig)
682 actConfig = &(*moduleIt)->GetConfig();
683 else
684 (*moduleIt)->BootstrapSetConfig( *actConfig );
685
686 } // resources distribution loop
687 }
688
689 // initialize modules on this phase
690 ALIB_DBG( bool foundThisModuleInList = false; )
691 for ( auto* camp : CAMPS ) {
692 // bootstrap camp
693 if(int(camp->GetBootstrapState()) >= int(actualPhase ) )
694 continue;
695
696 //std::cout << "Camp::Bootstrap '" << module->ResourceCategory << "', phase: " << int(actualPhase) << std::endl;
697
698 ALIB_ASSERT_ERROR( int(camp->GetBootstrapState()) == phaseIntegral - 1, "CAMPS",
699 "With this invocation of Bootstrap() a camp skips a bootstrap phase.\n"
700 "Resource category of the target camp: ", camp->ResourceCategory )
701 camp->BootstrapSetPhase(actualPhase);
702 camp->Bootstrap();
703
704 // stop if this is us
705 if (camp == targetCamp ) {
706 ALIB_DBG( foundThisModuleInList = true );
707 break;
708 } }
709 ALIB_ASSERT_ERROR( foundThisModuleInList, "CAMPS",
710 "The target camp of function Bootstrap is not included in list alib::CAMPS "
711 "or was already bootstrapped for this phase!\n"
712 "Resource category of the target camp: ", targetCamp->ResourceCategory )
713 }
714
715 // Are all camps finalized?
716 if ( targetPhase == BootstrapPhases::Final && targetCamp == CAMPS.back() ) {
717 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
718 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= &monomem::GLOBAL_ALLOCATOR_LOCK;
719 monomem::GLOBAL_ALLOCATOR_LOCK.Dbg.Name= "GlobalAllocator";
720 #endif
721} }
722
723void Shutdown( ShutdownPhases targetPhase, camp::Camp* targetCamp ) {
724 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
725 monomem::GLOBAL_ALLOCATOR.DbgCriticalSectionsPH.Get()->DCSLock= nullptr;
726 Formatter::DEFAULT->DCSLock= nullptr;
727 #endif
728
729 ALIB_ASSERT_ERROR( CAMPS.IsNotEmpty(), "CAMPS",
730 "Empty camp list on shutdown. Shutdown invoked twice?" )
731 if( targetCamp == nullptr )
732 targetCamp= CAMPS.front();
733
734 //std::cout << "Camp::Shutdown called on'" << targetCamp->ResourceCategory << "', target phase: " << int(targetPhase) << std::endl;
735
736 // find target camp in the list of camps
737 auto targetCampIt= CAMPS.begin();
738 while( targetCampIt != CAMPS.end()
739 && *targetCampIt != targetCamp )
740 ++targetCampIt;
741 ALIB_ASSERT_ERROR(targetCampIt != CAMPS.end(), "CAMPS",
742 "Target camp given to function alib::Shutdown() is not included in list alib::CAMPS.\n"
743 "Resource category of the target camp: ", targetCamp->ResourceCategory )
744
745
746 ALIB_DBG( bool foundThisModuleInList= false );
747 // loop over all (both) termination levels
748 for( int phaseIntegral= int( ShutdownPhases::Announce )
749 ; phaseIntegral<= int( targetPhase )
750 ; ++phaseIntegral )
751 {
752 ShutdownPhases actualPhase = ShutdownPhases( phaseIntegral );
753
754 // shutdown in reverse order
755 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt ) {
756 ALIB_ASSERT_ERROR( int(( *campIt )->GetBootstrapState()) < 0
757 || int(( *campIt )->GetBootstrapState()) == int(BootstrapPhases::Final),
758 "CAMPS", "Trying to terminate a not (fully) initialized module. "
759 "Module Name (resource category): ", targetCamp->ResourceCategory )
760
761 // shutdown module
762 if (int(( *campIt )->GetBootstrapState()) > -int(actualPhase) ) {
763 //std::cout << "Camp::Shutdown '" << (*campIt)->ResourceCategory << "', phase: " << int(actualPhase) << std::endl;
764
765 ALIB_ASSERT_ERROR( ( int(( *campIt )->GetBootstrapState()) == 3 && phaseIntegral == 1 )
766 || ( int(( *campIt )->GetBootstrapState()) == -1 && phaseIntegral == 2 ),
767 "CAMPS", "With this invocation of Bootstrap(), a camp skips a bootstrap phase \n"
768 "Resource category of the target camp: ", ( *campIt )->ResourceCategory )
769
770
771 ( *campIt )->Shutdown(actualPhase );
772 ( *campIt )->BootstrapSetPhase(BootstrapPhases(-int(actualPhase )) );
773
774 ALIB_DBG( if(( *campIt ) == targetCamp )
775 foundThisModuleInList= true; )
776 }
777
778 if(( *campIt ) == targetCamp )
779 break;
780 } }
781 ALIB_ASSERT_ERROR( foundThisModuleInList, "CAMPS",
782 "The target camp of function Shutdown is not included in list alib::CAMPS "
783 "or was already shutdown for this phase!\n"
784 "Resource category of the target camp: ", targetCamp->ResourceCategory )
785
786
787 #if ALIB_DEBUG_CRITICAL_SECTIONS
788 // deactivate assertions for non-locked access to configuration
789 if( targetPhase == ShutdownPhases::Announce)
790 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt )
791 (*campIt)->GetConfig()->NodeTable().dcs.DCSLock= nullptr;
792 #endif
793
794 // delete resources/config
795 if( targetPhase == ShutdownPhases::Destruct)
796 for(auto campIt= CAMPS.rbegin() ; campIt != CAMPS.rend() ; ++campIt ) {
797 ( *campIt )->BootstrapSetResourcePool(nullptr);
798 ( *campIt )->BootstrapSetConfig(nullptr);
799
800 if(( *campIt ) == targetCamp )
801 break;
802 }
803
804 if( targetPhase == ShutdownPhases::Destruct
805 && targetCamp == CAMPS.front() )
806 {
807 IF_ALIB_THREADS( threads ::shutdown(); )
809 IF_ALIB_BOXING( boxing ::shutdown(); )
810 IF_ALIB_SINGLETONS( singletons ::shutdown(); )
811
812 ALIB_ASSERT_WARNING( Formatter::DEFAULT.UseCount() == 1, "ALIB",
813 "DefaultFormatter still shared more than once: ", Formatter::DEFAULT.UseCount() )
814 Formatter::DEFAULT= nullptr;
815
816 CAMPS.Reset();
818} }
819
820#endif // ALIB_CAMP
821} // namespace [alib]
822
823
824
825# include "ALib.Lang.CIMethods.H"
#define IF_ALIB_APP(...)
#define IF_ALIB_BOXING(...)
#define ALIB_REVISION
#define IF_ALIB_THREADS(...)
#define A_CHAR(STR)
#define ALIB_VERSION
#define IF_ALIB_ALOX(...)
#define IF_ALIB_SINGLETONS(...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define IF_ALIB_ENUMRECORDS(...)
#define ALIB_FORMAT
#define ALIB_DBG(...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define IF_ALIB_FILETREE(...)
#define IF_ALIB_EXPRESSIONS(...)
#define ALIB_COMPILATION_FLAGS
@ Huffman
Huffman encoding (byte based).
Definition ac.hpp:249
@ Incremental
Only distances of the values are written.
Definition ac.hpp:246
@ ALL
All compression methods selected.
Definition ac.hpp:229
@ Sparse
Writes '1' if next value is equal to previous, '0' plus next value otherwise.
Definition ac.hpp:240
@ MinMax
Stores the differences between the minimum and maximum value found.
Definition ac.hpp:237
@ VerySparse
Writes the number of following equal or non equal values.
Definition ac.hpp:243
@ NONE
No compression method selected.
Definition ac.hpp:226
BootstrapPhases GetBootstrapState()
Definition camp.hpp:158
SharedConfiguration & GetConfig()
Definition camp.hpp:195
void BootstrapSetConfig(const SharedConfiguration &pConfig)
Definition camp.hpp:186
void BootstrapSetResourcePool(const SPResourcePool &pResourcePool)
Definition camp.hpp:212
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 threads::RecursiveLock DEFAULT_LOCK
static SPFormatter DEFAULT
lang::Placeholder< lang::DbgCriticalSections > DbgCriticalSectionsPH
TLock & GetLock() const noexcept
SPResourcePool & GetResourcePoolSP()
SharedPtr< resources::ResourcePool, MonoAllocator > SPResourcePool
@ Running
The thread's #".Run" method is currently processed.
Definition thread.hpp:138
@ Started
Method #".Start" was invoked but not running, yet.
Definition thread.hpp:137
@ Terminated
The thread is terminated.
Definition thread.hpp:141
void Bootstrap(camp::Camp &camp, const NString &name, character innerDelim=',', character outerDelim=',')
Definition camp.hpp:263
@ 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.
@ Yes
Denotes recursion.
@ No
Denotes non-recursive.
@ Center
Chooses centered alignment.
@ Right
Chooses right alignment.
@ Left
Chooses left alignment.
@ WindowsOS
WindowsOS style line-feeds "\r\n".
@ Platform
Platform specific. Equals to either 'Unix' or 'WindowsOS'.
@ None
No line-feeds, not specified, etc.
@ Unix
Unix-style line-feeds "\n".
@ Ignore
Same as 'None'.
@ 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.
@ Yes
Create if something does not exist.
@ Keep
Chooses not no clear existing data.
@ Clear
Chooses to clear existing data.
@ Yes
Create default values.
@ 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.
@ Relative
Referring to a relative value.
@ 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).
RecursiveLock GLOBAL_ALLOCATOR_LOCK
TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
void bootstrap()
Definition thread.cpp:76
Definition alox.cpp:14
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
format::Formatter Formatter
Type alias in namespace #"%alib".
filetree::FilesCamp FILETREE
The singleton instance of ALib Camp class #"FilesCamp".
ListMA< camp::Camp * > CAMPS
BootstrapPhases
Definition camp.hpp:14
@ Final
The final initialization phase. Here, camps are initializing their custom setup.
Definition camp.hpp:34
void BootstrapAddDefaultCamps()
void Bootstrap(BootstrapPhases targetPhase, camp::Camp *targetCamp, int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
CompilationFlagMeaningsEntry COMPILATION_FLAG_MEANINGS[40]
Definition bootstrap.cpp:12
containers::List< T, MonoAllocator, TRecycling > ListMA
Type alias in namespace #"%alib".
Definition list.hpp:689
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class #"ALoxCamp".
Definition aloxcamp.cpp:5
ShutdownPhases
Termination levels usable with #"alib_mod_bs_camps;Bootstrapping ALib Camps".
Definition camp.hpp:40
@ Destruct
The main phase of termination that destructs everything.
Definition camp.hpp:44
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
TCompilationFlags COMPILATION_FLAGS
Definition bootstrap.cpp:10
int VERSION
Definition bootstrap.cpp:8
variables::TSharedConfiguration< SharedLock > SharedConfiguration
Type alias in namespace #"%alib".
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class #"ExpressionsCamp".
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class #"Basecamp".
Definition basecamp.cpp:2
void Shutdown()
bool NonCampModulesInitialized
app::AppCamp APP
The singleton instance of the camp class used by class #"App".
Definition appcamp.cpp:1
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace #"%alib".
format::FormatterJavaStyle FormatterJavaStyle
Type alias in namespace #"%alib".
void AssertALibVersionAndFlags(int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
Definition bootstrap.cpp:60
unsigned char REVISION
Definition bootstrap.cpp:9
This is a struct composing an entry in #"COMPILATION_FLAG_MEANINGS".
Definition bootstrap.hpp:27
unsigned char bits[5]
The Flags.
Definition bootstrap.hpp:23