ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
basecamp.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !DOXYGEN
17# include "alib/time/time.hpp"
31# if ALIB_THREADS
33# endif
34# if ALIB_THREADMODEL
36# endif
37# if ALIB_CONFIGURATION
40# endif
41# if ALIB_ALOX
42# include "alib/alox/aloxcamp.hpp"
43# endif
44# if ALIB_CLI
45# include "alib/cli/clicamp.hpp"
46# endif
47# if ALIB_EXPRESSIONS
49# endif
50# if ALIB_FILES
52# endif
53# if ALIB_BITBUFFER
55# endif
59#endif // !DOXYGEN
60
61using namespace alib;
62
63
68
69
71namespace lang {
72namespace format { NumberFormat* BYTESIZE_NUMBER_FORMAT= nullptr; }
73
74/// This is the reference documentation of sub-namespace \b system of module \alib_basecamp.
75namespace system {}
76
77// #################################################################################################
78// Replacement method for ALib Essential Reports
79// #################################################################################################
80#if ALIB_DEBUG
81#if !DOXYGEN
82namespace {
83#endif
85/// This method is installed with \alib{lang::DBG_SIMPLE_ALIB_MSG_PLUGIN} in method
86/// \alib{lang;Camp::bootstrap}.
87///
88/// The message strings are simply passed to the default \alib{lang;Report}.
89/// This way, the essential assert, error and message macros are using the \alib report system
90/// at the moment that the \alib_basecamp_nl is included in the \alibdist.
91///
92/// @param ci Information about the scope of invocation.
93/// @param type The type of message. See \alib{lang;Message}.
94/// @param topic The topic of message.
95/// @param qtyMsgs The number of messages in \p{msgs}.
96/// @param msgs A list of strings (this is all that the essential versions of \alib reporting
97/// macros provide).
98void debugReportPlugin(const CallerInfo& ci, int type, const char* topic,
99 int qtyMsgs, const nchar** msgs)
100{
101 LocalAllocator1K allocator;
102 Message message( ci, allocator, Report::Types(type), topic );
103 for (int i= 0; i< qtyMsgs; ++i )
104 message.Add( msgs[i] );
105 Report::GetDefault().DoReport( message );
106}
108
109#if !DOXYGEN
110} // anonymous namespace
111#endif
112#endif // ALIB_DEBUG
113
114
115/// This is the reference documentation of sub-namespace \b format of module \alib_basecamp.
116///
117/// Extensive documentation for this namespace is provided with chapter
118/// \ref alib_basecamp_format "4. Namespace alib::lang::format" of the Programmer's Manual of that module.
119namespace format {}
120
121
122#if !DOXYGEN
123namespace
124{
126 String months[12];
127 String days[7];
128
129 enum Units
130 {
131 TS_ZERO,
132 DayPlural,
133 DaySingular,
134 HourPlural,
135 HourSingular,
136 MinPlural,
137 MinSingular,
138 SecPlural,
139 SecSingular,
140 MlSecPlural,
141 MlSecSingular,
142 McSecPlural,
143 McSecSingular,
144 NSecPlural,
145 NSecSingular, SIZE_OF_UNITS
146 };
147
148 String units[SIZE_OF_UNITS];
150} // namespace alib::lang::format[::anonymous]
151#endif // DOXYGEN
152
153namespace basecamp {
154
156: Camp( "ALIB" )
157, LocaleFound(nullptr)
158{
159 ALIB_ASSERT_ERROR( this == &BASECAMP, "BASECAMP",
160 "Instances of class BaseCamp must not be created. Use singleton alib::BASECAMP" )
161}
162
164{
166 {
167 #if ALIB_DEBUG
169 # if ALIB_THREADS
170 Formatter::DefaultLock.Dbg.Name= "DefaultFormatter";
171 # endif
172 #endif
173
174
175 #define EOS ,
176#if !ALIB_RESOURCES_OMIT_DEFAULTS
178
179
180 // CodeMarker_CommonEnums
181 "Alignment", A_CHAR("0" "," "Left" "," "1" ","
182 "1" "," "Right" "," "1" ","
183 "2" "," "Center" "," "1" ),
184
185 "Bool", A_CHAR("0" "," "False" "," "1" ","
186 "1" "," "True" "," "1" ","
187 "0" "," "0" "," "1" ","
188 "1" "," "1" "," "1" ","
189 "0" "," "No" "," "1" ","
190 "1" "," "Yes" "," "1" ","
191 "0" "," "Off" "," "2" ","
192 "1" "," "On" "," "2" ","
193 "0" "," "-" "," "1" ","
194 "1" "," "Ok" "," "2" ),
195
196 "Caching", A_CHAR("0" "," "Disabled" "," "1" ","
197 "1" "," "Enabled" "," "1" ","
198 "1" "," "Auto" "," "1" ),
199
200 "Case", A_CHAR("0" "," "Sensitive" "," "1" ","
201 "1" "," "Ignore" "," "1" ),
202
203 "ContainerOp", A_CHAR("0" "," "Insert" "," "1" ","
204 "1" "," "Remove" "," "1" ","
205 "3" "," "GetCreate" "," "4" ","
206 "2" "," "Get" "," "1" ","
207 "4" "," "Create" "," "1" ),
208
209 // CreateDefaults: using Bool
210 // CreateIfNotExists: using Bool
211
212 "CurrentData", A_CHAR("0" "," "Keep" "," "1" ","
213 "1" "," "Clear" "," "1" ),
214
215 "Inclusion", A_CHAR("0" "," "Include" "," "1" ","
216 "1" "," "Exclude" "," "1" ),
217
218 "Initialization", A_CHAR("0" "," "Suppress" "," "1" ","
219 "1" "," "Default" "," "1" ","
220 "2" "," "Nulled" "," "1" ","
221 "0" "," "None" "," "2" ","
222 "1" "," "Initialize" "," "1" ","
223 "2" "," "Zero" "," "1" ),
224
225 "Phase", A_CHAR("0" "," "Begin" "," "1" ","
226 "1" "," "End" "," "1" ),
227
228 "Propagation", A_CHAR("0" "," "Omit" "," "1" ","
229 "1" "," "ToDescendants" "," "1" ),
230
231 "Reach", A_CHAR("0" "," "Global" "," "1" ","
232 "1" "," "Local" "," "1" ),
233
234 // Recursive: using Bool
235
236 "Responsibility", A_CHAR("0" "," "KeepWithSender" "," "1" ","
237 "1" "," "Transfer" "," "1" ),
238
239 "Safeness", A_CHAR("0" "," "Safe" "," "1" ","
240 "1" "," "Unsafe" "," "1" ),
241
242 "Side", A_CHAR("0" "," "Left" "," "1" ","
243 "1" "," "Right" "," "1" ),
244
245 "SortOrder", A_CHAR("0" "," "Ascending" "," "1" ","
246 "1" "," "Descending" "," "1" ),
247
248 "SourceData", A_CHAR("0" "," "Copy" "," "1" ","
249 "1" "," "Move" "," "1" ),
250
251 "Switch", A_CHAR("0" "," "Off" "," "2" ","
252 "1" "," "On" "," "2" ),
253
254 "Timezone", A_CHAR("0" "," "Local" "," "1" ","
255 "1" "," "UTC" "," "1" ),
256
257 "Timing", A_CHAR("0" "," "Async" "," "1" ","
258 "1" "," "Sync" "," "1" ","
259 "0" "," "Asynchronous" "," "1" ","
260 "1" "," "Synchronous" "," "1" ","
261 "1" "," "Synchronized" "," "1" ),
262
263 "ValueReference", A_CHAR("0" "," "Absolute" "," "1" ","
264 "1" "," "Relative" "," "1" ),
265
266 "Whitespaces", A_CHAR("0" "," "Trim" "," "1" ","
267 "1" "," "Keep" "," "1" ),
268
269
270 #if ALIB_THREADS
271 "TSts", A_CHAR( "0" "," "Unstarted" "," "1" ","
272 "1" "," "Started" "," "3" ","
273 "2" "," "Running" "," "1" ","
274 "3" "," "Done" "," "3" ","
275 "4" "," "Terminated" "," "1" ),
276
278 "TMDWP", A_CHAR( "0" "," "Lowest" "," "4" ","
279 "500" "," "DeferredDeletion" "," "1" ","
280 "1000" "," "Low" "," "1" ","
281 "2000" "," "Standard" "," "1" ","
282 "4000" "," "Highest" "," "5" ","
283 "3000" "," "High" "," "1" ),
284 #endif
285 #endif
286
287
288
290 // variables
291DOX_MARKER([DOX_CONFIG_DECLARATION6])
292"Var0", A_CHAR("1|ALIB/LOCALE|" "S" ),
293"Var1", A_CHAR("2|ALIB/WAIT_FOR_KEY_PRESS|" "B" ),
294"Var2", A_CHAR("3|ALIB/HAS_CONSOLE_WINDOW|" "B" ),
295
296"Var_C1", A_CHAR("Defines the locale of the application. If empty or not set, the system's locale is used.\n"
297 "If set, a UTF8 local should be used, for example 'us_US.UTF-8' or 'de_DE.UTF-8'" ),
298"Var_C2", A_CHAR("If true, the process waits for a key stroke on termination. If empty, under Windows" "\n"
299 "behavior is detected, under other OSes, defaults to false." ),
300"Var_C3", A_CHAR("Boolean value that denotes what its name indicates. If empty, under Windows value is " "\n"
301 "detected, under other OSes, defaults to true." ),
302DOX_MARKER([DOX_CONFIG_DECLARATION6])
303
304#endif // ALIB_CONFIGURATION
305
306 // INI-File comment for section ALIB
307 "INI_CMT_ALIB", A_CHAR("@>'/// '@HL-General ALib library settings.\n@HL-"),
308
309 // Exit message when waiting for key-press requested with variable WAIT_FOR_KEY_PRESS
310 "EXIT_MSG" , A_CHAR( "ALIB: Press 'Enter' to exit..." ),
311
313 "ACAlgos" , A_CHAR( "0" ",NONE" "," "1" ","
314 "31" ",ALL" "," "1" ","
315 "1" ",Uncompressed" "," "1" ","
316 "2" ",MinMax" "," "1" ","
317 "4" ",Sparse" "," "1" ","
318 "8" ",VerySparse" "," "1" ","
319 "16" ",Incremental" "," "1" ","
320 "32" ",Huffman" "," "1" ),
321 #endif
322
323 // Calendar
324 "Months" , A_CHAR("January,February,March,April,May,June,July,August,September,October,November,December")
325 , "Days" , A_CHAR("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,") EOS
326
327 "DurUnts" , A_CHAR("zero time" "," // 0 TS_ZERO
328 " days" "," // 1 DayP
329 " day" "," // 2 DayS
330 " hours" "," // 3 HourP
331 " hour" "," // 4 HourS
332 " minutes" "," // 5 MinP
333 " minute" "," // 6 MinS
334 " seconds" "," // 7 SecP
335 " second" "," // 8 SecS
336 " ms" "," // 9 MlSecP
337 " ms" "," // 10 MlSecS
338 " \u00B5s" "," // 11 McSecP
339 " \u00B5s" "," // 12 McSecS
340 " ns" "," // 13 NSecP
341 " ns" ), // 14 NSecS
342
343 "FMTDT" , A_CHAR( "yyyy-MM-dd HH:mm:ss"), // default format string for DateTime values used by FFormat_DateTime()
344 "FMTCI" , A_CHAR( "[@ sf:sl from ''ya'' by ''ta'']"), // default format string for CallerInfo values used by FFormat_CallerInfo()
345 "FMTCINT", A_CHAR( "<None>"), // format output if CallerInfo has no thread set
346 "FMTCINY", A_CHAR( "<None>"), // format output if CallerInfo originates from static method or namespace function
347 "FMTCINR", A_CHAR( "<Null>"), // format output if CallerInfo originates from static method or namespace function
348
349 // Exceptions
350 "E<", A_CHAR("system::"),
351 "E", A_CHAR("0,OK" ",NON" ) EOS
352
353 // Enums
354 "SystemFolders", A_CHAR("0,Root" ",1,"
355 "1,Current" ",1,"
356 "3,HomeConfig" ",5,"
357 "2,Home" ",1,"
358 "4,Module" ",1,"
359 "5,Temp" ",1,"
360 "6,VarTemp" ",1" ) EOS
361
362 // System errors
363 #if defined (__GLIBC__) || defined(__APPLE__)
364 "SE<" , A_CHAR("glibc::" ),
365 "OSERR" , A_CHAR("GNU-C Library call returned {!Q} ({})."),
366 "UknSE" , A_CHAR("GNU-C Library call returned ({}). (Unknown error number)"),
367 #elif defined(_WIN32)
368 "SE<" , A_CHAR("WindowsOS::" ),
369 "OSERR" , A_CHAR("Windows system call returned {!Q} ({})."),
370 "UknSE" , A_CHAR("Windows system call returned ({}). (Unknown error number)"),
371 #endif
372 "SE",
373
374 A_CHAR("-1" "," "UNKNOWN" "," "UknSE" "," )
375 A_CHAR("0" "," "OK" "," "," )
376
377#if defined (__GLIBC__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
378 A_CHAR("1" "," "EPERM" "," "OSERR" ","
379 "2" "," "ENOENT" "," "OSERR" ","
380 "3" "," "ESRCH" "," "OSERR" ","
381 "4" "," "EINTR" "," "OSERR" ","
382 "5" "," "EIO" "," "OSERR" ","
383 "6" "," "ENXIO" "," "OSERR" ","
384 "7" "," "E2BIG" "," "OSERR" ","
385 "8" "," "ENOEXEC" "," "OSERR" ","
386 "9" "," "EBADF" "," "OSERR" ","
387 "10" "," "ECHILD" "," "OSERR" ","
388 "11" "," "EAGAIN" "," "OSERR" ","
389 "12" "," "ENOMEM" "," "OSERR" ","
390 "13" "," "EACCES" "," "OSERR" ","
391 "14" "," "EFAULT" "," "OSERR" ","
392 "15" "," "ENOTBLK" "," "OSERR" ","
393 "16" "," "EBUSY" "," "OSERR" ","
394 "17" "," "EEXIST" "," "OSERR" ","
395 "18" "," "EXDEV" "," "OSERR" ","
396 "19" "," "ENODEV" "," "OSERR" ","
397 "20" "," "ENOTDIR" "," "OSERR" ","
398 "21" "," "EISDIR" "," "OSERR" ","
399 "22" "," "EINVAL" "," "OSERR" ","
400 "23" "," "ENFILE" "," "OSERR" ","
401 "24" "," "EMFILE" "," "OSERR" ","
402 "25" "," "ENOTTY" "," "OSERR" ","
403 "26" "," "ETXTBSY" "," "OSERR" ","
404 "27" "," "EFBIG" "," "OSERR" ","
405 "28" "," "ENOSPC" "," "OSERR" ","
406 "29" "," "ESPIPE" "," "OSERR" ","
407 "30" "," "EROFS" "," "OSERR" ","
408 "31" "," "EMLINK" "," "OSERR" ","
409 "32" "," "EPIPE" "," "OSERR" ","
410 "33" "," "EDOM" "," "OSERR" ","
411 "34" "," "ERANGE" "," "OSERR" ","
412 "35" "," "EDEADLK" "," "OSERR" ","
413 "36" "," "ENAMETOOLONG" "," "OSERR" ","
414 "37" "," "ENOLCK" "," "OSERR" ","
415 "38" "," "ENOSYS" "," "OSERR" ","
416 "39" "," "ENOTEMPTY" "," "OSERR" ","
417 "40" "," "ELOOP" "," "OSERR" ","
418 "42" "," "ENOMSG" "," "OSERR" ","
419 "43" "," "EIDRM" "," "OSERR" "," )
420#if !defined(__APPLE__)
421 A_CHAR("44" "," "ECHRNG" "," "OSERR" ","
422 "45" "," "EL2NSYNC" "," "OSERR" ","
423 "46" "," "EL3HLT" "," "OSERR" ","
424 "47" "," "EL3RST" "," "OSERR" ","
425 "48" "," "ELNRNG" "," "OSERR" ","
426 "49" "," "EUNATCH" "," "OSERR" ","
427 "50" "," "ENOCSI" "," "OSERR" ","
428 "51" "," "EL2HLT" "," "OSERR" ","
429 "52" "," "EBADE" "," "OSERR" ","
430 "53" "," "EBADR" "," "OSERR" ","
431 "54" "," "EXFULL" "," "OSERR" ","
432 "55" "," "ENOANO" "," "OSERR" ","
433 "56" "," "EBADRQC" "," "OSERR" ","
434 "57" "," "EBADSLT" "," "OSERR" ","
435 "59" "," "EBFONT" "," "OSERR" ",")
436#endif
437 A_CHAR("60" "," "ENOSTR" "," "OSERR" ","
438 "61" "," "ENODATA" "," "OSERR" ","
439 "62" "," "ETIME" "," "OSERR" ","
440 "63" "," "ENOSR" "," "OSERR" ",")
441#if !defined(__APPLE__)
442 A_CHAR("64" "," "ENONET" "," "OSERR" ","
443 "65" "," "ENOPKG" "," "OSERR" ",")
444#endif
445 A_CHAR("66" "," "EREMOTE" "," "OSERR" ","
446 "67" "," "ENOLINK" "," "OSERR" ",")
447#if !defined(__APPLE__)
448 A_CHAR("68" "," "EADV" "," "OSERR" ","
449 "69" "," "ESRMNT" "," "OSERR" ","
450 "70" "," "ECOMM" "," "OSERR" ",")
451#endif
452 A_CHAR("71" "," "EPROTO" "," "OSERR" ","
453 "72" "," "EMULTIHOP" "," "OSERR" ",")
454#if !defined(__APPLE__)
455 A_CHAR("73" "," "EDOTDOT" "," "OSERR" ",")
456#endif
457 A_CHAR("74" "," "EBADMSG" "," "OSERR" ","
458 "75" "," "EOVERFLOW" "," "OSERR" ",")
459#if !defined(__APPLE__)
460 A_CHAR("76" "," "ENOTUNIQ" "," "OSERR" ","
461 "77" "," "EBADFD" "," "OSERR" ","
462 "78" "," "EREMCHG" "," "OSERR" ","
463 "79" "," "ELIBACC" "," "OSERR" ","
464 "80" "," "ELIBBAD" "," "OSERR" ","
465 "81" "," "ELIBSCN" "," "OSERR" ","
466 "82" "," "ELIBMAX" "," "OSERR" ","
467 "83" "," "ELIBEXEC" "," "OSERR" ",")
468#endif
469 A_CHAR("84" "," "EILSEQ" "," "OSERR" ",")
470#if !defined(__APPLE__)
471 A_CHAR("85" "," "ERESTART" "," "OSERR" ","
472 "86" "," "ESTRPIPE" "," "OSERR" ",")
473#endif
474 A_CHAR("87" "," "EUSERS" "," "OSERR" ","
475 "88" "," "ENOTSOCK" "," "OSERR" ","
476 "89" "," "EDESTADDRREQ" "," "OSERR" ","
477 "90" "," "EMSGSIZE" "," "OSERR" ","
478 "91" "," "EPROTOTYPE" "," "OSERR" ","
479 "92" "," "ENOPROTOOPT" "," "OSERR" ","
480 "93" "," "EPROTONOSUPPORT" "," "OSERR" ","
481 "94" "," "ESOCKTNOSUPPORT" "," "OSERR" ","
482 "95" "," "EOPNOTSUPP" "," "OSERR" ","
483 "96" "," "EPFNOSUPPORT" "," "OSERR" ","
484 "97" "," "EAFNOSUPPORT" "," "OSERR" ","
485 "98" "," "EADDRINUSE" "," "OSERR" ","
486 "99" "," "EADDRNOTAVAIL" "," "OSERR" ","
487 "100" "," "ENETDOWN" "," "OSERR" ","
488 "101" "," "ENETUNREACH" "," "OSERR" ","
489 "102" "," "ENETRESET" "," "OSERR" ","
490 "103" "," "ECONNABORTED" "," "OSERR" ","
491 "104" "," "ECONNRESET" "," "OSERR" ","
492 "105" "," "ENOBUFS" "," "OSERR" ","
493 "106" "," "EISCONN" "," "OSERR" ","
494 "107" "," "ENOTCONN" "," "OSERR" ","
495 "108" "," "ESHUTDOWN" "," "OSERR" ","
496 "109" "," "ETOOMANYREFS" "," "OSERR" ","
497 "110" "," "ETIMEDOUT" "," "OSERR" ","
498 "111" "," "ECONNREFUSED" "," "OSERR" ","
499 "112" "," "EHOSTDOWN" "," "OSERR" ","
500 "113" "," "EHOSTUNREACH" "," "OSERR" ","
501 "114" "," "EALREADY" "," "OSERR" ","
502 "115" "," "EINPROGRESS" "," "OSERR" ","
503 "116" "," "ESTALE" "," "OSERR" "," )
504#if !defined(__APPLE__)
505 A_CHAR("117" "," "EUCLEAN" "," "OSERR" ","
506 "118" "," "ENOTNAM" "," "OSERR" ","
507 "119" "," "ENAVAIL" "," "OSERR" ","
508 "120" "," "EISNAM" "," "OSERR" ","
509 "121" "," "EREMOTEIO" "," "OSERR" "," )
510#endif
511 A_CHAR("122" "," "EDQUOT" "," "OSERR" "," )
512#if !defined(__APPLE__)
513 A_CHAR("123" "," "ENOMEDIUM" "," "OSERR" ","
514 "124" "," "EMEDIUMTYPE" "," "OSERR" "," )
515#endif
516 A_CHAR("125" "," "ECANCELED" "," "OSERR" "," )
517#if !defined(__APPLE__)
518 A_CHAR("126" "," "ENOKEY" "," "OSERR" ","
519 "127" "," "EKEYEXPIRED" "," "OSERR" ","
520 "128" "," "EKEYREVOKED" "," "OSERR" ","
521 "129" "," "EKEYREJECTED" "," "OSERR" "," )
522#endif
523 A_CHAR("130" "," "EOWNERDEAD" "," "OSERR" ","
524 "131" "," "ENOTRECOVERABLE" "," "OSERR" )
525#if !defined(__APPLE__)
526 A_CHAR( ","
527 "132" "," "ERFKILL" "," "OSERR" ","
528 "133" "," "EHWPOISON" "," "OSERR" )
529#endif
530 EOS
531
532#elif defined(_WIN32)
533 A_CHAR( "1" "," "EPERM" "," "OSERR" ","
534 "2" "," "ENOENT" "," "OSERR" ","
535 "3" "," "ESRCH" "," "OSERR" ","
536 "4" "," "EINTR" "," "OSERR" ","
537 "5" "," "EIO" "," "OSERR" ","
538 "6" "," "ENXIO" "," "OSERR" ","
539 "7" "," "E2BIG" "," "OSERR" ","
540 "8" "," "ENOEXEC" "," "OSERR" ","
541 "9" "," "EBADF" "," "OSERR" ","
542 "10" "," "ECHILD" "," "OSERR" ","
543 "11" "," "EAGAIN" "," "OSERR" ","
544 "12" "," "ENOMEM" "," "OSERR" ","
545 "13" "," "EACCES" "," "OSERR" ","
546 "14" "," "EFAULT" "," "OSERR" ","
547 "16" "," "EBUSY" "," "OSERR" ","
548 "17" "," "EEXIST" "," "OSERR" ","
549 "18" "," "EXDEV" "," "OSERR" ","
550 "19" "," "ENODEV" "," "OSERR" ","
551 "20" "," "ENOTDIR" "," "OSERR" ","
552 "21" "," "EISDIR" "," "OSERR" ","
553 "23" "," "ENFILE" "," "OSERR" ","
554 "24" "," "EMFILE" "," "OSERR" ","
555 "25" "," "ENOTTY" "," "OSERR" ","
556 "27" "," "EFBIG" "," "OSERR" ","
557 "28" "," "ENOSPC" "," "OSERR" ","
558 "29" "," "ESPIPE" "," "OSERR" ","
559 "30" "," "EROFS" "," "OSERR" ","
560 "31" "," "EMLINK" "," "OSERR" ","
561 "32" "," "EPIPE" "," "OSERR" ","
562 "33" "," "EDOM" "," "OSERR" ","
563 "36" "," "EDEADLK" "," "OSERR" ","
564 "38" "," "ENAMETOOLONG" "," "OSERR" ","
565 "39" "," "ENOLCK" "," "OSERR" ","
566 "40" "," "ENOSYS" "," "OSERR" ","
567 "41" "," "ENOTEMPTY" "," "OSERR" ","
568 "22" "," "EINVAL" "," "OSERR" ","
569 "34" "," "ERANGE" "," "OSERR" ","
570 "42" "," "EILSEQ" "," "OSERR" ","
571 "80" "," "STRUNCATE" "," "OSERR" ","
572 "100" "," "EADDRINUSE" "," "OSERR" ","
573 "101" "," "EADDRNOTAVAIL" "," "OSERR" ","
574 "102" "," "EAFNOSUPPORT" "," "OSERR" ","
575 "103" "," "EALREADY" "," "OSERR" ","
576 "104" "," "EBADMSG" "," "OSERR" ","
577 "105" "," "ECANCELED" "," "OSERR" ","
578 "106" "," "ECONNABORTED" "," "OSERR" ","
579 "107" "," "ECONNREFUSED" "," "OSERR" ","
580 "108" "," "ECONNRESET" "," "OSERR" ","
581 "109" "," "EDESTADDRREQ" "," "OSERR" ","
582 "110" "," "EHOSTUNREACH" "," "OSERR" ","
583 "111" "," "EIDRM" "," "OSERR" ","
584 "112" "," "EINPROGRESS" "," "OSERR" ","
585 "113" "," "EISCONN" "," "OSERR" ","
586 "114" "," "ELOOP" "," "OSERR" ","
587 "115" "," "EMSGSIZE" "," "OSERR" ","
588 "116" "," "ENETDOWN" "," "OSERR" ","
589 "117" "," "ENETRESET" "," "OSERR" ","
590 "118" "," "ENETUNREACH" "," "OSERR" ","
591 "119" "," "ENOBUFS" "," "OSERR" ","
592 "120" "," "ENODATA" "," "OSERR" ","
593 "121" "," "ENOLINK" "," "OSERR" ","
594 "122" "," "ENOMSG" "," "OSERR" ","
595 "123" "," "ENOPROTOOPT" "," "OSERR" ","
596 "124" "," "ENOSR" "," "OSERR" ","
597 "125" "," "ENOSTR" "," "OSERR" ","
598 "126" "," "ENOTCONN" "," "OSERR" ","
599 "127" "," "ENOTRECOVERABLE" "," "OSERR" ","
600 "128" "," "ENOTSOCK" "," "OSERR" ","
601 "129" "," "ENOTSUP" "," "OSERR" ","
602 "130" "," "EOPNOTSUPP" "," "OSERR" ","
603 "131" "," "EOTHER" "," "OSERR" ","
604 "132" "," "EOVERFLOW" "," "OSERR" ","
605 "133" "," "EOWNERDEAD" "," "OSERR" ","
606 "134" "," "EPROTO" "," "OSERR" ","
607 "135" "," "EPROTONOSUPPORT" "," "OSERR" ","
608 "136" "," "EPROTOTYPE" "," "OSERR" ","
609 "137" "," "ETIME" "," "OSERR" ","
610 "138" "," "ETIMEDOUT" "," "OSERR" ","
611 "139" "," "ETXTBSY" "," "OSERR" ","
612 "140" "," "EWOULDBLOCK" "," "OSERR" ) EOS
613#endif // #elif defined(_WIN32)
614
615// ----------------------------------- system/message ------------------------------------
616 "REPE<" , A_CHAR("lang::") ,
617 "REPE" , A_CHAR("1,ErrorWritingReport,REPED1") ,
618
619 "REPED1", A_CHAR("Error writing ALib report."),
620
621 "ExcFmtExc", A_CHAR("\nAn exception occurred while formatting another (!) exception:\n" ),
622 "RepFmtExc", A_CHAR("\nAn exception occurred while formatting an ALib report (!):\n" ),
623
624// ----------------------------------- system/format ------------------------------------
625 "FE<", A_CHAR("format::"),
626
627 "PHT", A_CHAR( "0,NotGiven" ",1,"
628 "1,String" ",1,"
629 "2,Character" ",1,"
630 "3,IntBase10" ",6,"
631 "4,IntBinary" ",6,"
632 "5,IntOctal" ",6,"
633 "6,IntHex" ",6,"
634 "7,Float" ",1,"
635 "8,Bool" ",1,"
636 "9,HashCode" ",1,"
637 "10,Fill" ",4" ) ,
638
639
640// general formatter errors
641
642 "FE0" , A_CHAR( "11,ArgumentIndexIs0" ",FMG11" ),
643 "FE1" , A_CHAR( "12,ArgumentIndexOutOfBounds" ",FMG12" ),
644 "FE2" , A_CHAR( "13,IncompatibleTypeCode" ",FMG13" ),
645
646 // Formatter Python Style
647 "FE3" , A_CHAR( "101,MissingClosingBracket" ",FPS101" ),
648 //...
649 //...
650 "FE4" , A_CHAR( "102,MissingPrecisionValuePS" ",FPS102" ),
651 "FE5" , A_CHAR( "103,DuplicateTypeCode" ",FPS103" ),
652 "FE6" , A_CHAR( "104,UnknownTypeCode" ",FPS104" ),
653 "FE7" , A_CHAR( "105,ExclamationMarkExpected" ",FPS105" ),
654 "FE8" , A_CHAR( "106,UnknownConversionPS" ",FPS106" ),
655 "FE9" , A_CHAR( "107,PrecisionSpecificationWithInteger" ",FPS107" ),
656 "FE10", A_CHAR( "108,MissingReplacementStrings" ",FPS108" ),
657
658 // Formatter Java Style
659 "FE11" , A_CHAR( "201,NegativeValuesInBracketsNotSupported" ",FJS101" ),
660 "FE12" , A_CHAR( "202,MissingPrecisionValueJS" ",FJS102" ),
661 "FE13" , A_CHAR( "203,HexadecimalFloatFormatNotSupported" ",FJS103" ),
662 "FE14" , A_CHAR( "204,NoAlternateFormOfConversion" ",FJS104" ),
663 "FE15" , A_CHAR( "205,NoPrecisionWithConversion" ",FJS105" ),
664 "FE16" , A_CHAR( "206,UnknownDateTimeConversionSuffix" ",FJS106" ),
665 "FE17" , A_CHAR( "207,UnknownConversionJS" ",FJS107" ),
666
667 // PropertyFormatter and PropertyFormatters
668 "FE18" , A_CHAR( "501,UnknownPropertyInFormatString" ",PFM501" ),
669 "FE19" , A_CHAR( "502,ErrorInResultingFormatString" ",PFM502" ),
670 "FE20" , A_CHAR( "510,MissingConfigurationVariable" ",PFM510" ),
671
672 // class Paragraphs
673 "FE21" , A_CHAR( "601,UnknownMarker" ",ST601" ),
674 "FE22" , A_CHAR( "602,EndmarkerWithoutStart" ",ST602" ),
675
676 // general formatter errors
677 "FMG11" , A_CHAR( "Argument index 0 not allowed.\n"
678 "In: {!Q}\n >{!FillC-}^" ),
679 "FMG12" , A_CHAR( "Argument index #{} is out of bounds. {} arguments are available.\n"
680 "In: {!Q}\n >{!FillC-}^" ),
681 "FMG13" , A_CHAR( "Detected placeholder type does not match given argument.\n"
682 "Placeholder number: {}\n"
683 "Placeholder type: {} ({})\n" )
684 "Deduced argument type: {!Q}\n"
685 ALIB_REL_DBG( A_CHAR( "{!X}") ,
686 A_CHAR( "Native argument type: <{}>\n" )
687 "In: {!Q}\n >{!FillC-}^" ),
688
689 // Formatter Python Style
690 "FPS101" , A_CHAR( "Closing bracket '}}' of placeholder not found (or syntax error).\n"
691 "In: {!Q}\n >{!FillC-}^" ),
692 //...
693 //...
694 //...
695 "FPS102" , A_CHAR( "Missing precision value after '.' character."
696 "\nIn: {!Q}\n >{!FillC-}^" ),
697 "FPS103" , A_CHAR( "Duplicate type code {!Q'} given (previous was {!Q'})."
698 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") )
699 "\nIn: {!Q}\n >{!FillC-}^" ),
700 "FPS104" , A_CHAR( "Unknown type code {!Q'} given."
701 "\nIn: {!Q}\n >{!FillC-}^" )
702 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") ),
703 "FPS105" , A_CHAR( "Expected '!' in continuation of placeholder."
704 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") )
705 "\nIn: {!Q}\n >{!FillC-}^" ),
706 "FPS106" , A_CHAR( "Unknown conversion \"!{}\"."
707 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") )
708 "\nIn: {!Q}\n >{!FillC-}^" ),
709 "FPS107" , A_CHAR( "Precision not allowed with integer format."
710 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") )
711 "\nIn: {!Q}\n >{!FillC-}^" ),
712 "FPS108" , A_CHAR( "Missing pair of replacement strings \"<src><repl>\" after \"!Replace\"."
713 ALIB_REL_DBG( A_CHAR( "{!X}") , A_CHAR( "\nNative argument type: <{}> ") )
714 "\nIn: {!Q}\n >{!FillC-}^" ),
715
716
717 // Formatter Java Style
718 "FJS101" , A_CHAR( "Brackets for negative values not implemented/supported."
719 "\nIn: {!Q}\n >{!FillC-}^" ),
720 "FJS102" , A_CHAR( "Missing precision value after '.' character."
721 "\nIn: {!Q}\n >{!FillC-}^" ),
722 "FJS103" , A_CHAR( "Hexadecimal float format not implemented/supported."
723 "\nIn: {!Q}\n >{!FillC-}^" ),
724 "FJS104" , A_CHAR( "Alternate form '#' not supported with conversion {!Q}."
725 "\nIn: {!Q}\n >{!FillC-}^" ),
726 "FJS105" , A_CHAR( "Precision specification (\".{}\") is not supported with conversion {!Q}."
727 "\nIn: {!Q}\n >{!FillC-}^" ),
728 "FJS106" , A_CHAR( "Unknown date/time conversion suffix {!Q'}."
729 "\nIn: {!Q}\n >{!FillC-}^" ),
730 "FJS107" , A_CHAR( "Unknown conversion character {!Q'}."
731 "\nIn: {!Q}\n >{!FillC-}^" ),
732
733
734 // PropertyFormatter and PropertyFormatters
735 "PFM501" , A_CHAR( "Unknown property identifier \"{}{}\" in format string.\n"
736 "Format string: {!Q}.\n"
737 "Allowed identifiers: " ),
738 "PFM502" , A_CHAR( "Error in resulting format string.\nSource format: {!Q}." ),
739 "PFM510" , A_CHAR( "Missing or empty configuration variable {!Q} containing user-defined format string." ),
740
741 // class Paragraphs
742 "ST601" , A_CHAR( "Unknown marker at position {}.\n"
743 " Marked text: {!Q}.\n"
744 " >{!FillC-}^\n" ),
745 "ST602" , A_CHAR( "Found an end-marker without a start marker at position {}.\n"
746 " Marked text: {!Q}.\n"
747 " >{!FillC-}^\n" ),
748
749
750 "BS", A_CHAR( "0,B" ",3,"
751 "1,KiB" ",3,"
752 "2,MiB" ",3,"
753 "3,GiB" ",3,"
754 "4,TiB" ",3,"
755 "5,PiB" ",3,"
756 "6,EiB" ",3,"
757 "7,ZiB" ",3,"
758 "8,YiB" ",3,"
759 "9,RiB" ",3,"
760 "10,QiB" ",3,"
761 "11,B" ",1,"
762 "12,kB" ",2,"
763 "13,MB" ",2,"
764 "14,GB" ",2,"
765 "15,TB" ",2,"
766 "16,PB" ",2,"
767 "17,EB" ",2,"
768 "18,ZB" ",2,"
769 "19,YB" ",2,"
770 "20,RB" ",2,"
771 "21,QB" ",2" ) EOS
772
773 // end of BootstrapBulk()
774 nullptr );
775#endif // !ALIB_RESOURCES_OMIT_DEFAULTS
776
777
778 ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_lang_format_bytesize_iec )
779 ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_lang_format_bytesize_si )
780 ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_lang_format_bytesize_units )
781
785
794
802 #if ALIB_THREADS
804 alib::boxing::TMappedTo <alib::threads::Thread*> >(alib::threads::FAppend_thread);
806 #endif
807 #if ALIB_BITBUFFER
809 #endif
810
811
812 // create formatters. This has to be done very early, so that they can be used during
813 // initialization.
815 Formatter::Default->Next.InsertDerived<FormatterJavaStyle >();
816
817 // CodeMarker_CommonEnums
821DOX_MARKER( [DOX_ENUMS_MAKE_PARSABLE_22] )
823DOX_MARKER( [DOX_ENUMS_MAKE_PARSABLE_22] )
844
849DOX_MARKER([DOX_CONFIG_DECLARATION7])
851DOX_MARKER([DOX_CONFIG_DECLARATION7])
852#endif
853
856 EnumRecords<SystemFolders >::Bootstrap( *this, "SystemFolders" );
861 }
862
863 else if( phase == BootstrapPhases::PrepareConfig )
864 {
865
866 // preload all variable with declarations (and without placeholders)
867 #if ALIB_CONFIGURATION
869 #endif
870 }
871
872 else if( phase == BootstrapPhases::Final )
873 {
875 Substring parser;
876 parser= GetResource( "Months" ); for( int i= 0 ; i < 12 ; ++i ) { months[i]= parser.ConsumeToken(','); }
877 parser= GetResource( "Days" ); for( int i= 0 ; i < 7 ; ++i ) { days[i]= parser.ConsumeToken(','); }
878
879 parser= GetResource( "DurUnts" );
880 for( int i= 0 ; i < Units::SIZE_OF_UNITS ; ++i )
881 units[i]= parser.ConsumeToken(',');
882
883 ALIB_ASSERT( units[Units::SIZE_OF_UNITS-1].IsNotEmpty() )
884 ALIB_ASSERT( parser.IsEmpty() )
886
889
890 //############### set locale ###############
891 int receivedFrom= 0;
892 String256 locale;
893 #if ALIB_CONFIGURATION
894 Variable varLocale(*config, Variables::LOCALE);
895 if ( varLocale.IsDefined()
896 && varLocale.GetString().IsNotEmpty() )
897 {
898 receivedFrom= 1;
899 locale._( varLocale.GetString() );
900 }
901 else
902 #endif
903
904 if ( EnvironmentVariables::Get( A_CHAR("LANG") ,locale ) ) receivedFrom= 2;
905 else if ( EnvironmentVariables::Get( A_CHAR("LANGUAGE") ,locale ) ) receivedFrom= 3;
906
907 if( receivedFrom > 0 && !locale.Equals<NC,lang::Case::Ignore>( A_CHAR("none") ) )
908 {
909 ALIB_STRINGS_TO_NARROW( locale, nLocale, 1024)
910 if( !setlocale(LC_ALL, nLocale ) )
911 {
912 NString256 msg( "ALib Error: setlocale(\""); msg << nLocale <<"\") failed. Setting read from ";
913 msg << ( receivedFrom == 1 ? "config variable 'ALIB_LOCALE'" :
914 receivedFrom == 2 ? "environment variable 'LANG'" :
915 receivedFrom == 3 ? "environment variable 'LANGUAGE'" : "ERROR" );
916
917 std::cerr.write( msg.Buffer(), msg.Length() );
918
919 std::cerr << ". Trying 'setlocale(LC_ALL, \"\")': ";
920 if ( setlocale(LC_ALL, "" ) )
921 std::cerr << " success.";
922 else
923 {
924 std::cerr << "failed. Trying 'setlocale(LC_ALL, \"C\")': ";
925 if ( setlocale(LC_ALL, "C" ) )
926 std::cerr << " success.";
927 else
928 std::cerr << std::endl << " Panic: No standard locale setting was successful!";
929 }
930 std::cerr << std::endl;
931 }
932 else
934 }
935
936 // set the system's locale as the default for our static default number format
937 #if ALIB_STRINGS
939 NumberFormat::Global.Flags+= NumberFormatFlags::WriteGroupChars;
940 #endif
941
942
943 // --- determine if we have a console window ---
944 // read configuration
945 #if ALIB_CONFIGURATION
946 Variable varHasConsoleWindow(*config, Variables::HAS_CONSOLE_WINDOW );
947 if ( varHasConsoleWindow.IsDefined() )
948 HasConsoleWindow= varHasConsoleWindow;
949 else
950 {
951 #if defined(_WIN32)
952 // determine if we have a console window
953 HasConsoleWindow= GetConsoleWindow() != NULL;
954 #else
955 HasConsoleWindow= true;
956 #endif
957 (void) varHasConsoleWindow.Define();
958 varHasConsoleWindow= HasConsoleWindow;
959 }
960 #else // -> !ALIB_CONFIGURATION
961 #if defined(_WIN32)
962 // determine if we have a console window
963 HasConsoleWindow= GetConsoleWindow() != NULL;
964 #else
965 HasConsoleWindow= true;
966 #endif
967 #endif // ALIB_CONFIGURATION
968
969 // --- determine if we want to wait for a keypress upon termination ---
970 #if ALIB_CONFIGURATION
971 Variable varWaitForKeyPress(*config, Variables::WAIT_FOR_KEY_PRESS );
972 if ( varWaitForKeyPress.IsDefined() )
973 WaitForKeyPressOnTermination= varWaitForKeyPress;
974 else
975 {
976 #if defined(_WIN32) && ALIB_DEBUG
979 #else
981 #endif
982 (void) varWaitForKeyPress.Define();
983 varWaitForKeyPress= WaitForKeyPressOnTermination;
984 }
985 #else // -> !ALIB_CONFIGURATION
986 #if defined(_WIN32) && ALIB_DEBUG
989 #else
991 #endif
992 #endif
993
994 // --- attach Lock to Default-Formatter ---
995DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
996#if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
998#endif
999DOX_MARKER([DOX_CRITICAL_SECTIONS_ADD_LOCK2])
1000
1001 }
1002}
1003
1005{
1006 if( phase == ShutdownPhases::Announce )
1007 {
1008 #if ALIB_DEBUG_CRITICAL_SECTIONS && ALIB_MONOMEM
1009 Formatter::Default->DCSLock= nullptr;
1010 #endif
1011 return;
1012 }
1013
1014 // ShutdownPhases::Destruct:
1016 {
1017 #if defined(_WIN32)
1018 OutputDebugStringA( "\r\nALIB: Waiting for 'Enter' key in the console window.\r\n" );
1019 #endif
1020
1021 std::cout << std::endl << GetResource("EXIT_MSG") << std::endl;
1022 while ( getchar() != '\n' )
1023 ;
1024 }
1025
1026 // ::format
1027 ALIB_ASSERT_WARNING( Formatter::Default.UseCount() == 1,
1028 "ALIB", "DefaultFormatter still shared more than once: ",
1029 int(Formatter::Default.UseCount()) )
1030
1031 Formatter::Default= nullptr;
1032
1033 // alib/lang/message
1034 #if ALIB_DEBUG
1036 #endif
1037
1038 if ( Report::defaultReport != nullptr )
1039 delete Report::defaultReport;
1040
1043}
1044
1045// #############################################################################################
1046// Environment definition/detection
1047// #############################################################################################
1048
1049//! @cond NO_DOX
1050 #if defined(__unix__) || defined(__APPLE__)
1051 namespace {
1052 String DebuggerProcessNames= A_CHAR("gdb|debugserver");
1053 }
1054 #endif
1055//! @endcond
1056
1058 {
1059 #if defined(__unix__) || defined(__APPLE__)
1060
1061 // Unix: search debugger process in parent processes
1062 const ProcessInfo& pi= ProcessInfo::Current();
1063 uinteger parentPID= pi.PPID;
1064 if ( parentPID == 0 )
1065 return false;
1066
1067 ProcessInfo actPI( parentPID );
1068 Tokenizer tknzr( DebuggerProcessNames, '|' );
1069 while(tknzr.HasNext() )
1070 {
1071 Substring& debuggerName= tknzr.Next();
1072 if (actPI.Name.StartsWith( debuggerName ) )
1073 return true;
1074 }
1075 return false;
1076
1077 #elif defined(_WIN32)
1078
1079 return (bool) ( ::IsDebuggerPresent() != 0 ) ;
1080
1081 #else
1082 #pragma message ("Unknown Platform in file: " __FILE__ )
1083 return false;
1084 #endif
1085 }
1086
1087
1088// #################################################################################################
1089// namespace lang::system
1090// #################################################################################################
1091} namespace system {
1093{
1094 auto* enumRecord= enums::TryRecord( SystemErrors(errNo) );
1095 if( enumRecord == nullptr )
1096 return Exception( ci, SystemErrors::UNKNOWN, errNo );
1097
1098 return Exception( ci, SystemErrors(errNo), // as exception
1099 SystemErrors(errNo), // boxing the exception's name (!)
1100 errNo );
1101}
1102
1103// #################################################################################################
1104// CalendarDateTime::Format
1105// #################################################################################################
1107{
1108 if ( targetData == lang::CurrentData::Clear )
1109 target.Reset();
1110
1111 // this ensures that target is not nulled, as all other appends are NC-versions
1112 target._("");
1114
1115 while ( format.IsNotEmpty() )
1116 {
1117 // read n equal characters
1118 int n= 1;
1119 character c= format.ConsumeChar();
1120 while ( format.ConsumeChar(c) )
1121 ++n;
1122
1123 switch (c)
1124 {
1125 case '\'': // single quotes
1126 {
1127 // one or more pairs of single quotes?
1128 if ( n > 1 )
1129 {
1130 int pairs= n / 2;
1131 target.InsertChars<NC>( '\'', pairs );
1132 n-= (pairs * 2);
1133 }
1134
1135 // one single quote?
1136 if ( n == 1 )
1137 {
1138 // search end
1139 integer end= format.IndexOf( '\'' );
1140 if ( end < 1 )
1141 {
1142 ALIB_WARNING( "ALIB", "Format Error: Missing single Quote" )
1143 target << "Format Error: Missing closing single quote character <'>" ;
1144 return target;
1145 }
1146
1147 target._<NC>( format, 0, end );
1148 format.ConsumeChars<NC>( end + 1 );
1149 }
1150
1151 } break;
1152
1153 case 's': // second
1154 target.template _<NC>( alib::Format( Second, n, nf ) );
1155 break;
1156
1157 case 'm': //minute
1158 target._<NC>( alib::Format( Minute, n, nf ) );
1159 break;
1160
1161 case 'K': // hour 0..11
1162 target._<NC>( alib::Format( Hour % 12, n, nf ) );
1163 target._<NC>( Hour < 12 ? " am" : " pm" );
1164 break;
1165
1166 case 'H': // hour 0..23
1167 target._<NC>( alib::Format( Hour, n, nf ) );
1168 break;
1169
1171 case 'd': // day
1172 if ( n <= 2 ) target._<NC>( alib::Format( Day, n, nf) );
1173 else if ( n == 3 ) target._<NC>( days[DayOfWeek], 0, 3 );
1174 else target._<NC>( days[DayOfWeek] );
1175 break;
1176
1177 case 'M': // month
1178 if ( n <= 2 ) target._<NC>( alib::Format( Month, n, nf ) );
1179 else if ( n == 3 ) target._<NC>( months[Month-1], 0, 3 );
1180 else target._<NC>( months[Month-1] );
1181 break;
1183
1184 case 'y': // year
1185 if ( n == 1 ) target._<NC>( alib::Format(Year, 1, nf) );
1186 else if ( n == 2 ) target._<NC>( alib::Format(Year % 100, 2, nf) );
1187 else target._<NC>( alib::Format(Year, n, nf) );
1188 break;
1189
1190 default: // otherwise: copy what was in
1191 target.InsertChars<NC>( c, n );
1192 break;
1193 }
1194
1195 }
1196
1197 return target;
1198}
1199
1200
1201
1202// #################################################################################################
1203// FFormat_DateTime
1204// #################################################################################################
1205#if !DOXYGEN
1206DOX_MARKER([DOX_BOXING_IFORMAT_DATETIME])
1207void FFormat_DateTime( const Box& box, const String& formatSpec, NumberFormat&, AString& target )
1208{
1210 tct.Format( formatSpec.IsNotEmpty() ? formatSpec
1211 : BASECAMP.GetResource("FMTDT"),
1212 target );
1213}
1214DOX_MARKER([DOX_BOXING_IFORMAT_DATETIME])
1215#endif
1216
1217}}} // namespace [alib::lang::system]
1218
1219
1220#if !DOXYGEN
1221namespace alib::strings {
1222
1223// #################################################################################################
1224// T_Append<DateTime::Duration>
1225// #################################################################################################
1226using namespace lang;
1227
1228namespace {
1229
1230 template<typename TChar, typename TAllocator>
1231 void appendDateTime(TAString<TChar,TAllocator>& target, const DateTime::Duration pSrc)
1232 {
1234 using Duration= DateTime::Duration;
1235 Duration src= pSrc;
1236 auto nanos= src.InNanoseconds();
1237 if( nanos == 0 )
1238 {
1239 target << units[Units::TS_ZERO];
1240 return;
1241 }
1242
1243 if( nanos < 0 )
1244 {
1245 target << A_CHAR("- ");
1246 src= Duration() - src;
1247 }
1248
1249 TNumberFormat<TChar> nf( TNumberFormat<TChar>::Global );
1250 nf.FractionalPartWidth= 2;
1251 int64_t v= src.InAbsoluteDays();
1252 if( v >= 10 )
1253 {
1254 target << TFormat<TChar>( src.InDays(), &nf ) << units[Units::DayPlural];
1255 return;
1256 }
1257
1258 if( v > 0 )
1259 {
1260 target << v << ( v != 1 ? units[Units::DayPlural]
1261 : units[Units::DaySingular] );
1262
1263 Duration cpy= src - ( Duration::FromAbsoluteDays(v) );
1264
1265 target << ' ' << TFormat<TChar>( cpy.InHours(), &nf ) << units[Units::HourPlural];
1266 return;
1267 }
1268
1269 v= src.InAbsoluteHours();
1270 if( v > 0 )
1271 {
1272 target << v << ( v != 1 ? units[Units::HourPlural]
1273 : units[Units::HourSingular] );
1274
1275 Duration cpy= src - ( Duration::FromAbsoluteHours(v) );
1276
1277 auto minutes= cpy.InAbsoluteMinutes();
1278 target << ' ' << minutes << (minutes!= 1 ? units[Units::MinPlural]
1279 : units[Units::MinSingular] );
1280 return;
1281 }
1282
1283 v= src.InAbsoluteMinutes();
1284 if( v > 0 )
1285 {
1286 target << v << ( v != 1 ? units[Units::MinPlural]
1287 : units[Units::MinSingular] );
1288
1289 Duration cpy= src - ( Duration::FromAbsoluteMinutes(v) );
1290
1291 auto seconds= cpy.InAbsoluteSeconds();
1292 target << ' ' << seconds << (seconds!= 1 ? units[Units::SecPlural]
1293 : units[Units::SecSingular] );
1294 return;
1295 }
1296
1297 v= src.InAbsoluteSeconds();
1298 if( v > 0 )
1299 {
1300 target << TFormat<TChar>( src.InSeconds(), &nf ) << units[Units::SecPlural];
1301 return;
1302 }
1303
1304 nf.DecMinimumFieldWidth= 3;
1305
1306 auto val= src.InAbsoluteMilliseconds();
1307 if( val >= 1 )
1308 {
1309 target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::MlSecPlural]
1310 : units[Units::MlSecSingular] );
1311 return;
1312 }
1313
1314 val= src.InAbsoluteMicroseconds();
1315 if( val >= 1 )
1316 {
1317 target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::McSecPlural]
1318 : units[Units::McSecSingular] );
1319 return;
1320 }
1321
1322 val= src.InNanoseconds();
1323 target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::NSecPlural]
1324 : units[Units::NSecSingular] );
1325 return;
1327 }
1328} //anonymous namespace
1329
1330
1331template<typename TChar, typename TAllocator>
1332void T_Append<time::DateTime::Duration,TChar,TAllocator>::operator()( TAString<TChar,TAllocator>& target, const time::DateTime::Duration src )
1333{
1334 appendDateTime( target, src );
1335}
1336
1337template<typename TChar, typename TAllocator>
1338void T_Append<time::Ticks::Duration,TChar,TAllocator>::operator()( TAString<TChar,TAllocator>& target, const time::Ticks::Duration src)
1339{
1340 // simply convert the ticks-duration to a DateTime duration and use its append function
1341 appendDateTime( target, time::DateTime::Duration::FromNanoseconds( src.InNanoseconds() ));
1342}
1343
1344// Instantiations
1345template void T_Append<time::DateTime::Duration, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const time::DateTime::Duration );
1346template void T_Append<time::DateTime::Duration, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const time::DateTime::Duration );
1347template void T_Append<time::DateTime::Duration, xchar, lang::HeapAllocator>::operator()( TAString<xchar, lang::HeapAllocator>&, const time::DateTime::Duration );
1348template void T_Append<time::Ticks:: Duration, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const time::Ticks ::Duration );
1349template void T_Append<time::Ticks:: Duration, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const time::Ticks ::Duration );
1350template void T_Append<time::Ticks:: Duration, xchar, lang::HeapAllocator>::operator()( TAString<xchar, lang::HeapAllocator>&, const time::Ticks ::Duration );
1351
1352} // namespace [alib::strings]
1353#endif //!DOXYGEN
1354
1355
1356// #################################################################################################
1357// format::ByteSize
1358// #################################################################################################
1359#if !DOXYGEN
1360namespace alib::lang::format {
1361namespace {
1362
1363double convertTo(uinteger val, ByteSizeUnits unit)
1364{
1365 double v= double(val);
1366 int loopEnd;
1367 double divisor;
1368 if( unit < ByteSizeUnits::IEC_END)
1369 {
1370 loopEnd= int(unit);
1371 divisor= double(1024);
1372 }
1373 else
1374 {
1375 loopEnd= int(unit) - ByteSizeUnits::SI;
1376 divisor= double(1000);
1377 }
1378
1379 for (int i = 0; i < loopEnd; ++i)
1380 v/= divisor;
1381 return v;
1382}
1383
1385std::pair<double,ByteSizeUnits> getMagnitude( uinteger val, uinteger byteLimit, uinteger factor)
1386{
1388 if( val < byteLimit )
1389 return std::make_pair( double(val), ByteSizeUnits(0) );
1390
1391 while(val != 0)
1392 {
1393 ++unit;
1394 if( val < byteLimit * factor)
1395 return std::make_pair( double(val) / double(factor), unit );
1396
1397 val/= factor;
1398 }
1399}
1401} // namespace alib::lang::format[::anonymous]
1402
1403void FormatByteSize(AString& target, uinteger val, uint16_t magnitudeThreshold,
1404 char unitSeparator, ByteSizeUnits unit, NumberFormat& nf)
1405{
1406 target.EnsureRemainingCapacity(128);
1407
1408 auto magnitude= (unit == ByteSizeUnits::IEC) ? getMagnitude(val, magnitudeThreshold, 1024ull)
1409 : getMagnitude(val, magnitudeThreshold, 1000ull);
1410
1411 if( magnitude.second == 0 )
1412 target << Format( val, nullptr );
1413 else
1414 target.SetLength( strings::detail::WriteFloat( magnitude.first,
1415 target.VBuffer(), target.Length(), 0, nf) );
1416
1417 if( unitSeparator )
1418 target << unitSeparator;
1419 target << (magnitude.second + unit);
1420} // FormatByteSize()
1421
1422std::pair<double, ByteSizeUnits> ByteSizeIEC::GetMagnitude()
1423{
1424 auto result= getMagnitude( Value, MagnitudeThreshold, 1024 );
1425 result.second+= ByteSizeUnits::IEC;
1426 return result;
1427}
1428
1429std::pair<double,ByteSizeUnits> ByteSizeSI::GetMagnitude()
1430{
1431 auto result= getMagnitude( Value, MagnitudeThreshold, 1000 );
1432 result.second+= ByteSizeUnits::SI;
1433 return result;
1434}
1435
1436double ByteSizeIEC::ConvertTo(ByteSizeUnits unit) { return convertTo(Value, unit); };
1437double ByteSizeSI ::ConvertTo(ByteSizeUnits unit) { return convertTo(Value, unit); };
1438
1439
1440} namespace alib::strings {
1441
1442void T_Append< lang::format::ByteSizeSI, character, lang::HeapAllocator>::operator()( AString& target, const lang::format::ByteSizeSI src )
1443{
1445 lang::format::ByteSizeUnits::SI, * lang::format::BYTESIZE_NUMBER_FORMAT );
1446}
1447void T_Append< lang::format::ByteSizeIEC, character, lang::HeapAllocator>::operator()( AString& target, const lang::format::ByteSizeIEC src )
1448{
1450 lang::format::ByteSizeUnits::IEC, * lang::format::BYTESIZE_NUMBER_FORMAT );
1451}
1452
1453} // namespace [alib::strings]
1454
1455ALIB_BOXING_VTABLE_DEFINE( alib::lang::format::ByteSizeIEC , vt_lang_format_bytesize_iec )
1456ALIB_BOXING_VTABLE_DEFINE( alib::lang::format::ByteSizeSI , vt_lang_format_bytesize_si )
1457ALIB_BOXING_VTABLE_DEFINE( alib::lang::format::ByteSizeUnits , vt_lang_format_bytesize_units )
1458
1459#endif //!DOXYGEN
1460
const TUnboxable Unbox() const
TBoxes & Add()
Definition boxes.inl:74
ALIB_API bool Define(Priority requestedPriority=Priority::Standard)
Definition variable.cpp:272
void InsertDerived(TArgs &&... args)
NCString ResourceCategory
Definition camp.hpp:119
lang::resources::ResourcePool * resourcePool
Definition camp.hpp:75
config::Configuration * config
Definition camp.hpp:96
const String & GetResource(const NString &name)
ALIB_API void DoReport(Message &message)
Definition report.cpp:105
static ALIB_API Report * defaultReport
The default Report used internally by ALib and usually by processes that rely on ALib.
Definition report.hpp:104
Types
Types of reports.
Definition report.hpp:93
static Report & GetDefault()
Definition report.hpp:146
virtual ALIB_API void bootstrap(BootstrapPhases phase) override
Definition basecamp.cpp:163
virtual ALIB_API void shutdown(ShutdownPhases phase) override
ALIB_API bool IsDebuggerPresent()
PHTypes
Denotes the type of placeholders (respectively the values they represent).
static ALIB_API threads::RecursiveLock DefaultLock
static ALIB_API SPFormatter Default
SharedPtr< Formatter > Next
virtual void BootstrapBulk(const nchar *category,...)=0
int Minute
The calendar minute (0..59).
Definition calendar.hpp:63
int Year
The calendar year (e.g., 2022).
Definition calendar.hpp:51
int Month
The calendar month (1..12).
Definition calendar.hpp:54
ALIB_API AString & Format(Substring format, AString &target, lang::CurrentData targetData=lang::CurrentData::Keep) const
int Day
The calendar day (1..31).
Definition calendar.hpp:57
int Hour
The calendar hour (0..23).
Definition calendar.hpp:60
int Second
The calendar second (0..59).
Definition calendar.hpp:66
This class represents process information.
static ALIB_API const ProcessInfo & Current()
uinteger PPID
The parent's process id as AString. (Unix like OS / Mac OS only.)
static TDerivedClass * singleton
A pointer to the one and only singleton.
Definition singleton.hpp:54
TAString & InsertChars(TChar c, integer qty)
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
void EnsureRemainingCapacity(integer spaceNeeded)
Definition tastring.inl:742
TChar * VBuffer() const
Definition tastring.inl:843
void SetLength(integer newLength)
Definition tastring.inl:924
integer IndexOf(TChar needle, integer startIdx=0) const
Definition string.hpp:896
void Allocate(TAllocator &allocator, const TString< TChar > &copy)
Definition string.hpp:2012
constexpr bool IsNotEmpty() const
Definition string.hpp:389
constexpr integer Length() const
Definition string.hpp:326
bool Equals(const TString< TChar > &rhs) const
Definition string.hpp:580
bool StartsWith(const TString &needle) const
Definition string.hpp:820
constexpr const TChar * Buffer() const
Definition string.hpp:319
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:16
DbgLockAsserter Dbg
The debug tool instance.
#define ALIB_WARNING(...)
Definition alib.hpp:1268
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition vtable.inl:473
#define IF_ALIB_THREADS(...)
Definition alib.hpp:352
#define A_CHAR(STR)
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X(TAppendable)
#define IF_ALIB_BITBUFFER(...)
Definition alib.hpp:240
#define IF_ALIB_THREADMODEL(...)
Definition alib.hpp:344
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable)
#define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER(Identifier)
Definition vtable.inl:489
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:1271
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N(TAppendable)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
#define ALIB_ASSERT_WARNING(cond,...)
Definition alib.hpp:1272
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W(TAppendable)
#define ALIB_REL_DBG(releaseCode,...)
Definition alib.hpp:392
#define ALIB_WARNINGS_IGNORE_NOTHING_RETURNED
Definition alib.hpp:825
#define ALIB_ASSERT(cond)
Definition alib.hpp:1270
#define ALIB_THREADMODEL
Definition alib.hpp:212
#define ALIB_BITBUFFER
Definition alib.hpp:199
#define ALIB_CONFIGURATION
Definition alib.hpp:204
#define ALIB_THREADS
Definition alib.hpp:213
#define ALIB_ENUMS
Definition alib.hpp:206
void BootstrapRegister(typename TFDecl::Signature function)
Definition boxing.hpp:112
const T_EnumRecords< TEnum >::Type * TryRecord(TEnum element)
@ HAS_CONSOLE_WINDOW
See ALIB/HAS_CONSOLE_WINDOW.
@ WAIT_FOR_KEY_PRESS
See ALIB/WAIT_FOR_KEY_PRESS.
NumberFormat * BYTESIZE_NUMBER_FORMAT
Definition basecamp.cpp:72
ALIB_API void FormatByteSize(AString &target, uinteger byteSize, uint16_t magnitudeThreshold, char unitSeparator, ByteSizeUnits unit, NumberFormat &nf)
void FFormat_CallerInfo(const Box &box, const String &formatSpec, NumberFormat &, AString &target)
Exception CreateSystemException(const CallerInfo &ci, int errNo)
SystemExceptions
Denotes exceptions thrown by classes of namespace alib::lang::system.
SystemErrors
Denotes result values returned by system functions (glibc, etc).
ALIB_API void FFormat_DateTime(const Box &self, const String &formatSpec, NumberFormat &nf, AString &target)
platform_specific integer
Definition integers.hpp:43
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE void debugReportPlugin(const CallerInfo &ci, int type, const char *topic, int qtyMsgs, const nchar **msgs)
Definition basecamp.cpp:98
void(* DBG_SIMPLE_ALIB_MSG_PLUGIN)(const CallerInfo &ci, int type, const char *topic, int qtyMsgs, const char **msgs)
Definition alib.cpp:316
platform_specific uinteger
Definition integers.hpp:47
@ Clear
Chooses to clear existing data.
ALIB_API MonoAllocator GLOBAL_ALLOCATOR
ALIB_API integer WriteFloat(double value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf)
Definition alib.cpp:69
ShutdownPhases
Termination levels usable with Bootstrapping ALib Camps.
Definition alib.hpp:1418
lang::Exception Exception
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.hpp:276
lang::basecamp::BaseCamp BASECAMP
The singleton instance of ALib Camp class BaseCamp.
Definition basecamp.cpp:70
BootstrapPhases
Initialization levels usable with Bootstrapping ALib Camps.
Definition alib.hpp:1393
@ Final
The final initialization phase. Here, camps are initializing their custom setup.
strings::TFormat< character > Format
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
lang::format::ByteSizeUnits ByteSizeUnits
Type alias in namespace alib.
Definition bytesize.hpp:223
characters::nchar nchar
Type alias in namespace alib.
static void Bootstrap(TEnum element, TArgs &&... args) noexcept
char UnitSeparator
An optional character to separate the number from the unit.
Definition bytesize.hpp:114
ALIB_API std::pair< double, ByteSizeUnits > GetMagnitude()
ALIB_API double ConvertTo(ByteSizeUnits unit)
uinteger Value
The encapsulated value to print.
Definition bytesize.hpp:110
char UnitSeparator
An optional character to separate the number from the unit.
Definition bytesize.hpp:156
ALIB_API std::pair< double, ByteSizeUnits > GetMagnitude()
uinteger Value
The encapsulated value to print.
Definition bytesize.hpp:152
static ALIB_API bool Get(const CString &varName, AString &target, lang::CurrentData targetData=lang::CurrentData::Clear)
NumberFormatFlags Flags
The flag field.