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