ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
stringnzt.inl
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-2025 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace strings {
9
10//==================================================================================================
11/// This is rather a helper-class than a genuine string class. While derived from class \b String,
12/// no extension of its interface is offered. Instead, the templated constructor is limited to
13/// accepting only string-types that are not zero-terminated.
14///
15/// The class is designed to be used to create API interfaces (i.e., overloaded methods) that accept
16/// zero-terminated strings of type #"TCString;CString" independently of
17/// non-zero-terminated strings: If two overloaded methods accepted type \c String and \c CString
18/// alternatively, compilation would be ambiguous because the \b String version would accept
19/// zero-terminated strings as well. Therefore, overloaded methods rather must accept this class
20/// and \b CString.
21///
22/// \see
23/// Details and a quick sample are given in chapter
24/// #"alib_strings_nzt" of the
25/// #"alib_mod_strings;Programmer's Manual" of module \alib_strings_nl.
26///
27/// @tparam TChar The #"alib_characters_chars;character type" of this string.
28/// Alias names of this class using different character types are provided
29/// with in namespace #"alib" with type definitions
30/// #"StringNZT",
31/// #"NStringNZT",
32/// #"WStringNZT", and
33/// #"XStringNZT".
34//==================================================================================================
35template<typename TChar>
36class TStringNZT : public TString<TChar>
37{
38 public:
39 /// Constructor accepting a pointer to a character array and a string length.
40 ///
41 /// @param pBuffer Pointer to the start of the character string to represent.
42 /// @param pLength The length of the character string to represent.
43 constexpr
44 TStringNZT( const TChar* pBuffer, integer pLength )
45 : TString<TChar>( pBuffer, pLength) {}
46
47
48// Doxygen (V1.15) would create identical entries in its tag-file, so those are not reachable.
49// On the other hand, it complains if the methods are not doxed. So, we hide them from doxygen.
50#if DOXYGEN
51 /// Templated \b implicit constructor accepting a \c const reference to an object of a
52 /// type that satisfies the concept #"IsImplicitArraySource" while it does
53 /// \b not satisfy the concept #"IsImplicitZTArraySource",
54 /// In other words, this implicit constructor accepts only non-zero-terminated character
55 /// arrays.
56 ///
57 /// Internally another version exists, which accepts types that satisfy the concept
58 /// #"IsExplicitArraySource".<br>
59 ///
60 /// @tparam T The type of the given \p{src}.
61 /// @param src The source of the string data to copy.
62 template <typename T>
63 constexpr TStringNZT(const T src);
64#else
65 template <typename T>
66 requires ( characters::IsImplicitArraySource <T, TChar>
68 constexpr TStringNZT(const T& src)
69 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
70 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
71
72 template <typename T>
73 requires ( characters::IsImplicitArraySource <T, TChar>
75 constexpr TStringNZT(const T* src)
76 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
77 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
78
79 template <typename T>
80 requires characters::IsExplicitArraySource <T, TChar>
81 constexpr explicit TStringNZT(const T& src)
82 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
83 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
84#endif
85
86 /// Templated \b implicit constructor accepting a \c const pointer to an object of a
87 /// type that satisfies the concept #"IsExplicitArraySource".
88 ///
89 /// @tparam T The type of the given \p{src}.
90 /// @param src The source of the string data to copy.
91 template <typename T>
92 requires characters::IsExplicitArraySource <T, TChar>
93 constexpr explicit TStringNZT(const T* src)
94 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
95 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
96
97 /// Templated \b implicit constructor accepting a mutable reference to an object of a
98 /// type that satisfies the concept #"IsMutableArraySource".
99 ///
100 /// @tparam T The type of the given \p{src}.
101 /// @param src The source of the string data to copy.
102 template<typename T>
104 constexpr explicit TStringNZT( T& src)
105 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
106 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
107
108 /// Templated \b implicit constructor accepting a mutable pointer to an object of a
109 /// type that satisfies the concept #"IsMutableArraySource".
110 ///
111 /// @tparam T The type of the given \p{src}.
112 /// @param src The source of the string data to copy.
113 template<typename T>
115 constexpr explicit TStringNZT( T* src)
116 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
117 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
118
119}; // class TStringNZT
120
121//##################################################################################################
122// Specializations of ArrayTraits for class TStringNZT
123//##################################################################################################
124} namespace characters {
125#if !DOXYGEN
126template<typename TChar>
127struct ArrayTraits<strings::TStringNZT<TChar>, TChar>
128{
129 static constexpr Policy Access = Policy::Implicit;
130 static constexpr Policy Construction = Policy::NONE;
131 static constexpr const TChar* Buffer(const strings::TString<TChar>& src) {return src.Buffer();}
132 static constexpr integer Length(const strings::TString<TChar>& src) {return src.Length();}
133};
134#endif // !DOXYGEN
135}
136
137/// Type alias in namespace \b alib.
139
140/// Type alias in namespace \b alib.
142
143/// Type alias in namespace \b alib.
145
146/// Type alias in namespace \b alib.
148
149/// Type alias in namespace \b alib.
151
152/// Type alias in namespace \b alib.
154
155} // namespace [alib::strings]
#define ALIB_EXPORT
Definition alib.inl:562
constexpr TStringNZT(const T *src)
Definition stringnzt.inl:93
constexpr TStringNZT(T *src)
constexpr TStringNZT(T &src)
constexpr TStringNZT(const T src)
constexpr TStringNZT(const TChar *pBuffer, integer pLength)
Definition stringnzt.inl:44
constexpr integer Length() const
Definition string.inl:304
constexpr const character * Buffer() const
Definition string.inl:299
constexpr TString() noexcept=default
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TStringNZT< character > StringNZT
Type alias in namespace alib.
strings::TStringNZT< nchar > NStringNZT
Type alias in namespace alib.
strings::TStringNZT< wchar > WStringNZT
Type alias in namespace alib.
strings::TStringNZT< complementChar > ComplementStringNZT
Type alias in namespace alib.
strings::TStringNZT< xchar > XStringNZT
Type alias in namespace alib.
strings::TStringNZT< strangeChar > StrangeStringNZT
Type alias in namespace alib.
static constexpr Policy Access
static integer Length(const TStringSource &src)
static constexpr Policy Construction
static const TChar * Buffer(const TStringSource &src)