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