ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
system.cpp
1 // #################################################################################################
2 // ALib C++ Library
3 //
4 // Copyright 2013-2023 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_SYSTEM_SYSTEM)
11 # include "alib/system/system.hpp"
12 # endif
13 # if !defined (HPP_ALIB_FS_MODULES_DISTRIBUTION)
15 # endif
16 # if !defined (HPP_ALIB_STRINGS_NUMBERFORMAT)
18 # endif
19 # if !defined (HPP_ALIB_STRINGS_FORMAT)
20 # include "alib/strings/format.hpp"
21 # endif
22 # if !defined (HPP_ALIB_STRINGS_SUBSTRING)
24 # endif
25 # if !defined(HPP_ALIB_TIME_TIME)
26 # include "alib/time/time.hpp"
27 # endif
28 # if !defined (HPP_ALIB_RESOURCES_RESOURCES)
30 # endif
31 # if !defined (HPP_ALIB_RESULTS_RESULTS)
32 # include "alib/results/results.hpp"
33 # endif
34 # if !defined (HPP_ALIB_SYSTEM_DIRECTORY)
35 # include "alib/system/directory.hpp"
36 # endif
37 # if !defined (HPP_ALIB_SYSTEM_CALENDAR)
38 # include "alib/system/calendar.hpp"
39 # endif
40 # if !defined (HPP_ALIB_ENUMS_RECORDBOOTSTRAP)
42 # endif
43 # if !defined(HPP_ALIB_ENUMS_SERIALIZATION)
45 # endif
46 #if !defined(HPP_ALIB_TEXT_FWDS)
47 # include "alib/text/fwds.hpp"
48 #endif
49 #endif // !defined(ALIB_DOX)
50 
51 using namespace aworx::lib;
52 
55 
56 namespace aworx { namespace lib {
57 
59 
60 namespace system {
61 
62 
63 #if !defined(ALIB_DOX)
64 namespace
65 {
67  String months[12];
68  String days[7];
69 
70  enum Units
71  {
72  TS_ZERO,
73  DayPlural,
74  DaySingular,
75  HourPlural,
76  HourSingular,
77  MinPlural,
78  MinSingular,
79  SecPlural,
80  SecSingular,
81  MlSecPlural,
82  MlSecSingular,
83  McSecPlural,
84  McSecSingular,
85  NSecPlural,
86  NSecSingular, SIZE_OF_UNITS
87  };
88 
89  String units[SIZE_OF_UNITS];
91 }
92 #endif // defined(ALIB_DOX)
93 
94 System::System()
96 {
97  ALIB_ASSERT_ERROR( this == &SYSTEM, "SYSTEM",
98  "Instances of class System must not be created. Use singleton aworx::lib::SYSTEM" )
99 }
100 
101 
102 void System::bootstrap( BootstrapPhases phase, int, const char**, const wchar_t** )
103 {
104  if( phase == BootstrapPhases::PrepareResources )
105  {
107 
108  ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_system_exceptions )
109  ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_system_systemerrors )
110 
111 
112  #define EOS ,
113 #if !ALIB_RESOURCES_OMIT_DEFAULTS
115 
116  // Calendar
117  "Months" , A_CHAR("January,February,March,April,May,June,July,August,September,October,November,December")
118  , "Days" , A_CHAR("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,") EOS
119 
120  "DurUnts" , A_CHAR("zero time" "," // 0 TS_ZERO
121  " days" "," // 1 DayP
122  " day" "," // 2 DayS
123  " hours" "," // 3 HourP
124  " hour" "," // 4 HourS
125  " minutes" "," // 5 MinP
126  " minute" "," // 6 MinS
127  " seconds" "," // 7 SecP
128  " second" "," // 8 SecS
129  " ms" "," // 9 MlSecP
130  " ms" "," // 10 MlSecS
131  " \u00B5s" "," // 11 McSecP
132  " \u00B5s" "," // 12 McSecS
133  " ns" "," // 13 NSecP
134  " ns" ), // 14 NSecS
135 
136  "DFMT", A_CHAR( "yyyy-MM-dd HH:mm:ss"), // default format string for DateTime values used by FFormat_DateTime()
137 
138  // Exceptions
139  "E<", A_CHAR("system::"),
140  "E", A_CHAR("0,OK" ",NON" ) EOS
141 
142  "SpecialFolder", A_CHAR("0,Root" ",1,"
143  "1,Current" ",1,"
144  "3,HomeConfig" ",5,"
145  "2,Home" ",1,"
146  "4,Module" ",1,"
147  "5,Temp" ",1,"
148  "6,VarTemp" ",1" ) EOS
149 
150 
151  // System errors
152  #if defined (__GLIBC__) || defined(__APPLE__)
153  "SE<" , A_CHAR("glibc::" ),
154  "OSERR" , A_CHAR("GNU-C Library call returned {!Q} ({})."),
155  "UknSE" , A_CHAR("GNU-C Library call returned ({}). (Unknown error number)"),
156  #elif defined(_WIN32)
157  "SE<" , A_CHAR("WindowsOS::" ),
158  "OSERR" , A_CHAR("Windows system call returned {!Q} ({})."),
159  "UknSE" , A_CHAR("Windows system call returned ({}). (Unknown error number)"),
160  #endif
161  "SE",
162 
163  A_CHAR("-1" "," "UNKNOWN" "," "UknSE" "," )
164  A_CHAR("0" "," "OK" "," "," )
165 
166 #if defined (__GLIBC__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
167  A_CHAR("1" "," "EPERM" "," "OSERR" ","
168  "2" "," "ENOENT" "," "OSERR" ","
169  "3" "," "ESRCH" "," "OSERR" ","
170  "4" "," "EINTR" "," "OSERR" ","
171  "5" "," "EIO" "," "OSERR" ","
172  "6" "," "ENXIO" "," "OSERR" ","
173  "7" "," "E2BIG" "," "OSERR" ","
174  "8" "," "ENOEXEC" "," "OSERR" ","
175  "9" "," "EBADF" "," "OSERR" ","
176  "10" "," "ECHILD" "," "OSERR" ","
177  "11" "," "EAGAIN" "," "OSERR" ","
178  "12" "," "ENOMEM" "," "OSERR" ","
179  "13" "," "EACCES" "," "OSERR" ","
180  "14" "," "EFAULT" "," "OSERR" ","
181  "15" "," "ENOTBLK" "," "OSERR" ","
182  "16" "," "EBUSY" "," "OSERR" ","
183  "17" "," "EEXIST" "," "OSERR" ","
184  "18" "," "EXDEV" "," "OSERR" ","
185  "19" "," "ENODEV" "," "OSERR" ","
186  "20" "," "ENOTDIR" "," "OSERR" ","
187  "21" "," "EISDIR" "," "OSERR" ","
188  "22" "," "EINVAL" "," "OSERR" ","
189  "23" "," "ENFILE" "," "OSERR" ","
190  "24" "," "EMFILE" "," "OSERR" ","
191  "25" "," "ENOTTY" "," "OSERR" ","
192  "26" "," "ETXTBSY" "," "OSERR" ","
193  "27" "," "EFBIG" "," "OSERR" ","
194  "28" "," "ENOSPC" "," "OSERR" ","
195  "29" "," "ESPIPE" "," "OSERR" ","
196  "30" "," "EROFS" "," "OSERR" ","
197  "31" "," "EMLINK" "," "OSERR" ","
198  "32" "," "EPIPE" "," "OSERR" ","
199  "33" "," "EDOM" "," "OSERR" ","
200  "34" "," "ERANGE" "," "OSERR" ","
201  "35" "," "EDEADLK" "," "OSERR" ","
202  "36" "," "ENAMETOOLONG" "," "OSERR" ","
203  "37" "," "ENOLCK" "," "OSERR" ","
204  "38" "," "ENOSYS" "," "OSERR" ","
205  "39" "," "ENOTEMPTY" "," "OSERR" ","
206  "40" "," "ELOOP" "," "OSERR" ","
207  "42" "," "ENOMSG" "," "OSERR" ","
208  "43" "," "EIDRM" "," "OSERR" "," )
209 #if !defined(__APPLE__)
210  A_CHAR("44" "," "ECHRNG" "," "OSERR" ","
211  "45" "," "EL2NSYNC" "," "OSERR" ","
212  "46" "," "EL3HLT" "," "OSERR" ","
213  "47" "," "EL3RST" "," "OSERR" ","
214  "48" "," "ELNRNG" "," "OSERR" ","
215  "49" "," "EUNATCH" "," "OSERR" ","
216  "50" "," "ENOCSI" "," "OSERR" ","
217  "51" "," "EL2HLT" "," "OSERR" ","
218  "52" "," "EBADE" "," "OSERR" ","
219  "53" "," "EBADR" "," "OSERR" ","
220  "54" "," "EXFULL" "," "OSERR" ","
221  "55" "," "ENOANO" "," "OSERR" ","
222  "56" "," "EBADRQC" "," "OSERR" ","
223  "57" "," "EBADSLT" "," "OSERR" ","
224  "59" "," "EBFONT" "," "OSERR" ",")
225 #endif
226  A_CHAR("60" "," "ENOSTR" "," "OSERR" ","
227  "61" "," "ENODATA" "," "OSERR" ","
228  "62" "," "ETIME" "," "OSERR" ","
229  "63" "," "ENOSR" "," "OSERR" ",")
230 #if !defined(__APPLE__)
231  A_CHAR("64" "," "ENONET" "," "OSERR" ","
232  "65" "," "ENOPKG" "," "OSERR" ",")
233 #endif
234  A_CHAR("66" "," "EREMOTE" "," "OSERR" ","
235  "67" "," "ENOLINK" "," "OSERR" ",")
236 #if !defined(__APPLE__)
237  A_CHAR("68" "," "EADV" "," "OSERR" ","
238  "69" "," "ESRMNT" "," "OSERR" ","
239  "70" "," "ECOMM" "," "OSERR" ",")
240 #endif
241  A_CHAR("71" "," "EPROTO" "," "OSERR" ","
242  "72" "," "EMULTIHOP" "," "OSERR" ",")
243 #if !defined(__APPLE__)
244  A_CHAR("73" "," "EDOTDOT" "," "OSERR" ",")
245 #endif
246  A_CHAR("74" "," "EBADMSG" "," "OSERR" ","
247  "75" "," "EOVERFLOW" "," "OSERR" ",")
248 #if !defined(__APPLE__)
249  A_CHAR("76" "," "ENOTUNIQ" "," "OSERR" ","
250  "77" "," "EBADFD" "," "OSERR" ","
251  "78" "," "EREMCHG" "," "OSERR" ","
252  "79" "," "ELIBACC" "," "OSERR" ","
253  "80" "," "ELIBBAD" "," "OSERR" ","
254  "81" "," "ELIBSCN" "," "OSERR" ","
255  "82" "," "ELIBMAX" "," "OSERR" ","
256  "83" "," "ELIBEXEC" "," "OSERR" ",")
257 #endif
258  A_CHAR("84" "," "EILSEQ" "," "OSERR" ",")
259 #if !defined(__APPLE__)
260  A_CHAR("85" "," "ERESTART" "," "OSERR" ","
261  "86" "," "ESTRPIPE" "," "OSERR" ",")
262 #endif
263  A_CHAR("87" "," "EUSERS" "," "OSERR" ","
264  "88" "," "ENOTSOCK" "," "OSERR" ","
265  "89" "," "EDESTADDRREQ" "," "OSERR" ","
266  "90" "," "EMSGSIZE" "," "OSERR" ","
267  "91" "," "EPROTOTYPE" "," "OSERR" ","
268  "92" "," "ENOPROTOOPT" "," "OSERR" ","
269  "93" "," "EPROTONOSUPPORT" "," "OSERR" ","
270  "94" "," "ESOCKTNOSUPPORT" "," "OSERR" ","
271  "95" "," "EOPNOTSUPP" "," "OSERR" ","
272  "96" "," "EPFNOSUPPORT" "," "OSERR" ","
273  "97" "," "EAFNOSUPPORT" "," "OSERR" ","
274  "98" "," "EADDRINUSE" "," "OSERR" ","
275  "99" "," "EADDRNOTAVAIL" "," "OSERR" ","
276  "100" "," "ENETDOWN" "," "OSERR" ","
277  "101" "," "ENETUNREACH" "," "OSERR" ","
278  "102" "," "ENETRESET" "," "OSERR" ","
279  "103" "," "ECONNABORTED" "," "OSERR" ","
280  "104" "," "ECONNRESET" "," "OSERR" ","
281  "105" "," "ENOBUFS" "," "OSERR" ","
282  "106" "," "EISCONN" "," "OSERR" ","
283  "107" "," "ENOTCONN" "," "OSERR" ","
284  "108" "," "ESHUTDOWN" "," "OSERR" ","
285  "109" "," "ETOOMANYREFS" "," "OSERR" ","
286  "110" "," "ETIMEDOUT" "," "OSERR" ","
287  "111" "," "ECONNREFUSED" "," "OSERR" ","
288  "112" "," "EHOSTDOWN" "," "OSERR" ","
289  "113" "," "EHOSTUNREACH" "," "OSERR" ","
290  "114" "," "EALREADY" "," "OSERR" ","
291  "115" "," "EINPROGRESS" "," "OSERR" ","
292  "116" "," "ESTALE" "," "OSERR" "," )
293 #if !defined(__APPLE__)
294  A_CHAR("117" "," "EUCLEAN" "," "OSERR" ","
295  "118" "," "ENOTNAM" "," "OSERR" ","
296  "119" "," "ENAVAIL" "," "OSERR" ","
297  "120" "," "EISNAM" "," "OSERR" ","
298  "121" "," "EREMOTEIO" "," "OSERR" "," )
299 #endif
300  A_CHAR("122" "," "EDQUOT" "," "OSERR" "," )
301 #if !defined(__APPLE__)
302  A_CHAR("123" "," "ENOMEDIUM" "," "OSERR" ","
303  "124" "," "EMEDIUMTYPE" "," "OSERR" "," )
304 #endif
305  A_CHAR("125" "," "ECANCELED" "," "OSERR" "," )
306 #if !defined(__APPLE__)
307  A_CHAR("126" "," "ENOKEY" "," "OSERR" ","
308  "127" "," "EKEYEXPIRED" "," "OSERR" ","
309  "128" "," "EKEYREVOKED" "," "OSERR" ","
310  "129" "," "EKEYREJECTED" "," "OSERR" "," )
311 #endif
312  A_CHAR("130" "," "EOWNERDEAD" "," "OSERR" ","
313  "131" "," "ENOTRECOVERABLE" "," "OSERR" )
314 #if !defined(__APPLE__)
315  A_CHAR( ","
316  "132" "," "ERFKILL" "," "OSERR" ","
317  "133" "," "EHWPOISON" "," "OSERR" )
318 #endif
319  EOS
320 
321 #elif defined(_WIN32)
322  A_CHAR( "1" "," "EPERM" "," "OSERR" ","
323  "2" "," "ENOENT" "," "OSERR" ","
324  "3" "," "ESRCH" "," "OSERR" ","
325  "4" "," "EINTR" "," "OSERR" ","
326  "5" "," "EIO" "," "OSERR" ","
327  "6" "," "ENXIO" "," "OSERR" ","
328  "7" "," "E2BIG" "," "OSERR" ","
329  "8" "," "ENOEXEC" "," "OSERR" ","
330  "9" "," "EBADF" "," "OSERR" ","
331  "10" "," "ECHILD" "," "OSERR" ","
332  "11" "," "EAGAIN" "," "OSERR" ","
333  "12" "," "ENOMEM" "," "OSERR" ","
334  "13" "," "EACCES" "," "OSERR" ","
335  "14" "," "EFAULT" "," "OSERR" ","
336  "16" "," "EBUSY" "," "OSERR" ","
337  "17" "," "EEXIST" "," "OSERR" ","
338  "18" "," "EXDEV" "," "OSERR" ","
339  "19" "," "ENODEV" "," "OSERR" ","
340  "20" "," "ENOTDIR" "," "OSERR" ","
341  "21" "," "EISDIR" "," "OSERR" ","
342  "23" "," "ENFILE" "," "OSERR" ","
343  "24" "," "EMFILE" "," "OSERR" ","
344  "25" "," "ENOTTY" "," "OSERR" ","
345  "27" "," "EFBIG" "," "OSERR" ","
346  "28" "," "ENOSPC" "," "OSERR" ","
347  "29" "," "ESPIPE" "," "OSERR" ","
348  "30" "," "EROFS" "," "OSERR" ","
349  "31" "," "EMLINK" "," "OSERR" ","
350  "32" "," "EPIPE" "," "OSERR" ","
351  "33" "," "EDOM" "," "OSERR" ","
352  "36" "," "EDEADLK" "," "OSERR" ","
353  "38" "," "ENAMETOOLONG" "," "OSERR" ","
354  "39" "," "ENOLCK" "," "OSERR" ","
355  "40" "," "ENOSYS" "," "OSERR" ","
356  "41" "," "ENOTEMPTY" "," "OSERR" ","
357  "22" "," "EINVAL" "," "OSERR" ","
358  "34" "," "ERANGE" "," "OSERR" ","
359  "42" "," "EILSEQ" "," "OSERR" ","
360  "80" "," "STRUNCATE" "," "OSERR" ","
361  "100" "," "EADDRINUSE" "," "OSERR" ","
362  "101" "," "EADDRNOTAVAIL" "," "OSERR" ","
363  "102" "," "EAFNOSUPPORT" "," "OSERR" ","
364  "103" "," "EALREADY" "," "OSERR" ","
365  "104" "," "EBADMSG" "," "OSERR" ","
366  "105" "," "ECANCELED" "," "OSERR" ","
367  "106" "," "ECONNABORTED" "," "OSERR" ","
368  "107" "," "ECONNREFUSED" "," "OSERR" ","
369  "108" "," "ECONNRESET" "," "OSERR" ","
370  "109" "," "EDESTADDRREQ" "," "OSERR" ","
371  "110" "," "EHOSTUNREACH" "," "OSERR" ","
372  "111" "," "EIDRM" "," "OSERR" ","
373  "112" "," "EINPROGRESS" "," "OSERR" ","
374  "113" "," "EISCONN" "," "OSERR" ","
375  "114" "," "ELOOP" "," "OSERR" ","
376  "115" "," "EMSGSIZE" "," "OSERR" ","
377  "116" "," "ENETDOWN" "," "OSERR" ","
378  "117" "," "ENETRESET" "," "OSERR" ","
379  "118" "," "ENETUNREACH" "," "OSERR" ","
380  "119" "," "ENOBUFS" "," "OSERR" ","
381  "120" "," "ENODATA" "," "OSERR" ","
382  "121" "," "ENOLINK" "," "OSERR" ","
383  "122" "," "ENOMSG" "," "OSERR" ","
384  "123" "," "ENOPROTOOPT" "," "OSERR" ","
385  "124" "," "ENOSR" "," "OSERR" ","
386  "125" "," "ENOSTR" "," "OSERR" ","
387  "126" "," "ENOTCONN" "," "OSERR" ","
388  "127" "," "ENOTRECOVERABLE" "," "OSERR" ","
389  "128" "," "ENOTSOCK" "," "OSERR" ","
390  "129" "," "ENOTSUP" "," "OSERR" ","
391  "130" "," "EOPNOTSUPP" "," "OSERR" ","
392  "131" "," "EOTHER" "," "OSERR" ","
393  "132" "," "EOVERFLOW" "," "OSERR" ","
394  "133" "," "EOWNERDEAD" "," "OSERR" ","
395  "134" "," "EPROTO" "," "OSERR" ","
396  "135" "," "EPROTONOSUPPORT" "," "OSERR" ","
397  "136" "," "EPROTOTYPE" "," "OSERR" ","
398  "137" "," "ETIME" "," "OSERR" ","
399  "138" "," "ETIMEDOUT" "," "OSERR" ","
400  "139" "," "ETXTBSY" "," "OSERR" ","
401  "140" "," "EWOULDBLOCK" "," "OSERR" ) EOS
402 
403 
404 #endif
405 
406  // end of BootstrapBulk()
407  nullptr );
408 #endif // !ALIB_RESOURCES_OMIT_DEFAULTS
409 
410 
413 
414  lib::boxing::BootstrapRegister<text::FFormat, lib::boxing::TMappedTo<time::DateTime>>(FFormat_DateTime);
421 
422 
423  }
424 
425  else if( phase == BootstrapPhases::PrepareConfig )
426  {
429  EnumRecords<Directory::SpecialFolder>::Bootstrap( *this, "SpecialFolder" );
430  }
431 
432  else if( phase == BootstrapPhases::Final )
433  {
434  Substring parser;
435  parser= GetResource( "Months" ); for( int i= 0 ; i < 12 ; ++i ) { months[i]= parser.ConsumeToken(','); }
436  parser= GetResource( "Days" ); for( int i= 0 ; i < 7 ; ++i ) { days[i]= parser.ConsumeToken(','); }
437 
438  parser= GetResource( "DurUnts" );
439  for( int i= 0 ; i < Units::SIZE_OF_UNITS ; ++i )
440  units[i]= parser.ConsumeToken(',');
441 
442  ALIB_ASSERT( units[Units::SIZE_OF_UNITS-1].IsNotEmpty() )
443  ALIB_ASSERT( parser.IsEmpty() )
444  }
445 }
446 
447 Exception CreateSystemException( const NCString& file, int line, const NCString& func, int errNo )
448 {
449  auto* enumRecord= enums::TryRecord( system::SystemErrors(errNo) );
450  if( enumRecord == nullptr )
451  return Exception( file, line, func, SystemErrors::UNKNOWN, errNo );
452 
453  return Exception( file, line, func, SystemErrors(errNo), // as exception
454  SystemErrors(errNo), // boxing the exception's name (!)
455  errNo );
456 }
457 
458 
459 
460 // #################################################################################################
461 // CalendarDateTime::Format
462 // #################################################################################################
463 AString& CalendarDateTime::Format( Substring format, AString& target, CurrentData targetData ) const
464 {
465  if ( targetData == CurrentData::Clear )
466  target.Reset();
467 
468  // this ensures that target is not nulled, as all other appends are NC-versions
469  target._("");
471 
472  while ( format.IsNotEmpty() )
473  {
474  // read n equal characters
475  int n= 1;
476  character c= format.ConsumeChar();
477  while ( format.ConsumeChar(c) )
478  ++n;
479 
480  switch (c)
481  {
482  case '\'': // single quotes
483  {
484  // one or more pairs of single quotes?
485  if ( n > 1 )
486  {
487  int pairs= n >> 1;
488  target.InsertChars<false>( '\'', pairs );
489  n-= (pairs << 1);
490  }
491 
492  // one single quote?
493  if ( n == 1 )
494  {
495  // search end
496  integer end= format.IndexOf( '\'' );
497  if ( end < 1 )
498  {
499  ALIB_WARNING( "SYSTEM", "Format Error: Missing single Quote" )
500  target << "Format Error: Missing single Quote" ;
501  return target;
502  }
503 
504  target._<false>( format, 0, end );
505  format.ConsumeChars<false>( end + 1 );
506  }
507 
508  } break;
509 
510  case 's': // second
511  target.template _<false>( aworx::Format( Second, n, nf ) );
512  break;
513 
514  case 'm': //minute
515  target._<false>( aworx::Format( Minute, n, nf ) );
516  break;
517 
518  case 'K': // hour 0..11
519  target._<false>( aworx::Format( Hour % 12, n, nf ) );
520  target._<false>( Hour < 12 ? " am" : " pm" );
521  break;
522 
523  case 'H': // hour 0..23
524  target._<false>( aworx::Format( Hour, n, nf ) );
525  break;
526 
527  case 'd': // day
528  if ( n <= 2 ) target._<false>( aworx::Format( Day, n, nf) );
529  else if ( n == 3 ) target._<false>( days[DayOfWeek], 0, 3 );
530  else target._<false>( days[DayOfWeek] );
531  break;
532 
533  case 'M': // month
534  if ( n <= 2 ) target._<false>( aworx::Format( Month, n, nf ) );
535  else if ( n == 3 ) target._<false>( months[Month-1], 0, 3 );
536  else target._<false>( months[Month-1] );
537  break;
538 
539  case 'y': // year
540  if ( n == 1 ) target._<false>( aworx::Format(Year, 1, nf) );
541  else if ( n == 2 ) target._<false>( aworx::Format(Year % 100, 2, nf) );
542  else target._<false>( aworx::Format(Year, n, nf) );
543  break;
544 
545  default: // otherwise: copy what was in
546  target.InsertChars<false>( c, n );
547  break;
548  }
549 
550  }
551 
552  return target;
553 }
554 
555 
556 
557 // #################################################################################################
558 // FFormat_DateTime
559 // #################################################################################################
560 #if !defined(ALIB_DOX)
561 DOX_MARKER([DOX_ALIB_BOXING_IFORMAT_DATETIME])
562 void FFormat_DateTime( const Box& box, const String& formatSpec, AString& target )
563 {
565  tct.Format( formatSpec.IsNotEmpty() ? formatSpec
566  : lib::SYSTEM.GetResource("DFMT"),
567  target );
568 }
569 DOX_MARKER([DOX_ALIB_BOXING_IFORMAT_DATETIME])
570 #endif
571 
572 
573 
574 } // namespace aworx::lib[::system]
575 
576 #if !defined(ALIB_DOX)
577 namespace strings {
578 
579 // #################################################################################################
580 // T_Append<DateTime::Duration>
581 // #################################################################################################
582 using namespace system;
583 
584 namespace {
585 
586  template<typename TChar>
587  void appendDateTime(TAString<TChar>& target, const DateTime::Duration pSrc)
588  {
589  using Duration= DateTime::Duration;
590  Duration src= pSrc;
591  auto nanos= src.InNanoseconds();
592  if( nanos == 0 )
593  {
594  target << units[Units::TS_ZERO];
595  return;
596  }
597 
598  if( nanos < 0 )
599  {
600  target << A_CHAR("- ");
601  src= Duration() - src;
602  }
603 
604  TNumberFormat<TChar> nf( TNumberFormat<TChar>::Global );
605  nf.FractionalPartWidth= 2;
606  int64_t v= src.InAbsoluteDays();
607  if( v >= 10 )
608  {
609  target << TFormat<TChar>( src.InDays(), &nf ) << units[Units::DayPlural];
610  return;
611  }
612 
613  if( v > 0 )
614  {
615  target << v << ( v != 1 ? units[Units::DayPlural]
616  : units[Units::DaySingular] );
617 
618  Duration cpy= src - ( Duration::FromAbsoluteDays(v) );
619 
620  target << ' ' << TFormat<TChar>( cpy.InHours(), &nf ) << units[Units::HourPlural];
621  return;
622  }
623 
624  v= src.InAbsoluteHours();
625  if( v > 0 )
626  {
627  target << v << ( v != 1 ? units[Units::HourPlural]
628  : units[Units::HourSingular] );
629 
630  Duration cpy= src - ( Duration::FromAbsoluteHours(v) );
631 
632  auto minutes= cpy.InAbsoluteMinutes();
633  target << ' ' << minutes << (minutes!= 1 ? units[Units::MinPlural]
634  : units[Units::MinSingular] );
635  return;
636  }
637 
638  v= src.InAbsoluteMinutes();
639  if( v > 0 )
640  {
641  target << v << ( v != 1 ? units[Units::MinPlural]
642  : units[Units::MinSingular] );
643 
644  Duration cpy= src - ( Duration::FromAbsoluteMinutes(v) );
645 
646  auto seconds= cpy.InAbsoluteSeconds();
647  target << ' ' << seconds << (seconds!= 1 ? units[Units::SecPlural]
648  : units[Units::SecSingular] );
649  return;
650  }
651 
652  v= src.InAbsoluteSeconds();
653  if( v > 0 )
654  {
655  target << TFormat<TChar>( src.InSeconds(), &nf ) << units[Units::SecPlural];
656  return;
657  }
658 
659  nf.DecMinimumFieldWidth= 3;
660 
661  auto val= src.InAbsoluteMilliseconds();
662  if( val >= 1 )
663  {
664  target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::MlSecPlural]
665  : units[Units::MlSecSingular] );
666  return;
667  }
668 
669  val= src.InAbsoluteMicroseconds();
670  if( val >= 1 )
671  {
672  target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::McSecPlural]
673  : units[Units::McSecSingular] );
674  return;
675  }
676 
677  val= src.InNanoseconds();
678  target << TFormat<TChar>(val,&nf) << ( val!= 1 ? units[Units::NSecPlural]
679  : units[Units::NSecSingular] );
680  return;
681  }
682 } //anonymous namespace
683 
684 
685 template<typename TChar>
686 void T_Append<time::DateTime::Duration,TChar>::operator()( TAString<TChar>& target, const time::DateTime::Duration src )
687 {
688  appendDateTime( target, src );
689 }
690 
691 template<typename TChar>
692 void T_Append<time::Ticks::Duration,TChar>::operator()( TAString<TChar>& target, const time::Ticks::Duration src)
693 {
694  // simply convert the ticks-duration to a DateTime duration and use its append function
695  appendDateTime( target, time::DateTime::Duration::FromNanoseconds( src.InNanoseconds() ));
696 }
697 
698 // Instantiations
699 template void T_Append<time::DateTime::Duration, nchar>::operator()( TAString<nchar>&, const time::DateTime::Duration );
700 template void T_Append<time::DateTime::Duration, wchar>::operator()( TAString<wchar>&, const time::DateTime::Duration );
701 template void T_Append<time::DateTime::Duration, xchar>::operator()( TAString<xchar>&, const time::DateTime::Duration );
702 template void T_Append<time::Ticks:: Duration, nchar>::operator()( TAString<nchar>&, const time::Ticks ::Duration );
703 template void T_Append<time::Ticks:: Duration, wchar>::operator()( TAString<wchar>&, const time::Ticks ::Duration );
704 template void T_Append<time::Ticks:: Duration, xchar>::operator()( TAString<xchar>&, const time::Ticks ::Duration );
705 
706 } // namespace aworx::lib[::strings]
707 #endif //!defined(ALIB_DOX)
708 
709 
710 }}// namespace [aworx::lib]
aworx::lib::strings::TSubstring::ConsumeChar
ALIB_WARNINGS_IGNORE_IF_CONSTEXPR TChar ConsumeChar()
Definition: substring.hpp:156
aworx::lib::system::CalendarDateTime::Minute
int Minute
Definition: calendar.hpp:74
aworx::lib::strings::TNumberFormat::Global
static TNumberFormat Global
Definition: numberformat.hpp:150
ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_W(TAppendable)
Definition: functions.inl:510
aworx::lib::Module::resourcePool
resources::ResourcePool * resourcePool
Definition: module.hpp:114
aworx::lib::integer
platform_specific integer
Definition: integers.hpp:49
aworx::lib::system::System
Definition: system.hpp:43
ALIB_WARNING
#define ALIB_WARNING(...)
Definition: tools.hpp:182
aworx::lib::strings::TSubstring::ConsumeChars
integer ConsumeChars(integer regionLength, TSubstring *target=nullptr)
Definition: substring.hpp:291
aworx::lib::ALibDistribution::CheckDistribution
ALIB_API void CheckDistribution(int alibVersion=ALIB_VERSION, uint64_t compilationFlags=ALIB_COMPILATION_FLAGS)
Definition: distribution.cpp:612
aworx::lib::system::CalendarDateTime::DayOfWeek
int DayOfWeek
Definition: calendar.hpp:86
aworx::lib::strings::TNumberFormat< character >::Computational
static TNumberFormat Computational
Definition: numberformat.hpp:164
format.hpp
aworx::lib::system::CalendarDateTime::Second
int Second
Definition: calendar.hpp:77
resources.hpp
aworx::character
lib::characters::character character
Type alias in namespace aworx.
Definition: characters.hpp:695
aworx::lib::enums::EnumRecords::Bootstrap
static void Bootstrap(TEnum element, TArgs &&... args) noexcept
aworx::lib::Module::BootstrapPhases
BootstrapPhases
Definition: module.hpp:78
aworx::lib::strings::TString::IsEmpty
constexpr bool IsEmpty() const
Definition: string.hpp:398
recordbootstrap.hpp
aworx::lib::SYSTEM
system::System SYSTEM
Definition: system.cpp:58
aworx::lib::system::CalendarDateTime::Day
int Day
Definition: calendar.hpp:68
aworx::lib::Module::BootstrapPhases::PrepareResources
numberformat.hpp
aworx::Format
lib::strings::TFormat< character > Format
Type alias in namespace aworx.
Definition: strings/fwds.hpp:305
serialization.hpp
aworx::lib::strings::TString< character >
aworx::lib::strings::TString::IsNotEmpty
constexpr bool IsNotEmpty() const
Definition: string.hpp:404
aworx::lib::strings::T_Append::operator()
void operator()(TAString< TChar > &target, const TAppendable &src)
aworx::lib::strings::TSubstring::ConsumeToken
TString< TChar > ConsumeToken(TChar separator=',')
Definition: substring.hpp:559
aworx::lib::strings::TAString::Reset
TAString & Reset()
Definition: astring.hpp:1304
aworx::lib::system::CalendarDateTime::Month
int Month
Definition: calendar.hpp:65
aworx::lib::CurrentData
CurrentData
Definition: commonenumdefs.hpp:112
aworx::lib::strings::TAString::InsertChars
TAString & InsertChars(TChar c, integer qty)
Definition: astring.hpp:1397
aworx::lib::Module::ResourceCategory
NCString ResourceCategory
Definition: module.hpp:172
aworx::lib
Definition: alox/alox.hpp:40
alib_precompile.hpp
aworx::lib::system::CalendarDateTime::Year
int Year
Definition: calendar.hpp:62
directory.hpp
ALIB_ASSERT
#define ALIB_ASSERT(cond)
Definition: tools.hpp:184
aworx::lib::strings::TNumberFormat< character >
ALIB_REVISION
#define ALIB_REVISION
Definition: modules.hpp:21
aworx::lib::system::Exceptions
Exceptions
Definition: systemerrors.hpp:281
aworx::lib::system::CalendarDateTime
Definition: calendar.hpp:58
aworx::lib::strings::TSubstring< character >
aworx::lib::strings::TFormat
Definition: format.hpp:84
aworx
Definition: alox/alox.hpp:40
aworx::lib::strings::TString::IndexOf
integer IndexOf(TChar needle, integer startIdx=0) const
Definition: string.hpp:850
results.hpp
aworx::lib::system::SystemErrors::UNKNOWN
Unknown Error.
aworx::ALIB
lib::ALibDistribution ALIB
Definition: distribution.cpp:125
aworx::lib::time::DateTime
Definition: datetime.hpp:38
aworx::lib::Module::BootstrapPhases::Final
The final initialization phase.
ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable)
Definition: functions.inl:502
aworx::lib::strings::TAString< character >
aworx::lib::resources::ResourcePool::BootstrapBulk
virtual void BootstrapBulk(const nchar *category,...)=0
A_CHAR
#define A_CHAR(STR)
ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_RESTORE
Definition: compilers.hpp:331
ALIB_ASSERT_ERROR
#define ALIB_ASSERT_ERROR(cond,...)
Definition: tools.hpp:185
aworx::lib::results::Exception
Definition: exception.hpp:129
aworx::lib::boxing::Box::Unbox
const TUnboxable Unbox() const
aworx::lib::strings::TAString::_
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
Definition: astring.hpp:1048
ALIB_BOXING_VTABLE_DEFINE
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition: vtable.inl:490
ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_N(TAppendable)
Definition: functions.inl:506
aworx::lib::system::SystemErrors
SystemErrors
Definition: systemerrors.hpp:28
aworx::lib::system::FFormat_DateTime
ALIB_API void FFormat_DateTime(const Box &self, const String &formatSpec, AString &target)
ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER
#define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER(Identifier)
Definition: vtable.inl:506
aworx::lib::strings::TCString< nchar >
distribution.hpp
ALIB_VERSION
#define ALIB_VERSION
Definition: modules.hpp:20
aworx::lib::Module::BootstrapPhases::PrepareConfig
system.hpp
aworx::lib::system::CalendarDateTime::Format
ALIB_API AString & Format(Substring format, AString &target, CurrentData targetData=CurrentData::Keep) const
Definition: system.cpp:463
aworx::lib::Module
Definition: module.hpp:74
ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE_X(TAppendable)
Definition: functions.inl:514
aworx::lib::system::System::bootstrap
virtual void bootstrap(BootstrapPhases phase, int argc, const char **argv, const wchar_t **wargv) override
Definition: system.cpp:102
aworx::Exception
lib::results::Exception Exception
Type alias in namespace aworx.
Definition: exception.hpp:532
time.hpp
calendar.hpp
aworx::lib::boxing::Box
Definition: box.inl:33
aworx::lib::system::CreateSystemException
Exception CreateSystemException(const NCString &file, int line, const NCString &func, int errNo)
Definition: system.cpp:447
aworx::lib::Module::GetResource
const String & GetResource(const NString &name)
Definition: module.hpp:462
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition: compilers.hpp:258
aworx::lib::system::CalendarDateTime::Hour
int Hour
Definition: calendar.hpp:71
substring.hpp
aworx::lib::enums::TryRecord
const T_EnumRecords< TEnum >::Type * TryRecord(TEnum element)
fwds.hpp
aworx::lib::CurrentData::Clear
Chooses to clear existing data.