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