ALib C++ Library
by
Library Version:
2402 R1
Documentation generated by
Loading...
Searching...
No Matches
home
dev
A-Worx
ALib
src
alib
strings
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)
12
# include "
alib/strings/string.hpp
"
13
#endif
14
15
16
namespace
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
**************************************************************************************************/
40
template
<
typename
TChar>
41
class
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
72
ATMP_SELECT_IF_1TP
(
typename
T,
characters::T_CharArray
<
ATMP_RCV
(T),TChar>::Access ==
characters::AccessType::Implicit
73
&&
characters::T_ZTCharArray
<
ATMP_RCV
(T),TChar>::Access !=
characters::AccessType::Implicit
)
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
80
ATMP_SELECT_IF_1TP
(
typename
T,
characters::T_CharArray
<
ATMP_RCV
(T),TChar>::Access ==
characters::AccessType::Implicit
81
&&
characters::T_ZTCharArray
<
ATMP_RCV
(T),TChar>::Access !=
characters::AccessType::Implicit
)
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
88
ATMP_SELECT_IF_1TP
(
typename
T,
characters::T_CharArray
<
ATMP_RCV
(T),TChar>::Access ==
characters::AccessType::ExplicitOnly
)
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
alib::strings::TStringNZT
Definition
stringnzt.hpp:42
alib::strings::TStringNZT::TStringNZT
constexpr TStringNZT(const TChar *pBuffer, integer pLength)
Definition
stringnzt.hpp:52
alib::strings::TStringNZT::TStringNZT
constexpr TStringNZT(const TCharArray &src)
alib::strings::TString
Definition
string.hpp:74
alib::strings::TString::Length
constexpr integer Length() const
Definition
string.hpp:357
alib::strings::TString::TString
constexpr TString() noexcept=default
alib::strings::TString::Buffer
constexpr const TChar * Buffer() const
Definition
string.hpp:350
ATMP_RCV
#define ATMP_RCV( T)
Definition
tmp.hpp:40
ATMP_SELECT_IF_1TP
#define ATMP_SELECT_IF_1TP(TParam, ...)
Definition
tmp.hpp:57
alib::characters::AccessType::ExplicitOnly
@ ExplicitOnly
alib::characters::AccessType::Implicit
@ Implicit
alib::characters::AccessType::MutableOnly
@ MutableOnly
alib
Definition
alib.cpp:57
alib::integer
lang::integer integer
Type alias in namespace alib.
Definition
integers.hpp:286
string.hpp
alib::characters::T_CharArray
Definition
characters.hpp:265
alib::characters::T_ZTCharArray
Definition
characters.hpp:347