ALib C++ Library
Library Version: 2402 R1
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 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_STRINGS_STRINGNZT
9#define HPP_ALIB_STRINGS_STRINGNZT 1
10
11#if !defined(HPP_ALIB_STRINGS_STRING)
13#endif
14
15
16namespace alib { namespace strings {
17
18/** ************************************************************************************************
19 * This is rather a helper class than a genuine string class. While derived from class \b String,
20 * no extension of its interface is offered. Instead, the templated constructor is limited to
21 * accept only string types that are not zero-terminated.
22 *
23 * The class is designed to be used to create API interfaces (i.e. overloaded methods) that accept
24 * zero-terminated strings of type \alib{strings;TCString;CString} independently from
25 * non-zero-terminated strings: If two overloaded methods accepted type \c String and \c CString
26 * alternatively, compilation would be ambiguous because the \b String version would accept
27 * zero-terminated strings as well. Therefore, overloaded methods rather must accept this class
28 * and \b CString.
29 *
30 * \see
31 * Details and a quick sample are given in chapter
32 * \ref alib_strings_nzt "4. Non-Zero-Terminated String Detection" of the
33 * \ref alib_mod_strings "Programmer's Manual" of module \alib_strings_nl.
34 *
35 * @tparam TChar The character type. Alias names of this class using character types
36 * \alib{character}, \alib{nchar}, \alib{wchar} and \alib{xchar} are provided
37 * with in namespace #alib with type definitions \alib{StringNZT},
38 * \alib{NStringNZT}, \alib{WStringNZT} and \alib{XStringNZT}.
39 **************************************************************************************************/
40template<typename TChar>
41class TStringNZT : public TString<TChar>
42{
43 public:
44
45 /** ****************************************************************************************
46 * Constructor accepting a pointer to a character array and a string length.
47 *
48 * @param pBuffer Pointer to the start of the character string to represent.
49 * @param pLength The length of the character string to represent.
50 ******************************************************************************************/
51 constexpr
52 TStringNZT( const TChar* pBuffer, integer pLength )
53 : TString<TChar>( pBuffer, pLength)
54 {}
55
56
57 #if defined(ALIB_DOX)
58 /** ****************************************************************************************
59 * Templated constructor that accepts C++ string types which are not zero-terminated.
60 *
61 * @tparam TCharArray Type that comprises a non-zero-terminated character array.
62 * @param src The source object.
63 ******************************************************************************************/
64 template <typename TCharArray>
65 inline
66 constexpr
67 TStringNZT(const TCharArray& src );
68
69
70 #else // doxygen end
71
74 constexpr
75 TStringNZT(const T& src)
76 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( src ),
77 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( src ) )
78 {}
79
82 constexpr
83 TStringNZT(const T* src)
84 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( *src ),
85 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( *src ) )
86 {}
87
89 constexpr
90 explicit
91 TStringNZT(const T& src)
92 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( src ),
93 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( src ) )
94 {}
95
96 ATMP_SELECT_IF_1TP( typename T, characters::T_CharArray<ATMP_RCV(T),TChar>::Access == characters::AccessType::ExplicitOnly )
97 constexpr
98 explicit
99 TStringNZT(const T* src)
100 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( *src ),
101 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( *src ) )
102 {}
103
104 ATMP_SELECT_IF_1TP( typename T, characters::T_CharArray<ATMP_RCV(T),TChar>::Access == characters::AccessType::MutableOnly && !std::is_const<T>::value )
105 constexpr
106 explicit
107 TStringNZT( T& src)
108 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( const_cast<T&>( src ) ),
109 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( const_cast<T&>( src ) ) )
110 {}
111
112 ATMP_SELECT_IF_1TP( typename T, characters::T_CharArray<ATMP_RCV(T),TChar>::Access == characters::AccessType::MutableOnly && !std::is_const<T>::value )
113 constexpr
114 explicit
115 TStringNZT( T* src)
116 : TString<TChar>( characters::T_CharArray<ATMP_RCV(T),TChar>::Buffer( const_cast<T&>( *src ) ),
117 characters::T_CharArray<ATMP_RCV(T),TChar>::Length( const_cast<T&>( *src ) ) )
118 {}
119
120 #endif // doxygen
121}; // class TStringNZT
122
123
124}} // namespace [alib::strings]
125
126
127#endif // HPP_ALIB_STRINGS_STRINGNZT
constexpr TStringNZT(const TChar *pBuffer, integer pLength)
Definition stringnzt.hpp:52
constexpr TStringNZT(const TCharArray &src)
constexpr integer Length() const
Definition string.hpp:357
constexpr TString() noexcept=default
constexpr const TChar * Buffer() const
Definition string.hpp:350
#define ATMP_RCV( T)
Definition tmp.hpp:40
#define ATMP_SELECT_IF_1TP(TParam, ...)
Definition tmp.hpp:57
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286