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