ALib C++ Library
Library Version: 2510 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 \ref mainpage_license "Boost Software 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 \alib{strings;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/// \ref alib_strings_nzt "4. Non-Zero-Terminated String Detection" of the
25/// \ref alib_mod_strings "Programmer's Manual" of module \alib_strings_nl.
26///
27/// @tparam TChar The \ref 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/// \alib{StringNZT},
31/// \alib{NStringNZT},
32/// \alib{WStringNZT}, and
33/// \alib{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 /// Templated \b implicit constructor accepting a \c const reference to an object of a
49 /// type that satisfies the concept \alib{characters;IsImplicitArraySource} while it does
50 /// \b not satisfy the concept \alib{characters;IsImplicitZTArraySource}.<br>
51 /// In other words, this implicit constructor accepts only non-zero-terminated character
52 /// arrays.
53 ///
54 /// @tparam T The type of the given \p{src}.
55 /// @param src The source of the string data to copy.
56 template <typename T>
57 requires ( characters::IsImplicitArraySource <T, TChar>
59 constexpr TStringNZT(const T& src)
60 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
61 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
62
63 /// Templated \b implicit constructor accepting a \c const pointer to an object of a
64 /// type that satisfies the concept \alib{characters;IsImplicitArraySource} while it does
65 /// \b not satisfy the concept \alib{characters;IsImplicitZTArraySource}.<br>
66 /// In other words, this implicit constructor accepts only non-zero-terminated character
67 /// arrays.
68 ///
69 /// @tparam T The type of the given \p{src}.
70 /// @param src The source of the string data to copy.
71 template <typename T>
72 requires ( characters::IsImplicitArraySource <T, TChar>
74 constexpr TStringNZT(const T* src)
75 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
76 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
77
78
79 /// Templated \b implicit constructor accepting a \c const reference to an object of a
80 /// type that satisfies the concept \alib{characters;IsExplicitArraySource}.
81 ///
82 /// @tparam T The type of the given \p{src}.
83 /// @param src The source of the string data to copy.
84 template <typename T>
85 requires characters::IsExplicitArraySource <T, TChar>
86 constexpr explicit TStringNZT(const T& src)
87 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
88 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
89
90 /// Templated \b implicit constructor accepting a \c const pointer to an object of a
91 /// type that satisfies the concept \alib{characters;IsExplicitArraySource}.
92 ///
93 /// @tparam T The type of the given \p{src}.
94 /// @param src The source of the string data to copy.
95 template <typename T>
96 requires characters::IsExplicitArraySource <T, TChar>
97 constexpr explicit TStringNZT(const T* src)
98 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
99 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
100
101 /// Templated \b implicit constructor accepting a mutable reference to an object of a
102 /// type that satisfies the concept \alib{characters;IsMutableArraySource}.
103 ///
104 /// @tparam T The type of the given \p{src}.
105 /// @param src The source of the string data to copy.
106 template<typename T>
108 constexpr explicit TStringNZT( T& src)
109 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
110 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
111
112 /// Templated \b implicit constructor accepting a mutable pointer to an object of a
113 /// type that satisfies the concept \alib{characters;IsMutableArraySource}.
114 ///
115 /// @tparam T The type of the given \p{src}.
116 /// @param src The source of the string data to copy.
117 template<typename T>
119 constexpr explicit TStringNZT( T* src)
120 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
121 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
122
123}; // class TStringNZT
124
125// #################################################################################################
126// Specializations of ArrayTraits for class TStringNZT
127// #################################################################################################
128} namespace characters {
129#if !DOXYGEN
130template<typename TChar>
131struct ArrayTraits<strings::TStringNZT<TChar>, TChar>
132{
133 static constexpr Policy Access = Policy::Implicit;
134 static constexpr Policy Construction = Policy::NONE;
135 static constexpr const TChar* Buffer(const strings::TString<TChar>& src) {return src.Buffer();}
136 static constexpr integer Length(const strings::TString<TChar>& src) {return src.Length();}
137};
138#endif // !DOXYGEN
139}
140
141/// Type alias in namespace \b alib.
143
144/// Type alias in namespace \b alib.
146
147/// Type alias in namespace \b alib.
149
150/// Type alias in namespace \b alib.
152
153/// Type alias in namespace \b alib.
155
156/// Type alias in namespace \b alib.
158
159} // namespace [alib::strings]
160
161
constexpr TStringNZT(const T &src)
Definition stringnzt.inl:59
constexpr TStringNZT(const T *src)
Definition stringnzt.inl:97
constexpr TStringNZT(T &src)
constexpr TStringNZT(T *src)
constexpr TStringNZT(const T *src)
Definition stringnzt.inl:74
constexpr TStringNZT(const T &src)
Definition stringnzt.inl:86
constexpr TStringNZT(const TChar *pBuffer, integer pLength)
Definition stringnzt.inl:44
constexpr integer Length() const
Definition string.inl:318
constexpr const character * Buffer() const
Definition string.inl:313
constexpr TString() noexcept=default
#define ALIB_EXPORT
Definition alib.inl:488
strings::TStringNZT< complementChar > ComplementStringNZT
Type alias in namespace alib.
strings::TStringNZT< character > StringNZT
Type alias in namespace alib.
strings::TStringNZT< strangeChar > StrangeStringNZT
Type alias in namespace alib.
strings::TStringNZT< nchar > NStringNZT
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TStringNZT< xchar > XStringNZT
Type alias in namespace alib.
strings::TStringNZT< wchar > WStringNZT
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)