ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
appendables.inl
Go to the documentation of this file.
1
2//==================================================================================================
3/// \file
4/// This header-file is part of module \alib_strings of the \aliblong.
5///
6/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
7/// Published under \ref mainpage_license "Boost Software License".
8//==================================================================================================
9ALIB_EXPORT namespace alib { namespace strings {
10
11//##################################################################################################
12// struct AppendableTraits: fundamental types
13//##################################################################################################
14
15// Faking all template specializations of namespace strings for doxygen into namespace
16// strings::APPENDABLES to keep the documentation of namespace string clean!
17#if DOXYGEN
18namespace APPENDABLES {
19#endif
20
21/// Specialization of functor \alib{strings;AppendableTraits} for type \c bool.
22template<typename TChar, typename TAllocator> struct AppendableTraits<bool ,TChar,TAllocator>
23{
24 /// Writes the words "true" or "false" to the given AString.
25 /// @param target The \b AString that \b Append was invoked on.
26 /// @param b The boolean to write to \p{target}.
27 void operator()( TAString<TChar,TAllocator>& target, bool b )
28 { target.template _<NC>( b ? "true" : "false" ); }
29};
30
31/// Specialization of functor \alib{strings;AppendableTraits} for type \c int8_t.
32template<typename TChar, typename TAllocator> struct AppendableTraits<int8_t ,TChar,TAllocator>
33{
34 /// Uses function \alib{strings;detail::WriteDecSigned} with
35 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
36 /// @param target The \b AString that \b Append was invoked on.
37 /// @param value The value to write.
38 void operator()( TAString<TChar,TAllocator>& target, int8_t value )
40};
41
42/// Specialization of functor \alib{strings;AppendableTraits} for type \c uint8_t.
43template<typename TChar, typename TAllocator> struct AppendableTraits<uint8_t ,TChar,TAllocator>
44{
45 /// Uses function \alib{strings;detail::WriteDecUnsigned} with
46 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
47 /// @param target The \b AString that \b Append was invoked on.
48 /// @param value The value to write.
49 void operator()( TAString<TChar,TAllocator>& target, uint8_t value )
51};
52
53/// Specialization of functor \alib{strings;AppendableTraits} for type \c int16_t.
54template<typename TChar, typename TAllocator> struct AppendableTraits<int16_t ,TChar,TAllocator>
55{
56 /// Uses function \alib{strings;detail::WriteDecSigned} with
57 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
58 /// @param target The \b AString that \b Append was invoked on.
59 /// @param value The value to write.
60 void operator()( TAString<TChar,TAllocator>& target, int16_t value )
62
63};
64
65/// Specialization of functor \alib{strings;AppendableTraits} for type \c uint16_t.
66template<typename TChar, typename TAllocator> struct AppendableTraits<uint16_t ,TChar,TAllocator>
67{
68 /// Uses function \alib{strings;detail::WriteDecUnsigned} with
69 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
70 /// @param target The \b AString that \b Append was invoked on.
71 /// @param value The value to write.
72 void operator()( TAString<TChar,TAllocator>& target, uint16_t value )
74
75};
76
77/// Specialization of functor \alib{strings;AppendableTraits} for type \c int32_t.
78template<typename TChar, typename TAllocator> struct AppendableTraits<int32_t ,TChar,TAllocator>
79{
80 /// Uses function \alib{strings;detail::WriteDecSigned} with
81 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
82 /// @param target The \b AString that \b Append was invoked on.
83 /// @param value The value to write.
84 void operator()( TAString<TChar,TAllocator>& target, int32_t value )
86
87};
88
89/// Specialization of functor \alib{strings;AppendableTraits} for type \c uint32_t.
90template<typename TChar, typename TAllocator> struct AppendableTraits<uint32_t ,TChar,TAllocator>
91{
92 /// Uses function \alib{strings;detail::WriteDecUnsigned} with
93 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
94 /// @param target The \b AString that \b Append was invoked on.
95 /// @param value The value to write.
96 void operator()( TAString<TChar,TAllocator>& target, uint32_t value )
98
99};
100
101
102/// Specialization of functor \alib{strings;AppendableTraits} for type \c int64_t.
103template<typename TChar, typename TAllocator> struct AppendableTraits<int64_t ,TChar,TAllocator>
104{
105 /// Uses function \alib{strings;detail::WriteDecSigned} with
106 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
107 /// @param target The \b AString that \b Append was invoked on.
108 /// @param value The value to write.
109 void operator()( TAString<TChar,TAllocator>& target, int64_t value );
110};
111
112/// Specialization of functor \alib{strings;AppendableTraits} for type \c uint64_t.
113template<typename TChar, typename TAllocator> struct AppendableTraits<uint64_t ,TChar,TAllocator>
114{
115 /// Uses function \alib{strings;detail::WriteDecUnsigned} with
116 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
117 /// @param target The \b AString that \b Append was invoked on.
118 /// @param value The value to write.
119 void operator()( TAString<TChar,TAllocator>& target, uint64_t value );
120};
121
122/// Specialization of functor \alib{strings;AppendableTraits} for type \c intGap_t.
123template<typename TChar, typename TAllocator> struct AppendableTraits<intGap_t ,TChar,TAllocator>
124{
125 /// Uses function \alib{strings;detail::WriteDecSigned} with
126 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
127 /// @param target The \b AString that \b Append was invoked on.
128 /// @param value The value to write.
131};
132
133/// Specialization of functor \alib{strings;AppendableTraits} for type \c uintGap_t.
134template<typename TChar, typename TAllocator> struct AppendableTraits<uintGap_t ,TChar,TAllocator>
135{
136 /// Uses function \alib{strings;detail::WriteDecUnsigned} with
137 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
138 /// @param target The \b AString that \b Append was invoked on.
139 /// @param value The value to write.
142};
143
144/// Specialization of functor \alib{strings;AppendableTraits} for type \c float.
145template<typename TChar, typename TAllocator> struct AppendableTraits<float ,TChar,TAllocator>
146{
147 /// Uses function \alib{strings;detail::WriteFloat} with
148 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
149 /// @param target The \b AString that \b Append was invoked on.
150 /// @param value The value to write.
151 void operator()( TAString<TChar,TAllocator>& target, float value)
152 { AppendableTraits<double, TChar,TAllocator>()( target, double(value) ); }
153};
154
155/// Specialization of functor \alib{strings;AppendableTraits} for type \c double.
156template<typename TChar, typename TAllocator> struct AppendableTraits<double ,TChar,TAllocator>
157{
158 /// Uses function \alib{strings;detail::WriteFloat} with
159 /// \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
160 /// @param target The \b AString that \b Append was invoked on.
161 /// @param value The value to write.
162 void operator()( TAString<TChar,TAllocator>& target, double value);
163};
164
165/// Specialization of functor \alib{strings;AppendableTraits} for type <c>long double</c>.
166template<typename TChar, typename TAllocator> struct AppendableTraits<long double ,TChar,TAllocator>
167{
168 /// Casts the value "down" to just \c double and uses function \alib{strings;detail::WriteFloat}
169 /// with \alib{strings;TNumberFormat<TChar>::Computational} to write the number.
170 ///
171 /// @param target The \b AString that \b Append was invoked on.
172 /// @param value The value to write.
173 void operator()( TAString<TChar,TAllocator>& target, long double value)
174 { AppendableTraits<double, TChar,TAllocator>()( target, double(value) ); }
175};
176
177
178#if ALIB_DEBUG
179/// Specialization of functor \alib{strings;AppendableTraits} for type \c std::type_info.<br>
180/// Available only in debug-compilations.
181template<typename TChar, typename TAllocator> struct AppendableTraits<std::type_info ,TChar,TAllocator>
182{
183 /// Writes the demangled type name.
184 /// @param target The \b AString that \b Append was invoked on.
185 /// @param type The type to write to \p{target}.
186 void operator()( TAString<TChar,TAllocator>& target, const std::type_info& type );
187};
188#endif
189
190#if ALIB_EXT_LIB_THREADS_AVAILABLE
191/// Specialization of functor \alib{strings;AppendableTraits} for type \c std::thread::id.<br>
192template<typename TChar, typename TAllocator> struct AppendableTraits<std::thread::id ,TChar,TAllocator>
193{
194 /// Writes the thread information.
195 /// @param target The \b AString that \b Append was invoked on.
196 /// @param type The thread ID to write to \p{target}.
197 void operator()( TAString<TChar,TAllocator>& target, const std::thread::id& type );
198};
199#endif
200
201/// Specialization of functor \alib{strings;AppendableTraits} for type \alib{lang;CallerInfo}.<br>
202/// This functor writes all information available in a standard format.
203/// A more flexible way is provided with formatter type \alib{format;FMTCallerInfo} that
204/// defines a format string to pick certain fields of the \b CallerInfo.
205/// This format specification is also availble in placeholders of type
206/// \alib{format;FormatterPythonStyle}.
207template<typename TChar, typename TAllocator> struct AppendableTraits<lang::CallerInfo ,TChar,TAllocator>
208{
209 /// Writes thread and source location.
210 /// @param target The \b AString that \b Append was invoked on.
211 /// @param ci The caller information to write to \p{target}.
213};
214
215/// An enumeration of the list of "units" needed when describing time-spans, for example,
216/// in the term <c>"3 days 2,4 hours"</c>.
217enum class DayTimeUnits
218{
219 TS_ZERO , ///< In \b DT_UNITS, this defaults to <b></b>.
220 DayPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
221 DaySingular , ///< In \b DT_UNITS, this defaults to <b></b>.
222 HourPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
223 HourSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
224 MinPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
225 MinSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
226 SecPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
227 SecSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
228 MlSecPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
229 MlSecSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
230 McSecPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
231 McSecSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
232 NSecPlural , ///< In \b DT_UNITS, this defaults to <b></b>.
233 NSecSingular , ///< In \b DT_UNITS, this defaults to <b></b>.
234 SIZE_OF_UNITS , ///< Stop marker
235};
236
237/// A list of "units" needed when describing time-spans, for example, in the term
238/// <b>"3 days, 2 hours and 1 second"</b>.
239/// This is used with the specialization of the traits-functor \alib{strings;AppendableTraits}
240/// for type \alib{time;TimePointBase::Duration;DateTime::Duration}.
241///
242/// If module \alib_camp is not included in the \alibbuild, the values default to:
243/// \snippet "strings/astring.cpp" DT_UNITS_DEFAULTS
244/// In case the module is included, the same values are resourced in #alib::BASECAMP under
245/// key <c>"DurUnts"</c>. In both cases a user might change this during bootstrap.
247
248/// Specialization of functor \alib{strings;AppendableTraits} for type
249/// \alib{time;TimePointBase::Duration;DateTime::Duration}.
250template<typename TChar, typename TAllocator> struct AppendableTraits<time::DateTime::Duration ,TChar,TAllocator>
251{
252 /// Appends a human-readable string representation of objects of templated inner type
253 /// \alib{time;TimePointBase::Duration} of type \alib{time;DateTime}.
254 ///
255 /// \see
256 /// For details of the conversion, see
257 /// \ref anchor_T_Append_TimePointBase_Duration "documentation of sibling method"
258 /// for type \b %Ticks, which shares this method's implementation.
259 ///
260 /// @param target The \b AString that \b Append was invoked on.
261 /// @param duration The duration to append.
262 void operator()( TAString<TChar,TAllocator>& target, const time::DateTime::Duration duration );
263};
264
265/// Specialization of functor \alib{strings;AppendableTraits} for type
266/// \alib{time;TimePointBase::Duration;Ticks::Duration}.
267template<typename TChar, typename TAllocator> struct AppendableTraits<time::Ticks::Duration ,TChar,TAllocator>
268{
269 /// \anchor anchor_T_Append_TimePointBase_Duration
270 /// Appends a human-readable string representation of objects of templated inner type
271 /// \alib{time;TimePointBase::Duration} of type \alib{time;Ticks}.
272 ///
273 /// Depending on the length of the duration, a different human-readable time unit or combination
274 /// of it is used. The following rules are checked from top to bottom:
275 /// - If zero, resource string \b "TS_ZERO" is written.
276 /// - If negative, a minus sign <c>'-'</c> is written and the value is negated.
277 /// - If greater than 10 days, writes the number of days as floating point number.
278 /// - If between 1 and 10 days, writes the integral number of days and the additional hours as
279 /// floating point number.
280 /// - If greater than an hour, writes the integral number of hours and integral minutes.
281 /// - If greater than a minute, writes the integral number of minutes and integral seconds.
282 /// - If greater than a second, writes the number of seconds as floating point number.
283 /// - If greater than a millisecond, writes the number of milliseconds as floating point number.
284 /// - If greater than a microsecond, writes the number of microseconds as floating point number.
285 /// - If greater than a nanosecond, writes the number of nanoseconds as floating point number.
286 ///
287 /// All floating point numbers are written with two digits fractional precision.<br>
288 /// The unit symbols are read from the \ref alib_mod_resources "resources" of module class
289 /// \alib{camp;Basecamp}. The list is given with resource name <b>UNITS</b>.
290 ///
291 /// @param target The \b AString that \b Append was invoked on.
292 /// @param duration The duration to append.
293 void operator()( TAString<TChar,TAllocator>& target, const time::Ticks::Duration duration );
294};
295
296#if !ALIB_SINGLE_THREADED
297
298/// Specialization of functor \alib{strings;AppendableTraits} for type \alib{threads;Thread}.
300 /// Appends the name and ID of the thread.
301 /// @param target The \b AString that \b Append was invoked on.
302 /// @param thread The thread to append.
304};
305
306/// Specialization of functor \alib{strings;AppendableTraits} for type \alib{threads;Thread}.
308 /// Appends the name and ID of the thread.
309 /// @param target The \b AString that \b Append was invoked on.
310 /// @param thread The thread to append.
312};
313#endif
314
315
316// Faking all template specializations of namespace strings for doxygen into namespace
317// strings::APPENDABLES to keep the documentation of namespace string clean!
318#if DOXYGEN
319}
320#endif
321
322}} // namespace [alib::strings]
#define ALIB_DLL
Definition alib.inl:503
#define ALIB_EXPORT
Definition alib.inl:497
@ McSecSingular
In DT_UNITS, this defaults to .
@ HourSingular
In DT_UNITS, this defaults to .
@ SecSingular
In DT_UNITS, this defaults to .
@ NSecSingular
In DT_UNITS, this defaults to .
@ MlSecSingular
In DT_UNITS, this defaults to .
@ MinPlural
In DT_UNITS, this defaults to .
@ HourPlural
In DT_UNITS, this defaults to .
@ MlSecPlural
In DT_UNITS, this defaults to .
@ DayPlural
In DT_UNITS, this defaults to .
@ SecPlural
In DT_UNITS, this defaults to .
@ MinSingular
In DT_UNITS, this defaults to .
@ McSecPlural
In DT_UNITS, this defaults to .
@ TS_ZERO
In DT_UNITS, this defaults to .
@ DaySingular
In DT_UNITS, this defaults to .
@ NSecPlural
In DT_UNITS, this defaults to .
String DT_UNITS[size_t(DayTimeUnits::SIZE_OF_UNITS)]
lang::intGap_t intGap_t
Type alias in namespace alib.
Definition integers.inl:155
characters::wchar wchar
Type alias in namespace alib.
threads::Thread Thread
Type alias in namespace alib.
Definition thread.inl:387
lang::uintGap_t uintGap_t
Type alias in namespace alib.
Definition integers.inl:158
characters::nchar nchar
Type alias in namespace alib.
lang::CallerInfo CallerInfo
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
void operator()(TAString< TChar, TAllocator > &target, bool b)
void operator()(TAString< TChar, TAllocator > &target, double value)
void operator()(TAString< TChar, TAllocator > &target, float value)
void operator()(TAString< TChar, TAllocator > &target, int16_t value)
void operator()(TAString< TChar, TAllocator > &target, int32_t value)
void operator()(TAString< TChar, TAllocator > &target, int64_t value)
void operator()(TAString< TChar, TAllocator > &target, int8_t value)
void operator()(TAString< TChar, TAllocator > &target, intGap_t value)
void operator()(TAString< TChar, TAllocator > &target, const lang::CallerInfo &ci)
void operator()(TAString< TChar, TAllocator > &target, long double value)
void operator()(TAString< TChar, TAllocator > &target, const std::thread::id &type)
void operator()(TAString< TChar, TAllocator > &target, const std::type_info &type)
ALIB_DLL void operator()(TAString< nchar, lang::HeapAllocator > &target, const threads::Thread &thread)
ALIB_DLL void operator()(TAString< wchar, lang::HeapAllocator > &target, const threads::Thread &thread)
void operator()(TAString< TChar, TAllocator > &target, const time::DateTime::Duration duration)
void operator()(TAString< TChar, TAllocator > &target, const time::Ticks::Duration duration)
void operator()(TAString< TChar, TAllocator > &target, uint16_t value)
void operator()(TAString< TChar, TAllocator > &target, uint32_t value)
void operator()(TAString< TChar, TAllocator > &target, uint64_t value)
void operator()(TAString< TChar, TAllocator > &target, uint8_t value)
void operator()(TAString< TChar, TAllocator > &target, uintGap_t value)