ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
qt_characters.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7///
8/// <b>Legal Notice:</b>
9/// This is an optional extension header to provide compatibility between ALib and
10/// the QT class library.
11/// All information about QT is found at https://www.qt.io
12/// ALib otherwise does not use or rely on QT.
13/// The use of QT is bound to the QT license restrictions.
14//==================================================================================================
15#ifndef HPP_ALIB_COMPATIBILITY_QT_CHARACTERS
16#define HPP_ALIB_COMPATIBILITY_QT_CHARACTERS 1
17#pragma once
18#if !defined(DOXYGEN)
19# include "alib/alib.hpp"
20#endif
21
22ALIB_ASSERT_MODULE(CHARACTERS)
23
24#if !defined(ALIB_QT_LIB_NOT_FOUND) // this is only set in an automated test project
25
26// include QT
27#if defined(__clang__)
28 #pragma clang diagnostic push
29 #pragma clang diagnostic ignored "-Wreserved-id-macro"
30 #pragma clang diagnostic ignored "-Wredundant-parens"
31 #pragma clang diagnostic ignored "-Wcovered-switch-default"
32 #pragma clang diagnostic ignored "-Wsign-conversion"
33 #pragma clang diagnostic ignored "-Wdeprecated"
34 #pragma clang diagnostic ignored "-Wunused-variable"
35 #pragma clang diagnostic ignored "-Wcomma"
36 #pragma clang diagnostic ignored "-Wduplicate-enum"
37#endif
38#include <QtCore/QString>
39#include <QtCore/QVector>
40
41#if defined(__clang__)
42 #pragma clang diagnostic pop
43#endif
44
45#if defined(HPP_ALIB_BOXING_BOXING)
46# error "Wrong inclusion order. Header 'alib/compatibility/qt_characters.hpp' has to be included before headers of module ALib Boxing."
47#endif
48
50
51namespace alib::characters {
52
53// Faking all template specializations of namespace strings for doxygen into namespace
54// strings::custom to keep the documentation of namespace string clean!
55#if DOXYGEN
56namespace compatibility {
57/// Specializations of type traits structs \alib{characters;T_CharArray} and
58/// \alib{characters;T_ZTCharArray} for types found in the
59/// \https{QT Class Library,www.qt.io}.
60namespace qt {} }
61
62#else
63
64#define ALIB_QTCHAR typename alib::characters::TT_CharOfSize<2>::type
65#define ALIB_QTCHAR_4 typename alib::characters::TT_CharOfSize<4>::type
66
68// QStringView
69template<> struct T_CharArray<QStringView, ALIB_QTCHAR>
70{
71 static constexpr AccessType Access = AccessType::Implicit;
73 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
74 static integer Length (QStringView const & src) { return static_cast<integer >(src.size()); }
75 static QStringView Construct(const ALIB_QTCHAR* array, integer length ) { return QStringView( array, static_cast<qsizetype>(length) ); }
76};
77
78template<> struct T_ZTCharArray<QStringView, ALIB_QTCHAR>
79{
80 static constexpr AccessType Access = AccessType::ExplicitOnly;
81 static constexpr ConstructionType Construction = ConstructionType::Implicit;
82 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
83 static integer Length (QStringView const & src) { return static_cast<integer >(src.size()); }
84 static QStringView Construct(const ALIB_QTCHAR* array, integer length ) { return QStringView( array, static_cast<qsizetype>(length) ); }
85};
86
87// QString
88template<> struct T_CharArray<QString, ALIB_QTCHAR >
89{
90 static constexpr AccessType Access = AccessType::Implicit;
92 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
93 static integer Length (QString const & src) { return static_cast<integer >(src.size()); }
94 static QString Construct(const ALIB_QTCHAR* array, integer length ) { return QString( reinterpret_cast<const QChar*>(array), static_cast<int>(length) ); }
95};
96
97template<> struct T_ZTCharArray<QString, ALIB_QTCHAR>
98{
99 static constexpr AccessType Access = AccessType::Implicit;
100 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
101 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.utf16()); }
102 static integer Length (QString const & src) { return static_cast<integer >(src.size() ); }
103 static QString Construct(const ALIB_QTCHAR* array, integer length ) { return QString( reinterpret_cast<const QChar*>(array), static_cast<int>(length) ); }
104};
105
106// QLatin1String
107template<> struct T_CharArray<QLatin1String, nchar>
108{
109 static constexpr AccessType Access = AccessType::Implicit;
111 static const nchar* Buffer (QLatin1String const & src) { return src.data(); }
112 static integer Length (QLatin1String const & src) { return static_cast<integer >(src.size()); }
113 static QLatin1String Construct(const nchar* array, integer length ) { return QLatin1String( array, static_cast<int>(length) ); }
114};
115
116template<> struct T_ZTCharArray<QLatin1String, nchar>
117{
118 static constexpr AccessType Access = AccessType::ExplicitOnly;
119 static constexpr ConstructionType Construction = ConstructionType::Implicit;
120 static const nchar* Buffer (QLatin1String const & src) { return reinterpret_cast<const nchar*>(src.data()); }
121 static integer Length (QLatin1String const & src) { return static_cast<integer >(src.size()); }
122 static QLatin1String Construct(const nchar* array, integer length ) { return QLatin1String( array, static_cast<int>(length) ); }
123};
124
125// QByteArray
126template<> struct T_CharArray<QByteArray, nchar>
127{
128 static constexpr AccessType Access = AccessType::Implicit;
130 static const nchar* Buffer (QByteArray const & src) { return src.data(); }
131 static integer Length (QByteArray const & src) { return static_cast<integer >(src.size()); }
132 static QByteArray Construct(const nchar* array, integer length ) { return QByteArray( array, static_cast<int>(length) ); }
133};
134
135template<> struct T_ZTCharArray<QByteArray, nchar>
136{
137 static constexpr AccessType Access = AccessType::ExplicitOnly;
138 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
139 static const nchar* Buffer (QByteArray const & src) { return reinterpret_cast<const nchar*>(src.data()); }
140 static integer Length (QByteArray const & src) { return static_cast<integer >(src.size()); }
141 static QByteArray Construct(const nchar* array, integer length ) { return QByteArray( array, static_cast<int>(length) ); }
142};
143
144// QVector<uint>
145template<> struct T_CharArray<QVector<uint>, ALIB_QTCHAR_4>
146{
147 static constexpr AccessType Access = AccessType::Implicit;
149 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
150 static integer Length (QVector<uint> const & src) { return static_cast<integer >(src.size()); }
151 static QVector<uint> Construct(const ALIB_QTCHAR_4* array, integer length )
152 {
153 QVector<uint> result;
154 result.reserve( static_cast<int>(length) );
155 const ALIB_QTCHAR_4* end= array + length;
156 while( array < end )
157 result.append( static_cast<uint>( *array++ ) );
158 return result;
159 }
160};
161
162template<> struct T_ZTCharArray<QVector<uint>, ALIB_QTCHAR_4>
163{
164 static constexpr AccessType Access = AccessType::ExplicitOnly;
165 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
166 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
167 static integer Length (QVector<uint> const & src) { return static_cast<integer >(src.size() ); }
168 static QVector<uint> Construct(const ALIB_QTCHAR_4* array, integer length )
169 {
170 QVector<uint> result;
171 result.reserve( static_cast<int>(length) );
172 const ALIB_QTCHAR_4* end= array + length;
173 while( array < end )
174 result.append( static_cast<uint>( *array++ ) );
175 return result;
176 }
177};
178
180
181#endif //ALIB_DOX
182
183} // namespace [alib::characters]
184
185
186#endif // !defined(ALIB_QT_LIB_NOT_FOUND) // this is only set in an automated test project
187#endif // HPP_ALIB_COMPATIBILITY_QT_CHARACTERS
188
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
@ ExplicitOnly
Allows explicit construction of objects from character array data.
@ Implicit
Allows implicit (and explicit) construction of objects from character array data.
@ ExplicitOnly
Allows explicit access of the character array data from mutable or constant objects.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
static const TChar * Buffer(const TString &src)
static constexpr ConstructionType Construction
static TString Construct(const TChar *array, integer length)
static constexpr AccessType Access
static integer Length(const TString &src)
static const TChar * Buffer(const TString &src)
static TString Construct(const TChar *array, integer length)
static integer Length(const TString &src)