8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
24 import ALib.Strings.Calendar;
30 import ALib.Camp.Base;
47 fmtCI.
Format( formatSpec.IsNotEmpty() ? formatSpec
51 :
A_CHAR(
"[@ sf:sl from ''ya'' by ''ta'']")
64 while ( format.IsNotEmpty() ) {
68 while ( format.ConsumeChar(c) )
77 target.InsertChars<NC>(
'\'', pairs );
84 integer end= format.IndexOf(
'\'' );
86 ALIB_WARNING(
"ALIB",
"Format Error: Missing single Quote" )
87 target <<
"Format Error: Missing closing single quote character <'>" ;
91 target._<NC>( format, 0, end );
92 format.ConsumeChars<NC>( end + 1 );
101 if ( format.ConsumeChar(
'f') ) {
102 if(
ci.File ) target._<NC>(
ci.File );
103 else target._<NC>(
"<NULL>" );
106 if ( format.ConsumeChar(
'l') ) {
108 target._<NC>(
ci.Line );
111 if ( format.ConsumeChar(
'm') ) {
113 target._<NC>(
ci.Func );
117 target.InsertChars<NC>( c, n );
121 #if !ALIB_SINGLE_THREADED
129 if ( format.ConsumeChar(
'n') ) {
130 target._<NC>( thread ? thread->GetName()
140 if ( format.ConsumeChar(
'i') ) {
141 if ( thread ) target._<NC>( thread->GetID() );
145 else target._<NC>(
A_CHAR(
"<Null>") );
151 if ( format.ConsumeChar(
'c') ) {
152 if constexpr (
sizeof(std::thread::id) ==
sizeof(uint16_t) ) {
153 uint16_t nativeID= 0;
154 memcpy(&nativeID, &
ci.ThreadID, 2);
155 target._<NC>(
"0x")._<NC>(
Hex(nativeID, 4));
157 if constexpr (
sizeof(std::thread::id) ==
sizeof(uint32_t) ) {
158 uint32_t nativeID= 0;
159 memcpy(&nativeID, &
ci.ThreadID, 4);
160 target._<NC>(
"0x")._<NC>(
Hex(nativeID, 8));
162 if constexpr (
sizeof(std::thread::id) ==
sizeof(uint64_t) ) {
163 uint64_t nativeID= 0;
164 memcpy(&nativeID, &
ci.ThreadID, 8);
165 target._<NC>(
"0x")._<NC>(
Hex(nativeID, 16));
172 if ( format.ConsumeChar(
'a') ) {
173 target._<NC>(
ci.ThreadID );
177 target.InsertChars<NC>( c, n );
187 if ( format.ConsumeChar(
'f') ) {
197 if (!
ci.TypeInfo) target._<NC>(
204 else target << lang::DbgTypeDemangler(*
ci.TypeInfo).Get();
210 if ( format.ConsumeChar(
'n') ) {
237 if ( format.ConsumeChar(
'a') ) {
239 target._<NC>(
ci.Func )._<NC>(
"()");
242 target._<NC>( *
ci.TypeInfo )._<NC>(
"::");
243 target._<NC>(
ci.Func )._<NC>(
"()");
250 target.InsertChars<NC>( c, n );
255 target.InsertChars<NC>( c, n );
269DOX_MARKER([DOX_BOXING_IFORMAT_DATETIME])
271 strings::util::CalendarDateTime tct( box.Unbox<
DateTime>() );
272 tct.Format( formatSpec.IsNotEmpty() ? formatSpec
276 :
A_CHAR(
"yyyy-MM-dd HH:mm:ss" ),
280DOX_MARKER([DOX_BOXING_IFORMAT_DATETIME])
294 double v= double(val);
297 if( unit < ByteSizeUnits::IEC_END) {
299 divisor= double(1024);
301 loopEnd= int(unit - ByteSizeUnits::SI);
302 divisor= double(1000);
305 for (
int i = 0; i < loopEnd; ++i)
313 if( val < byteLimit )
318 if( val < byteLimit * factor)
319 return std::make_pair(
double(val) /
double(factor), unit );
328 target.EnsureRemainingCapacity(128);
330 auto magnitude= (unit == ByteSizeUnits::IEC) ? getMagnitude(val, magnitudeThreshold, 1024ull)
331 : getMagnitude(val, magnitudeThreshold, 1000ull);
333 if( magnitude.second == ByteSizeUnits::IEC )
334 target <<
Dec( val,
nullptr );
337 target.VBuffer(), target.Length(), 0, nf) );
340 target << unitSeparator;
341 target << (magnitude.second + unit);
345 auto result= getMagnitude( Value, MagnitudeThreshold, 1024 );
346 result.second+= ByteSizeUnits::IEC;
351 auto result= getMagnitude( Value, MagnitudeThreshold, 1000 );
352 result.second+= ByteSizeUnits::SI;
357double ByteSizeSI ::ConvertTo(
ByteSizeUnits unit) {
return convertTo(Value, unit); };
360}
namespace alib::strings {
362void AppendableTraits< format::ByteSizeSI, character, lang::HeapAllocator>::operator()( AString& target,
const format::ByteSizeSI src )
364 format::FormatByteSize( target, src.Value, src.MagnitudeThreshold, src.UnitSeparator,
365 format::ByteSizeUnits::SI, * format::BYTESIZE_NUMBER_FORMAT );
367void AppendableTraits< format::ByteSizeIEC, character, lang::HeapAllocator>::operator()( AString& target,
const format::ByteSizeIEC src )
369 format::FormatByteSize( target, src.Value, src.MagnitudeThreshold, src.UnitSeparator,
370 format::ByteSizeUnits::IEC, * format::BYTESIZE_NUMBER_FORMAT );
const String & GetResource(const NString &name)
TAString & _(const TAppendable &src)
static ALIB_DLL Thread * Get(std::thread::id nativeID)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNING(domain,...)
#define ALIB_WARNINGS_IGNORE_NOTHING_RETURNED
void typeName(const detail::VTable *vtable, AString &result)
@ Clear
Chooses to clear existing data.
ALIB_DLL integer WriteFloat(double value, TChar *buffer, integer idx, int minWidth, const TNumberFormat< TChar > &nf)
strings::TDec< character > Dec
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class Basecamp.
NLocalString< 2048 > NString2K
Type alias name for TLocalString<nchar,2048>.
time::DateTime DateTime
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TNumberFormat< character > NumberFormat
Type alias in namespace alib.
threads::Thread Thread
Type alias in namespace alib.
strings::THex< character > Hex
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
lang::CallerInfo CallerInfo
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.