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