ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
stringnzt.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/// Copyright 2013-2026 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 #"%^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 #"^CString" independently of/ non-zero-terminated strings:
17/// If two overloaded methods accepted type \c String and \c CString
18/// alternatively, compilation would be ambiguous because the #"%^String" version would accept
19/// zero-terminated strings as well. Therefore, overloaded methods rather must accept this class
20/// and #"%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 public:
38 /// Constructor accepting a pointer to a character array and a string length.
39 ///
40 /// @param pBuffer Pointer to the start of the character string to represent.
41 /// @param pLength The length of the character string to represent.
42 constexpr
43 TStringNZT( const TChar* pBuffer, integer pLength )
44 : TString<TChar>( pBuffer, pLength) {}
45
46
47// Doxygen (V1.15) would create identical entries in its tag-file, so those are not reachable.
48// On the other hand, it complains if the methods are not doxed. So, we hide them from doxygen.
49#if DOXYGEN
50 /// Templated \b implicit constructor accepting a \c const reference to an object of a
51 /// type that satisfies the concept #"IsImplicitArraySource" while it does
52 /// \b not satisfy the concept #"IsImplicitZTArraySource",
53 /// In other words, this implicit constructor accepts only non-zero-terminated character
54 /// arrays.
55 ///
56 /// Internally another version exists, which accepts types that satisfy the concept
57 /// #"IsExplicitArraySource".<br>
58 ///
59 /// @tparam T The type of the given \p{src}.
60 /// @param src The source of the string data to copy.
61 template <typename T>
62 constexpr TStringNZT(const T src);
63#else
64 template <typename T>
65 requires ( characters::IsImplicitArraySource <T, TChar>
67 constexpr TStringNZT(const T& src)
68 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
69 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
70
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 template <typename T>
79 requires characters::IsExplicitArraySource <T, TChar>
80 constexpr explicit TStringNZT(const T& src)
81 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
82 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
83#endif
84
85 /// Templated \b implicit constructor accepting a \c const pointer to an object of a
86 /// type that satisfies the concept #"IsExplicitArraySource".
87 ///
88 /// @tparam T The type of the given \p{src}.
89 /// @param src The source of the string data to copy.
90 template <typename T>
91 requires characters::IsExplicitArraySource <T, TChar>
92 constexpr explicit TStringNZT(const T* src)
93 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
94 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
95
96 /// Templated \b implicit constructor accepting a mutable reference to an object of a
97 /// type that satisfies the concept #"IsMutableArraySource".
98 ///
99 /// @tparam T The type of the given \p{src}.
100 /// @param src The source of the string data to copy.
101 template<typename T>
103 constexpr explicit TStringNZT( T& src)
104 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
105 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {}
106
107 /// Templated \b implicit constructor accepting a mutable pointer to an object of a
108 /// type that satisfies the concept #"IsMutableArraySource".
109 ///
110 /// @tparam T The type of the given \p{src}.
111 /// @param src The source of the string data to copy.
112 template<typename T>
114 constexpr explicit TStringNZT( T* src)
115 : TString<TChar>( characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
116 characters::ArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {}
117
118}; // class TStringNZT
119
120//##################################################################################################
121// Specializations of ArrayTraits for class TStringNZT
122//##################################################################################################
123} namespace characters {
124#if !DOXYGEN
125template<typename TChar>
126struct ArrayTraits<strings::TStringNZT<TChar>, TChar>
127{
128 static constexpr Policy Access = Policy::Implicit;
129 static constexpr Policy Construction = Policy::NONE;
130 static constexpr const TChar* Buffer(const strings::TString<TChar>& src) {return src.Buffer();}
131 static constexpr integer Length(const strings::TString<TChar>& src) {return src.Length();}
132};
133#endif // !DOXYGEN
134}
135
136/// Type alias in namespace #"%alib".
138
139/// Type alias in namespace #"%alib".
141
142/// Type alias in namespace #"%alib".
144
145/// Type alias in namespace #"%alib".
147
148/// Type alias in namespace #"%alib".
150
151/// Type alias in namespace #"%alib".
153
154} // namespace [alib::strings]
#define ALIB_EXPORT
constexpr TStringNZT(const T *src)
Definition stringnzt.hpp:92
constexpr TStringNZT(T *src)
constexpr TStringNZT(T &src)
constexpr TStringNZT(const T src)
constexpr TStringNZT(const TChar *pBuffer, integer pLength)
Definition stringnzt.hpp:43
constexpr integer Length() const
Definition string.hpp:300
constexpr const character * Buffer() const
Definition string.hpp:295
constexpr TString() noexcept=default
Definition alox.cpp:14
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp: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)