ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
spaces.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_strings of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_STRINGS_UTIL_SPACES
9#define HPP_ALIB_STRINGS_UTIL_SPACES 1
10
11#if !defined (HPP_ALIB_STRINGS_STRING)
13#endif
14
15
16namespace alib { namespace strings { namespace util {
17
18
19/** ************************************************************************************************
20 * This is a simple class that provides a string full of spaces.
21 * This string may be used to avoid repeated memory allocations/initializations and/or repeated
22 * method invocations when a software interfaces to libraries that either allow to write
23 * a string or a single character (i.e. <c>std::ostream</c>).
24 **************************************************************************************************/
25class Spaces
26{
27 public:
28 /** ****************************************************************************************
29 * Receives a narrow string full of spaces. Its length depends on previous calls and on
30 * parameter \p minLength, which defaults to \c 128 and usually should \b not be
31 * specified much higher.
32 *
33 * @param minLength The minimum length. Defaults to \c 128.
34 * @return A static string filled with spaces.
35 ******************************************************************************************/
37 static NString& GetN(integer minLength= 128);
38
39 /** ****************************************************************************************
40 * Receives a narrow string full of spaces. Its length depends on previous calls and on
41 * parameter \p minLength, which defaults to \c 128 and usually should \b not be
42 * specified much higher.
43 *
44 * @param minLength The minimum length. Defaults to \c 128.
45 * @return A static string filled with spaces.
46 ******************************************************************************************/
48 static WString& GetW(integer minLength= 128);
49
50 /** ****************************************************************************************
51 * Receives a narrow string full of spaces. Its length depends on previous calls and on
52 * parameter \p minLength, which defaults to \c 128 and usually should \b not be
53 * specified much higher.
54 *
55 * @param minLength The minimum length. Defaults to \c 128.
56 * @return A static string filled with spaces.
57 ******************************************************************************************/
58 static String& Get(integer minLength= 128)
59 {
60 #if !ALIB_CHARACTERS_WIDE
61 return Spaces::GetN( minLength );
62 #else
63 return Spaces::GetW( minLength );
64 #endif
65 }
66
67 /** ****************************************************************************************
68 * Write the given number of spaces to the narrow-character ostream.
69 * @param os The output stream to write to.
70 * @param qty The quantity of spaces to write.
71 ******************************************************************************************/
73 static void Write( std::basic_ostream<char >& os, integer qty );
74
75 #if ALIB_CHARACTERS_NATIVE_WCHAR || defined(ALIB_DOX)
76 /** ************************************************************************************
77 * Write the given number of spaces to the ostream of type \c wchar_t.
78 *
79 * \par Availability
80 * This method is available only if compiler symbol
81 * \ref ALIB_CHARACTERS_NATIVE_WCHAR evaluates to \c true (\b 1). This is due to
82 * the fact that otherwise, the internal wide string buffer of spaces
83 * is either of type \c char16_t or \c char32_t, the one of both that is
84 * incompatible with output streams of character type \c wchar_t.<br>
85 * Consequently, this method must not be used (and replaced by a custom
86 * implementation) in the case that a software is supposed to compile successfully
87 * with a non-default setting of compiler symbol \ref ALIB_CHARACTERS_SIZEOF_WCHAR.
88 *
89 * @param os The output stream to write to.
90 * @param qty The quantity of spaces to write.
91 **************************************************************************************/
93 static void Write( std::basic_ostream<wchar_t>& os, integer qty );
94 #endif
95};
96
97}} // namespace alib[::strings::util]
98
99/// Type alias in namespace \b alib.
101
102} // namespace alib
103
104#endif // HPP_ALIB_STRINGS_UTIL_SPACES
static ALIB_API void Write(std::basic_ostream< wchar_t > &os, integer qty)
static ALIB_API WString & GetW(integer minLength=128)
Definition spaces.cpp:39
static String & Get(integer minLength=128)
Definition spaces.hpp:58
static ALIB_API void Write(std::basic_ostream< char > &os, integer qty)
Definition spaces.cpp:49
static ALIB_API NString & GetN(integer minLength=128)
Definition spaces.cpp:31
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286