ALib C++ Library
Library Version: 2402 R1
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
18#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
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
49#if !defined(HPP_ALIB_CHARACTERS_CHARACTERS)
51#endif
52
53namespace alib { namespace characters {
54
55// Faking all template specializations of namespace strings for doxygen into namespace
56// strings::custom to keep the documentation of namespace string clean!
57#if defined(ALIB_DOX)
58namespace compatibility {
59/**
60 * Specializations of type traits structs \alib{characters;T_CharArray} and
61 * \alib{characters;T_ZTCharArray} for types found in the
62 * \https{QT Class Library,www.qt.io}.
63 */
64namespace qt {} }
65
66#else
67
68#define ALIB_QTCHAR typename alib::characters::TT_CharOfSize<2>::type
69#define ALIB_QTCHAR_4 typename alib::characters::TT_CharOfSize<4>::type
70
72// QStringView
73template<> struct T_CharArray<QStringView, ALIB_QTCHAR>
74{
75 static constexpr AccessType Access = AccessType::Implicit;
77 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
78 static integer Length (QStringView const & src) { return static_cast<integer >(src.size()); }
79 static QStringView Construct(const ALIB_QTCHAR* array, integer length ) { return QStringView( array, static_cast<qsizetype>(length) ); }
80};
81
82template<> struct T_ZTCharArray<QStringView, ALIB_QTCHAR>
83{
84 static constexpr AccessType Access = AccessType::ExplicitOnly;
85 static constexpr ConstructionType Construction = ConstructionType::Implicit;
86 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
87 static integer Length (QStringView const & src) { return static_cast<integer >(src.size()); }
88 static QStringView Construct(const ALIB_QTCHAR* array, integer length ) { return QStringView( array, static_cast<qsizetype>(length) ); }
89};
90
91// QString
92template<> struct T_CharArray<QString, ALIB_QTCHAR >
93{
94 static constexpr AccessType Access = AccessType::Implicit;
96 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
97 static integer Length (QString const & src) { return static_cast<integer >(src.size()); }
98 static QString Construct(const ALIB_QTCHAR* array, integer length ) { return QString( reinterpret_cast<const QChar*>(array), static_cast<int>(length) ); }
99};
100
101template<> struct T_ZTCharArray<QString, ALIB_QTCHAR>
102{
103 static constexpr AccessType Access = AccessType::Implicit;
104 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
105 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.utf16()); }
106 static integer Length (QString const & src) { return static_cast<integer >(src.size() ); }
107 static QString Construct(const ALIB_QTCHAR* array, integer length ) { return QString( reinterpret_cast<const QChar*>(array), static_cast<int>(length) ); }
108};
109
110// QLatin1String
111template<> struct T_CharArray<QLatin1String, nchar>
112{
113 static constexpr AccessType Access = AccessType::Implicit;
115 static const nchar* Buffer (QLatin1String const & src) { return src.data(); }
116 static integer Length (QLatin1String const & src) { return static_cast<integer >(src.size()); }
117 static QLatin1String Construct(const nchar* array, integer length ) { return QLatin1String( array, static_cast<int>(length) ); }
118};
119
120template<> struct T_ZTCharArray<QLatin1String, nchar>
121{
122 static constexpr AccessType Access = AccessType::ExplicitOnly;
123 static constexpr ConstructionType Construction = ConstructionType::Implicit;
124 static const nchar* Buffer (QLatin1String const & src) { return reinterpret_cast<const nchar*>(src.data()); }
125 static integer Length (QLatin1String const & src) { return static_cast<integer >(src.size()); }
126 static QLatin1String Construct(const nchar* array, integer length ) { return QLatin1String( array, static_cast<int>(length) ); }
127};
128
129// QByteArray
130template<> struct T_CharArray<QByteArray, nchar>
131{
132 static constexpr AccessType Access = AccessType::Implicit;
134 static const nchar* Buffer (QByteArray const & src) { return src.data(); }
135 static integer Length (QByteArray const & src) { return static_cast<integer >(src.size()); }
136 static QByteArray Construct(const nchar* array, integer length ) { return QByteArray( array, static_cast<int>(length) ); }
137};
138
139template<> struct T_ZTCharArray<QByteArray, nchar>
140{
141 static constexpr AccessType Access = AccessType::ExplicitOnly;
142 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
143 static const nchar* Buffer (QByteArray const & src) { return reinterpret_cast<const nchar*>(src.data()); }
144 static integer Length (QByteArray const & src) { return static_cast<integer >(src.size()); }
145 static QByteArray Construct(const nchar* array, integer length ) { return QByteArray( array, static_cast<int>(length) ); }
146};
147
148// QVector<uint>
149template<> struct T_CharArray<QVector<uint>, ALIB_QTCHAR_4>
150{
151 static constexpr AccessType Access = AccessType::Implicit;
153 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
154 static integer Length (QVector<uint> const & src) { return static_cast<integer >(src.size()); }
155 static QVector<uint> Construct(const ALIB_QTCHAR_4* array, integer length )
156 {
157 QVector<uint> result;
158 result.reserve( static_cast<int>(length) );
159 const ALIB_QTCHAR_4* end= array + length;
160 while( array < end )
161 result.append( static_cast<uint>( *array++ ) );
162 return result;
163 }
164};
165
166template<> struct T_ZTCharArray<QVector<uint>, ALIB_QTCHAR_4>
167{
168 static constexpr AccessType Access = AccessType::ExplicitOnly;
169 static constexpr ConstructionType Construction = ConstructionType::ExplicitOnly;
170 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
171 static integer Length (QVector<uint> const & src) { return static_cast<integer >(src.size() ); }
172 static QVector<uint> Construct(const ALIB_QTCHAR_4* array, integer length )
173 {
174 QVector<uint> result;
175 result.reserve( static_cast<int>(length) );
176 const ALIB_QTCHAR_4* end= array + length;
177 while( array < end )
178 result.append( static_cast<uint>( *array++ ) );
179 return result;
180 }
181};
182
184
185#endif //ALIB_DOX
186
187}} // namespace [alib::characters]
188
189
190#endif // !defined(ALIB_QT_LIB_NOT_FOUND) // this is only set in an automated test project
191#endif // HPP_ALIB_COMPATIBILITY_QT_CHARACTERS
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
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)