ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
format.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of module \alib_strings of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_STRINGS_FORMAT
9#define HPP_ALIB_STRINGS_FORMAT 1
10#pragma once
11
12#if !defined(HPP_ALIB_STRINGS_TASTRING_INLINING)
13# error "ALib sources with ending '.inl' must not be included from outside."
14#endif
15
16#if ALIB_BOXING
17# include "alib/boxing/boxing.hpp"
18#endif
19
20#include <limits>
21
22namespace alib { namespace strings {
23
24//==================================================================================================
25/// This is a type purely made to be \ref alib_strings_assembly_ttostring "appended" to objects of
26/// type \alib{strings;TAString;AString}.
27/// Various constructors accept integer and floating point values, along with formatting options.
28/// The specialization of functor \alib{strings;T_Append} will use a given (or defaulted) instance
29/// of class \alib{strings;TNumberFormat;NumberFormat} to format the encapsulated value and
30/// append the result to the \b %AString in question.
31///
32/// \note
33/// Within the same header file that this class in declared in, there are several
34/// specializations of functor \alib{strings;T_Append} defined for plain integer and
35/// floating point types. These specializations create an object of this type, providing the
36/// value only, hence, using this classes constructor's default values. The number format
37/// used as default by the constructors of this class is
38/// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
39/// As a result, the application of such core types, as in:
40/// \snippet "DOX_ASTRING_APPEND.cpp" DOX_APPEND_FORMAT1
41/// which produces:
42/// \verbinclude "DOX_APPEND_FORMAT1.txt"
43///
44/// \note
45/// does \b not use a locale specific number format. Instead, it uses one that is exchangeable
46/// between applications independent of the locale setting of the executing machine.<br>
47/// Consequently, for locale specific output, an object of this class needs to be appended
48/// along with a locale enabled instance of \b %NumberFormat. For example:
49/// \snippet "DOX_ASTRING_APPEND.cpp" DOX_APPEND_FORMAT2
50/// which - dependent on the current local setting - might produce:
51/// \verbinclude "DOX_APPEND_FORMAT2.txt"
52///
53///
54/// <b>Inner Types:</b><br>
55/// Besides accepting plain number types, this class in addition aggregates several public inner
56/// types, namely
57/// - \alib{strings::TFormat;Tab},
58/// - \alib{strings::TFormat;Field},
59/// - \alib{strings::TFormat;Escape},
60/// - \alib{strings::TFormat;Bin},
61/// - \alib{strings::TFormat;Hex},
62/// - \alib{strings::TFormat;Oct}, and
63/// - \alib{strings::TFormat;Fill}.
64///
65///
66/// Each of these classes provide certain formatting options, which are implemented by a
67/// corresponding specialization of functor \alib{strings;T_Append}.
68///
69/// \note The types are not 'physically' related to this class.
70/// Instead, placing them here as public inner types has been purely a design decision.
71/// Rationales were to make them more easily findable being aggregated here, to
72/// depopulate the namespace and finally to make the using code more readable.
73///
74/// <b>Details on Formats:</b><br>
75/// Details on the options of formatting integer and floating point numbers are documented
76/// with class
77/// \alib{strings;TNumberFormat;NumberFormat}.
78///
79/// @tparam TChar The \ref alib_characters_chars "character type" of the \b AString that
80/// instances can be "applied" to.
81//==================================================================================================
82template<typename TChar>
83class TFormat
84{
85 public:
86
87 // #############################################################################################
88 // Inner types
89 // #############################################################################################
90
91 //==============================================================================================
92 /// Implements a temporary object which is \ref alib_strings_assembly_ttostring "appended"
93 /// to instances of type \alib{strings;TAString;AString}.
94 ///
95 /// Appends \e tab characters (as provided) to reach a certain length (aka tabulator position)
96 /// of the \p{target}. The tab position is referenced to an optionally given \p{reference} value
97 /// which might be the start of the string or the position of the last newline. If this
98 /// parameter is negative, the last newline characters are searched from the end of the
99 /// string backwards.<br>
100 /// Referring to that as position 0, the tab position is then located at the next multiple
101 /// of parameter \p{tabSize}, after having added \p{minPad} tab characters.
102 //==============================================================================================
103 struct Tab
104 {
105 public:
106 /// The tab positions are multiples of this value.
108
109 /// The reference length of the AString which is taken as relative tab position
110 /// (instead of the beginning of the string). If -1, the target %AString is
111 /// searched backwards for the last newline and this position is used as the
112 /// reference.
114
115 /// The minimum pad characters to add. Defaults to 1.
117
118 /// The character to insert to reach the tab position. Normally this is the space
119 /// character ' '.
120 TChar tabChar;
121
122 /// Constructor. Copies the parameters.
123 ///
124 /// @param size The tab positions are multiples of this parameter.
125 /// @param referenceIdx The reference index marking the start of the actual line.
126 /// If -1, the last new-line character is searched from the end of
127 /// the string backwards, and used. Defaults to 0.
128 /// @param minPadChars The minimum pad characters to add. Defaults to 1.
129 /// @param fillChar The character to insert to reach the tab position.
130 /// Defaults to ' ' (space).
131 Tab( integer size, integer referenceIdx = 0, integer minPadChars= 1, TChar fillChar= ' ' )
132 : tabSize(size), reference(referenceIdx), minPad(minPadChars), tabChar(fillChar)
133 {}
134 };
135
136 //==============================================================================================
137 /// Used to create temporary objects which are \ref alib_strings_assembly_ttostring "appended"
138 /// to \alib{strings;TAString;AString} instances.<br>
139 ///
140 /// Appends the given object to the AString using a defined 'field'-width.
141 /// If the contents of the field is shorter than parameter \p{width} specifies, the field is
142 /// filled with a corresponding amount of \p{padChar} characters.<br>
143 /// Parameter \p{alignment} of type
144 /// \alib{lang;Alignment} allows left-, right- or center-aligning.
145 /// the contents of the field.
146 ///
147 /// \note
148 /// In case, module \alib_boxing is not available, the field content
149 /// parameter will be of type <c>const String&</c>.<br>
150 /// Otherwise, box-function \alib{boxing;FAppend} will be invoked on
151 /// the given box internally to receive the string representation.
152 ///
153 /// \note
154 /// Therefore, it is mandatory, that for any type that is used with this class
155 /// to be formatted in a field, this box-function has to be implemented. As
156 /// documented with that interface, for types that are
157 /// \ref alib_strings_assembly_ttostring "appendable" to \b %AString
158 /// objects already, all that is needed is to use macro
159 /// \ref ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE with the type in the bootstrap
160 /// section of an application.
161 //==============================================================================================
162 struct Field
163 {
164 public:
165 #if ALIB_BOXING || DOXYGEN
166 Box theContent; ///< The content of the field. If module
167 ///< \alib_boxing_nl is not available, this field
168 ///< is of type <c>const TString<TChar>&</c>
169 #else
171 #endif
172 integer fieldWidth; ///< The width of the field.
173 lang::Alignment alignment; ///< The alignment of the contents within the field.
174 TChar padChar; ///< The characters used for padding the contents within the field.
175
176 /// Constructor. Copies the parameters.
177 ///
178 /// @param content The contents of the field. If module \alib_boxing is not
179 /// available, this field is of type <c>const TString<TChar>&</c>,
180 /// otherwise of type \alib{boxing;Box}.
181 /// @param pWidth The width of the field
182 /// @param pAlignment The alignment of the contents within the field.
183 /// Defaults to
184 /// \alib{lang;Alignment;Alignment::Right}
185 /// Other options are
186 /// \alib{lang;Alignment;Alignment::Left} and
187 /// \alib{lang;Alignment;Alignment::Center}.
188 /// @param fillChar The character used to fill the field up to its size.
189 /// Defaults to ' ' (space).
191 #if ALIB_BOXING
192 Box content,
193 #else
194 const TString<TChar>& content,
195 #endif
196
197 integer pWidth,
199 TChar fillChar = ' ' )
200 #if ALIB_BOXING
201 : theContent(content),
202 #else
203 : theContent(content.IsNotNull() ? content : EMPTY_STRING ),
204 #endif
205 fieldWidth(pWidth),
206 alignment(pAlignment),
207 padChar(fillChar)
208 {}
209
210 };
211
212 //==============================================================================================
213 /// Implements a temporary object which is \ref alib_strings_assembly_ttostring "appended"
214 /// to instances of type \alib{strings;TAString;AString}.
215 ///
216 /// Escapes non-printable characters in the given region, or reversely converts such escaped
217 /// characters to their ASCII values.
218 ///
219 /// The characters converted are
220 /// <c>'\\\\'</c>, <c>'\\r'</c>, <c>'\\n'</c>, <c>'\\t'</c>, <c>'\\a'</c>,
221 /// <c>'\\b'</c>, <c>'\\v'</c>, <c>'\\f'</c>, <c>'\\e'</c> and <c>'"'</c>.
222 ///
223 /// If the new region length is needed to be known, it can be calculated as the sum of
224 /// the old region length and the difference of the string's length before and after the
225 /// operation.
226 //==============================================================================================
227 struct Escape
228 {
229 public:
230 /// The direction of conversion: \b Switch::On escapes ascii characters, while
231 /// \b Switch::Off converts escaped strings to ascii codes.
233
234 /// The start of the region to convert.
236
237 /// The length of the region to convert.
239
240
241 /// Constructor. Copies the parameters.
242 ///
243 /// @param escape \b Switch::On escapes ascii characters (the default),
244 /// \b Switch::Off converts escaped strings to ascii codes.
245 /// @param regionStart The start of the region to convert.
246 /// @param regionLength The length of the region to convert.
247 Escape( lang::Switch escape= lang::Switch::On, integer regionStart = 0, integer regionLength =MAX_LEN )
248 : pSwitch(escape), startIdx(regionStart), length(regionLength)
249 {}
250 };
251
252
253 //==============================================================================================
254 /// Implements a temporary object which can be \ref alib_strings_assembly_ttostring "appended"
255 /// to instances of type \alib{strings;TAString;AString}.
256 ///
257 /// Appends an integral value in binary format.
258 ///
259 /// \see
260 /// Class \alib{strings;TNumberFormat} for more information on formatting options for binary
261 /// number output.
262 //==============================================================================================
263 struct Bin
264 {
265 public:
266 uint64_t theValue; ///< The value to write.
267 int theWidth; ///< The minimum width of the number to write.
268 ///< Defaults to \c 0
269 ///< which denotes to choose the value of field
270 ///< \alib{strings;TNumberFormat::BinFieldWidth;NumberFormat::BinFieldWidth}.
271 TNumberFormat<TChar>* nf; ///< The number format to use. Defaults to \c nullptr which chooses
272 ///< \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
273
274 /// Constructor, taking the value and formatting parameters.
275 ///
276 /// @tparam TIntegral Value type which has to be statically castable to \c std::uint64_t.
277 /// @param value The value to write.
278 /// @param overrideWidth Defaults to \c 0 which
279 /// denotes to choose the value of field
280 /// \alib{strings;TNumberFormat::BinFieldWidth;NumberFormat::BinFieldWidth}.
281 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
282 /// the static singleton found in
283 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
284 template<typename TIntegral>
285 Bin( TIntegral value,
286 int overrideWidth= 0,
287 TNumberFormat<TChar>* numberFormat = nullptr )
288 : theValue (static_cast<uint64_t>(value))
289 , theWidth (overrideWidth)
290 , nf (numberFormat) {}
291
292 /// Constructor, taking the value and a just an object of type \b %NumberFormat.
293 ///
294 /// @tparam TIntegral Value type which has to be statically castable to \c std::uint64_t.
295 /// @param value The value to write.
296 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
297 /// the static singleton found in
298 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
299 template<typename TIntegral>
300 Bin( TIntegral value,
301 TNumberFormat<TChar>* numberFormat )
302 : theValue (static_cast<uint64_t>(value))
303 , theWidth (0)
304 , nf (numberFormat) {}
305
306 };
307
308 //==============================================================================================
309 /// Implements a temporary object which is \ref alib_strings_assembly_ttostring "appended"
310 /// to instances of type \alib{strings;TAString;AString}.
311 ///
312 /// Appends an integral value in hexadecimal format.
313 ///
314 /// \see
315 /// Class \alib{strings;TNumberFormat} for more information on formatting options for
316 /// hexadecimal number output.
317 //==============================================================================================
318 struct Hex
319 {
320 public:
321 uint64_t theValue; ///< The value to write.
322 int theWidth; ///< The minimum width of the number to write.
323 ///< Defaults to \c 0
324 ///< which denotes to choose the value of field
325 ///< \alib{strings;TNumberFormat::HexFieldWidth;NumberFormat::HexFieldWidth}.
326 TNumberFormat<TChar>* nf;///< The number format to use. Defaults to \c nullptr which chooses
327 ///< \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
328
329 /// Constructor, taking the value and formatting parameters.
330 ///
331 /// @tparam TIntegral Value type which has to be statically castable to \c std::uint64_t.
332 /// @param value The value to write.
333 /// @param overrideWidth Defaults to \c 0 which
334 /// denotes to choose the value of field
335 /// \alib{strings;TNumberFormat::HexFieldWidth;NumberFormat::HexFieldWidth}.
336 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
337 /// the static singleton found in
338 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
339 template<typename TIntegral>
340 Hex( TIntegral value,
341 int overrideWidth= 0,
342 TNumberFormat<TChar>* numberFormat = nullptr )
343 : theValue (static_cast<uint64_t>(value))
344 , theWidth (overrideWidth)
345 , nf (numberFormat) {}
346
347 /// Constructor, taking the value and a just an object of type \b %NumberFormat.
348 ///
349 /// @param value The value to write.
350 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
351 /// the static singleton found in
352 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
353 template<typename TIntegral>
354 Hex( TIntegral value,
355 TNumberFormat<TChar>* numberFormat )
356 : theValue (static_cast<uint64_t>(value))
357 , theWidth (0)
358 , nf (numberFormat) {}
359 };
360
361 //==============================================================================================
362 /// Implements a temporary object which is \ref alib_strings_assembly_ttostring "appended"
363 /// to instances of type \alib{strings;TAString;AString}.
364 ///
365 /// Appends an integral value in octal format.
366 ///
367 /// \see
368 /// Class \alib{strings;TNumberFormat} for more information on formatting options for octal
369 /// number output.
370 //==============================================================================================
371 struct Oct
372 {
373 public:
374 uint64_t theValue; ///< The value to write.
375 int theWidth; ///< The minimum width of the number to write.
376 ///< Defaults to \c 0
377 ///< which denotes to choose the value of field
378 ///< \alib{strings;TNumberFormat::OctFieldWidth;NumberFormat::OctFieldWidth}.
379 TNumberFormat<TChar>* nf; ///< The number format to use. Defaults to \c nullptr which chooses
380 ///< \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
381
382 /// Constructor, taking the value and formatting parameters.
383 ///
384 /// @tparam TIntegral Value type which has to be statically castable to \c std::uint64_t.
385 /// @param value The value to write.
386 /// @param overrideWidth Defaults to \c 0 which
387 /// denotes to choose the value of field
388 /// \alib{strings;TNumberFormat::OctFieldWidth;NumberFormat::OctFieldWidth}.
389 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
390 /// the static singleton found in
391 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
392 template<typename TIntegral>
393 Oct( TIntegral value,
394 int overrideWidth= 0,
395 TNumberFormat<TChar>* numberFormat = nullptr )
396 : theValue (static_cast<uint64_t>(value))
397 , theWidth (overrideWidth)
398 , nf (numberFormat) {}
399
400 /// Constructor, taking the value and a just an object of type \b %NumberFormat.
401 ///
402 /// @tparam TIntegral Value type which has to be statically castable to \c std::uint64_t.
403 /// @param value The value to write.
404 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
405 /// the static singleton found in
406 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
407 template<typename TIntegral>
408 Oct( TIntegral value,
409 TNumberFormat<TChar>* numberFormat )
410 : theValue (static_cast<uint64_t>(value))
411 , theWidth (0)
412 , nf (numberFormat) {}
413 };
414
415 //==============================================================================================
416 /// Implements a temporary object which is \ref alib_strings_assembly_ttostring "appended"
417 /// to instances of type \alib{strings;TAString;AString}.<br>
418 /// Appends a given number of characters.
419 //==============================================================================================
420 struct Fill
421 {
422 TChar fillChar; ///< The character to write.
423 int count; ///< The number of characters to write.
424
425 /// Constructor.
426 /// @param pFillChar The character to write.
427 /// @param pCount The number of characters to write.
428 Fill( TChar pFillChar, int pCount )
429 : fillChar(pFillChar)
430 , count (pCount) {}
431 };
432
433 // #############################################################################################
434 // Fields (class Format)
435 // #############################################################################################
436
437
438 /// The union to hold an integral or floating point value provided with the different
439 /// constructors.
440 union
441 {
442 int64_t value; ///< The value when using constructor with signed integer types.
443 double fpValue; ///< The value when using constructor with type double.
444 } v; ///< The data
445
446 TNumberFormat<TChar>* nf; ///< The number format to use. Defaults to \c nullptr which chooses
447 ///< the static singleton found in
448 ///< \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
449
450 int width; ///< The minimum width of the number to write.
451 ///< Defaults to \c 0 which denotes to choose the value of field
452 ///< \alib{strings;TNumberFormat::DecMinimumFieldWidth;NumberFormat::DecMinimumFieldWidth}.
453 int valueType; ///< Flag witch value to use (1= sInt, 2=uInt, 3=fp )
454
455
456#if DOXYGEN
457 /// Constructor. Stores parameters.
458 ///
459 /// @tparam T The type of argument \p{value}. Deduced by the compiler. Integer and
460 /// floating-point types are accepted
461 /// @param value The value to write.
462 /// @param overrideWidth Defaults to \c 0 which
463 /// denotes to choose the value of field
464 /// \alib{strings;TNumberFormat::DecMinimumFieldWidth;NumberFormat::DecMinimumFieldWidth}.
465 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
466 /// the static singleton found in
467 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
468 template<typename T>
469 inline
471 int overrideWidth= 0,
472 TNumberFormat<TChar>* numberFormat = nullptr );
473
474 /// Alternative constructor that omits parameter \p{width} and set it to \c 0.
475 ///
476 /// @tparam T The type of argument \p{value}. Deduced by the compiler. Integer and
477 /// floating-point types are accepted
478 /// @param value The value to write.
479 /// @param numberFormat The number format to use. Defaults to \c nullptr which chooses
480 /// the static singleton found in
481 /// \alib{strings;TNumberFormat::Computational;NumberFormat::Computational}.
482 template<typename T>
483 inline
485 TNumberFormat<TChar>* numberFormat = nullptr );
486
487#else
488 template<typename TInteger, ATMP_T_IF( int, std::numeric_limits<TInteger>::is_integer) = 0 >
489 TFormat( TInteger value,
490 int overrideWidth= 0,
491 TNumberFormat<TChar>* numberFormat = nullptr )
492 : nf (numberFormat)
493 , width (overrideWidth)
494 , valueType( std::numeric_limits<TInteger>::is_signed ? 1 : 2 )
495 { v.value= static_cast<int64_t>(value); }
496
497 template<typename TInteger, ATMP_T_IF( int, std::numeric_limits<TInteger>::is_integer) = 0 >
498 TFormat( TInteger value,
499 TNumberFormat<TChar>* numberFormat = nullptr )
500 : nf (numberFormat)
501 , width (0)
502 , valueType( std::numeric_limits<TInteger>::is_signed ? 1 : 2 )
503 { v.value= static_cast<int64_t>(value); }
504
505 template<typename TFloat, ATMP_T_IF( int, ATMP_EQ(TFloat, double)
506 || ATMP_EQ(TFloat, float ) )= 0 >
507 TFormat( TFloat value,
508 int overrideWidth= 0,
509 TNumberFormat<TChar>* numberFormat = nullptr )
510 : nf (numberFormat)
511 , width (overrideWidth)
512 , valueType( 3 )
513 { v.fpValue= static_cast<double>(value); }
514
515 template<typename TFloat, ATMP_T_IF( int, ATMP_EQ(TFloat, double)
516 || ATMP_EQ(TFloat, float ) )= 0 >
517 TFormat( TFloat value,
518 TNumberFormat<TChar>* numberFormat = nullptr )
519 : nf (numberFormat)
520 , width ( 0 )
521 , valueType( 3 )
522 { v.fpValue= static_cast<double>(value); }
523#endif // DOXYGEN
524
525
526}; // class format
527
528
529
530// #################################################################################################
531// Corresponding specializations of struct T_Append
532// #################################################################################################
533
534// Faking all template specializations of namespace strings for doxygen into namespace
535// strings::APPENDABLES to keep the documentation of namespace string clean!
536#if DOXYGEN
537 namespace APPENDABLES {
538#endif
539
540/// Specialization of functor \alib{strings;T_Append} for type \c Format.
541template<typename TChar, typename TAllocator> struct T_Append<TFormat<TChar> ,TChar,TAllocator>
542{
543 //==============================================================================================
544 /// Appends a string representation of the value encapsulated in the given \b Format value.
545 ///
546 /// @param target The \b AString that \b Append was invoked on.
547 /// @param fmt The format object.
548 //==============================================================================================
550};
551
552/// Specialization of functor \alib{strings;T_Append} for type \c Format::Tab.
553template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Tab ,TChar,TAllocator>
554{
555 //==============================================================================================
556 /// Appends tabulator characters to the given string.
557 ///
558 /// @param target The \b AString that \b Append was invoked on.
559 /// @param tab The object to append.
560 //==============================================================================================
561 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Tab& tab);
562};
563
564/// Specialization of functor \alib{strings;T_Append} for type \c Format::Field.
565template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Field ,TChar,TAllocator>
566{
567 //==============================================================================================
568 /// Appends a field with the adjusted boxed content to the given string.
569 ///
570 /// @param target The \b AString that \b Append was invoked on.
571 /// @param field The object to append.
572 //==============================================================================================
573 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Field& field);
574};
575
576
577/// Specialization of functor \alib{strings;T_Append} for type \c Format::Escape.
578template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Escape ,TChar,TAllocator>
579{
580 //==============================================================================================
581 /// Escapes or un-escapes the characters in the given string.
582 ///
583 /// @param target The \b AString that \b Append was invoked on.
584 /// @param esc The object to append.
585 //==============================================================================================
587};
588
589
590
591
592/// Specialization of functor \alib{strings;T_Append} for type \c Format::Bin.
593template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Bin ,TChar,TAllocator>
594{
595 //==============================================================================================
596 /// Appends a string representation of objects of type \alib{strings;TFormat::Bin;Format::Bin}.
597 ///
598 /// @param target The \b AString that \b Append was invoked on.
599 /// @param fmt The format object.
600 //==============================================================================================
601 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Bin& fmt );
602};
603
604/// Specialization of functor \alib{strings;T_Append} for type \c Format::Hex.
605template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Hex ,TChar,TAllocator>
606{
607 //==============================================================================================
608 /// Appends a string representation of objects of type \alib{strings;TFormat::Hex;Format::Hex}.
609 ///
610 /// @param target The \b AString that \b Append was invoked on.
611 /// @param fmt The format object.
612 //==============================================================================================
613 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Hex& fmt );
614};
615
616/// Specialization of functor \alib{strings;T_Append} for type \c Format::Oct.
617template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Oct ,TChar,TAllocator>
618{
619 //==============================================================================================
620 /// Appends a string representation of objects of type \alib{strings;TFormat::Oct;Format::Oct}.
621 ///
622 /// @param target The \b AString that \b Append was invoked on.
623 /// @param fmt The format object.
624 //==============================================================================================
625 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Oct& fmt );
626};
627
628/// Specialization of functor \alib{strings;T_Append} for type \c Format::Fill.
629template<typename TChar, typename TAllocator> struct T_Append<typename TFormat<TChar>::Fill ,TChar,TAllocator>
630{
631 //==============================================================================================
632 /// Appends objects of type \alib{strings;TFormat::Fill;Format::Fill}.
633 /// @param target The \b AString that \b Append was invoked on.
634 /// @param fmt The format object.
635 //==============================================================================================
636 void operator()( TAString<TChar,TAllocator>& target, const typename TFormat<TChar>::Fill& fmt );
637};
638// Faking all template specializations of namespace strings for doxygen into namespace
639// strings::APPENDABLES to keep the documentation of namespace string clean!
640#if DOXYGEN
641}
642#endif
643
644}} // namespace [alib::strings]
645
646#endif // HPP_ALIB_STRINGS_FORMAT
647
union alib::strings::TFormat::@0 v
The data.
double fpValue
The value when using constructor with type double.
Definition format.inl:443
TFormat(T value, TNumberFormat< TChar > *numberFormat=nullptr)
TNumberFormat< TChar > * nf
Definition format.inl:446
int valueType
Flag witch value to use (1= sInt, 2=uInt, 3=fp )
Definition format.inl:453
int64_t value
The value when using constructor with signed integer types.
Definition format.inl:442
TFormat(T value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
#define ATMP_EQ( T, TEqual)
Definition tmp.hpp:27
#define ATMP_T_IF(T, Cond)
Definition tmp.hpp:49
#define ALIB_BOXING
Definition alib.hpp:200
Switch
Denotes if sth. is switched on or off.
@ On
Switch it on, switched on, etc.
Alignment
Denotes Alignments.
@ Right
Chooses right alignment.
static constexpr integer MAX_LEN
The maximum length of an ALib string.
Definition string.hpp:31
Definition alib.cpp:69
constexpr const String EMPTY_STRING
An empty string of the default character type.
Definition string.hpp:2529
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
void operator()(TAString< TChar, TAllocator > &target, const TFormat< TChar > &fmt)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Bin &fmt)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Escape &esc)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Field &field)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Fill &fmt)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Hex &fmt)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Oct &fmt)
void operator()(TAString< TChar, TAllocator > &target, const typename TFormat< TChar >::Tab &tab)
uint64_t theValue
The value to write.
Definition format.inl:266
TNumberFormat< TChar > * nf
Definition format.inl:271
Bin(TIntegral value, TNumberFormat< TChar > *numberFormat)
Definition format.inl:300
Bin(TIntegral value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
Definition format.inl:285
Escape(lang::Switch escape=lang::Switch::On, integer regionStart=0, integer regionLength=MAX_LEN)
Definition format.inl:247
integer startIdx
The start of the region to convert.
Definition format.inl:235
integer length
The length of the region to convert.
Definition format.inl:238
integer fieldWidth
The width of the field.
Definition format.inl:172
Field(Box content, integer pWidth, lang::Alignment pAlignment=lang::Alignment::Right, TChar fillChar=' ')
Definition format.inl:190
TChar padChar
The characters used for padding the contents within the field.
Definition format.inl:174
lang::Alignment alignment
The alignment of the contents within the field.
Definition format.inl:173
TChar fillChar
The character to write.
Definition format.inl:422
int count
The number of characters to write.
Definition format.inl:423
Fill(TChar pFillChar, int pCount)
Definition format.inl:428
uint64_t theValue
The value to write.
Definition format.inl:321
Hex(TIntegral value, TNumberFormat< TChar > *numberFormat)
Definition format.inl:354
TNumberFormat< TChar > * nf
NumberFormat::Computational.
Definition format.inl:326
Hex(TIntegral value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
Definition format.inl:340
Oct(TIntegral value, TNumberFormat< TChar > *numberFormat)
Definition format.inl:408
uint64_t theValue
The value to write.
Definition format.inl:374
Oct(TIntegral value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
Definition format.inl:393
TNumberFormat< TChar > * nf
NumberFormat::Computational.
Definition format.inl:379
integer minPad
The minimum pad characters to add. Defaults to 1.
Definition format.inl:116
Tab(integer size, integer referenceIdx=0, integer minPadChars=1, TChar fillChar=' ')
Definition format.inl:131
integer tabSize
The tab positions are multiples of this value.
Definition format.inl:107