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