ALib C++ Framework
by
Library Version: 2511 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/// #"alib_manual_modules_impludes;import/include headers".
7///
8/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
9/// Published under #"mainpage_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 #"alib_strings_assembly_ttostring;appended"
20/// to #"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 #"lang::Alignment" allows left-, right- or center-aligning.
26/// the contents of the field.
27///
28/// \note
29/// In case, the module \alib_boxing is not available, the field content parameter will be of
30/// type <c>const String&</c> and this class is available after the inclusion of the header
31/// #"F;ALib.Strings.H".
32///
33/// \note
34/// Otherwise, a different implementation is used, which becomes available only with the
35/// inclusion of the header #"F;ALib.Boxing.H". That version stores a #"Box" instead
36/// of a string type, and this way is able to place any type which disposes about an
37/// implementation of box-function #"FAppend".<br>
38///
39/// \note
40/// Therefore, it is mandatory that for any type that is used with this class to be formatted
41/// in a field, this box-function has to be implemented.
42/// As documented with that interface, for types that are
43/// #"alib_strings_assembly_ttostring;appendable" to \b %AString objects already, all that
44/// is needed is to use macro #"ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE"
45/// with the type in the bootstrap section of an application.
46/// @tparam TChar The #"alib_characters_chars;character type" of the \b AString that
47/// instances can be "applied" to.
48template<typename TChar>
49struct TField
50{
51 public:
52 Box theContent; ///< The content of the field. If module
53 ///< \alib_boxing_nl is not available, this field
54 ///< is of type <c>const TString<TChar>&</c>
55 integer fieldWidth; ///< The width of the field.
56 lang::Alignment alignment; ///< The alignment of the contents within the field.
57 TChar padChar; ///< The characters used for padding the contents within the field.
58
59 /// Constructor. Copies the parameters.
60 ///
61 /// @param content The contents of the field. If the module \alib_boxing is not
62 /// available, this field is of type <c>const TString<TChar>&</c>,
63 /// otherwise of type #"Box".
64 /// @param pWidth The width of the field
65 /// @param pAlignment The alignment of the contents within the field.
66 /// Defaults to #"Alignment::Right"
67 /// Other options are #"Alignment::Left" and #"Alignment::Center".
68 /// @param fillChar The character used to fill the field up to its size.
69 /// Defaults to ' ' (space).
70 TField( Box content,
71 integer pWidth,
73 TChar fillChar = ' ' )
74 : theContent(content)
75 , fieldWidth(pWidth)
76 , alignment(pAlignment)
77 , padChar(fillChar) {}
78};
79
80// todo: for DOXYGEN eyes, this needs to be moved to APPENDABLES namespace
81
82#if DOXYGEN
83namespace APPENDABLES {
84#endif
85
86/// Specialization of functor #"AppendableTraits" for type \b %TField.
87/// @tparam TChar Character type of the target \b AString.
88/// @tparam TAllocator Allocator type of the target \b AString.
89template<typename TChar, typename TAllocator> struct AppendableTraits<TField<TChar> ,TChar,TAllocator>
90{
91 /// Writes the contents of \p{field} according to its specification.
92 /// @param target The AString to append \p{src} to.
93 /// @param field The field instance (usually a temporary).
95};
96#if DOXYGEN
97} // namespace alib::strings[::APPENDABLES]
98#endif
99
100extern template ALIB_DLL void AppendableTraits<TField <nchar>, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const TField <nchar>& );
101extern template ALIB_DLL void AppendableTraits<TField <wchar>, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const TField <wchar>& );
102
103} // namespace [alib::strings]
104
105ALIB_EXPORT namespace alib {
106/// Type alias in namespace \b alib.
108
109/// Type alias in namespace \b alib.
111
112/// Type alias in namespace \b alib.
114}
115#endif
#define ALIB_DLL
Definition alib.inl:573
#define ALIB_EXPORT
Definition alib.inl:562
Alignment
Denotes Alignments.
@ Right
Chooses right alignment.
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.inl:149
boxing::Box Box
Type alias in namespace alib.
Definition box.inl:1135
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=' ')