ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
strings_tfield.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_boxing of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8#if ALIB_STRINGS
9
10ALIB_EXPORT namespace alib::strings {
11
12// Note:
13// If boxing is not included in the ALib Build, then an alternative version of this class
14// is declared and implemented directly in module Strings.
15
16/// Used to create temporary objects which are #"alib_strings_assembly_ttostring;appended"
17/// to #"^AString" instances.<br>
18///
19/// Appends the given object to the AString using a defined 'field'-width.
20/// If the contents of the field is shorter than parameter \p{width} specifies, the field is
21/// filled with a corresponding amount of \p{padChar} characters.<br>
22/// Parameter \p{alignment} of type #"lang::Alignment" allows left-, right- or center-aligning.
23/// the contents of the field.
24///
25/// \note
26/// In case, the module \alib_boxing is not available, the field content parameter will be of
27/// type <c>const String&</c> and this class is available after the inclusion of the header
28/// #"F;ALib.Strings.H".
29///
30/// \note
31/// Otherwise, a different implementation is used, which becomes available only with the
32/// inclusion of the header #"F;ALib.Boxing.H". That version stores a #"Box" instead
33/// of a string type, and this way is able to place any type which disposes about an
34/// implementation of box-function #"FAppend".<br>
35///
36/// \note
37/// Therefore, it is mandatory that for any type that is used with this class to be formatted
38/// in a field, this box-function has to be implemented.
39/// As documented with that interface, for types that are
40/// #"alib_strings_assembly_ttostring;appendable" to #"%AString" objects already, all that
41/// is needed is to use macro #"ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE"
42/// with the type in the bootstrap section of an application.
43/// @tparam TChar The #"alib_characters_chars;character type" of the #"%AString" that
44/// instances can be "applied" to.
45template<typename TChar>
46struct TField {
47 public:
48 Box theContent; ///< The content of the field. If module
49 ///< \alib_boxing_nl is not available, this field
50 ///< is of type <c>const TString<TChar>&</c>
51 integer fieldWidth; ///< The width of the field.
52 lang::Alignment alignment; ///< The alignment of the contents within the field.
53 TChar padChar; ///< The characters used for padding the contents within the field.
54
55 /// Constructor. Copies the parameters.
56 ///
57 /// @param content The contents of the field. If the module \alib_boxing is not
58 /// available, this field is of type <c>const TString<TChar>&</c>,
59 /// otherwise of type #"Box".
60 /// @param pWidth The width of the field
61 /// @param pAlignment The alignment of the contents within the field.
62 /// Defaults to #"Alignment::Right"
63 /// Other options are #"Alignment::Left" and #"Alignment::Center".
64 /// @param fillChar The character used to fill the field up to its size.
65 /// Defaults to ' ' (space).
66 TField( Box content,
67 integer pWidth,
69 TChar fillChar = ' ' )
70 : theContent(content)
71 , fieldWidth(pWidth)
72 , alignment(pAlignment)
73 , padChar(fillChar) {}
74};
75
76
77#if DOXYGEN
78namespace APPENDABLES {
79#endif
80
81/// Specialization of functor #"AppendableTraits" for type #"%TField".
82/// @tparam TChar Character type of the target #"%AString".
83/// @tparam TAllocator Allocator type of the target #"%AString".
84template<typename TChar, typename TAllocator>
85struct AppendableTraits<TField<TChar> ,TChar,TAllocator> {
86 /// Writes the contents of \p{field} according to its specification.
87 /// @param target The AString to append \p{src} to.
88 /// @param field The field instance (usually a temporary).
90};
91#if DOXYGEN
92} // namespace alib::strings[::APPENDABLES]
93#endif
94
95extern template ALIB_DLL void AppendableTraits<TField <nchar>, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const TField <nchar>& );
96extern template ALIB_DLL void AppendableTraits<TField <wchar>, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const TField <wchar>& );
97
98} // namespace [alib::strings]
99
100ALIB_EXPORT namespace alib {
101/// Type alias in namespace #"%alib".
103
104/// Type alias in namespace #"%alib".
106
107/// Type alias in namespace #"%alib".
109}
110#endif
#define ALIB_DLL
#define ALIB_EXPORT
Alignment
Denotes Alignments.
@ Right
Chooses right alignment.
Definition alox.cpp:14
strings::TField< nchar > NField
Type alias in namespace #"%alib".
strings::TField< wchar > WField
Type alias in namespace #"%alib".
characters::wchar wchar
Type alias in namespace #"%alib".
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
boxing::Box Box
Type alias in namespace #"%alib".
Definition box.hpp:1128
strings::TField< character > Field
Type alias in namespace #"%alib".
characters::nchar nchar
Type alias in namespace #"%alib".
void operator()(TAString< TChar, TAllocator > &target, const TField< TChar > &field)
TField(Box content, integer pWidth, lang::Alignment pAlignment=lang::Alignment::Right, TChar fillChar=' ')