ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ALib.Compatibility.QTCharacters.H
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 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.inl"
20#endif
21
22
23#if !defined(ALIB_QT_LIB_NOT_FOUND) // this is only set in an automated test project
24
25// include QT
26#if defined(__clang__)
27 #pragma clang diagnostic push
28 #pragma clang diagnostic ignored "-Wreserved-id-macro"
29 #pragma clang diagnostic ignored "-Wredundant-parens"
30 #pragma clang diagnostic ignored "-Wcovered-switch-default"
31 #pragma clang diagnostic ignored "-Wsign-conversion"
32 #pragma clang diagnostic ignored "-Wdeprecated"
33 #pragma clang diagnostic ignored "-Wunused-variable"
34 #pragma clang diagnostic ignored "-Wcomma"
35 #pragma clang diagnostic ignored "-Wduplicate-enum"
36#endif
37#include <QtCore/QString>
38#include <QtCore/QVector>
39
40#if defined(__clang__)
41 #pragma clang diagnostic pop
42#endif
43
44#if defined(H_ALIB_BOXING)
45# error "Wrong inclusion order. Header 'alib/compatibility/qt_characters.hpp' has to be included before headers of module ALib Boxing."
46#endif
47
48#include "ALib.Lang.H"
49
51
52// Faking all template specializations of namespace strings for doxygen into namespace
53// strings::custom to keep the documentation of namespace string clean!
54#if DOXYGEN
55namespace compatibility {
56/// Specializations of type traits \alib{characters;ArrayTraits} and
57/// \alib{characters;ZTArrayTraits} for types found in the
58/// \https{QT Class Library,www.qt.io}.
59namespace qt {} }
60
61#else
62
63#define ALIB_QTCHAR alib::characters::TypeBySize<2>
64#define ALIB_QTCHAR_4 alib::characters::TypeBySize<4>
65
66// QStringView
67template<> struct ArrayTraits<QStringView, ALIB_QTCHAR>
68{
69 static constexpr Policy Access = Policy::Implicit;
70 static constexpr Policy Construction = Policy::Implicit;
71 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
72 static integer Length (QStringView const & src) { return integer(src.size()); }
73 static QStringView Construct(const ALIB_QTCHAR* b, integer l ) { return QStringView( b, qsizetype(l) ); }
74};
75
76template<> struct ZTArrayTraits<QStringView, ALIB_QTCHAR>
77{
78 static constexpr Policy Access = Policy::ExplicitOnly;
79 static constexpr Policy Construction = Policy::Implicit;
80 static const ALIB_QTCHAR* Buffer (QStringView const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
81 static integer Length (QStringView const & src) { return integer(src.size()); }
82 static QStringView Construct(const ALIB_QTCHAR* b, integer l ) { return QStringView( b, qsizetype(l) ); }
83};
84
85// QString
86template<> struct ArrayTraits<QString, ALIB_QTCHAR >
87{
88 static constexpr Policy Access = Policy::Implicit;
89 static constexpr Policy Construction = Policy::ExplicitOnly;
90 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.data()); }
91 static integer Length (QString const & src) { return integer(src.size()); }
92 static QString Construct(const ALIB_QTCHAR* b, integer l ) { return QString( reinterpret_cast<const QChar*>(b), int(l) ); }
93};
94
95template<> struct ZTArrayTraits<QString, ALIB_QTCHAR>
96{
97 static constexpr Policy Access = Policy::Implicit;
98 static constexpr Policy Construction = Policy::ExplicitOnly;
99 static const ALIB_QTCHAR* Buffer (QString const & src) { return reinterpret_cast<const ALIB_QTCHAR*>(src.utf16()); }
100 static integer Length (QString const & src) { return integer(src.size() ); }
101 static QString Construct(const ALIB_QTCHAR* b, integer l ) { return QString( reinterpret_cast<const QChar*>(b), int(l) ); }
102};
103
104// QLatin1String
105template<> struct ArrayTraits<QLatin1String, nchar>
106{
107 static constexpr Policy Access = Policy::Implicit;
108 static constexpr Policy Construction = Policy::Implicit;
109 static const nchar* Buffer (QLatin1String const & src) { return src.data(); }
110 static integer Length (QLatin1String const & src) { return integer(src.size()); }
111 static QLatin1String Construct(const nchar* b, integer l ) { return QLatin1String( b, int(l) ); }
112};
113
114template<> struct ZTArrayTraits<QLatin1String, nchar>
115{
116 static constexpr Policy Access = Policy::ExplicitOnly;
117 static constexpr Policy Construction = Policy::Implicit;
118 static const nchar* Buffer (QLatin1String const & src) { return reinterpret_cast<const nchar*>(src.data()); }
119 static integer Length (QLatin1String const & src) { return integer(src.size()); }
120 static QLatin1String Construct(const nchar* b, integer l ) { return QLatin1String( b, int(l) ); }
121};
122
123// QByteArray
124template<> struct ArrayTraits<QByteArray, nchar>
125{
126 static constexpr Policy Access = Policy::Implicit;
127 static constexpr Policy Construction = Policy::ExplicitOnly;
128 static const nchar* Buffer (QByteArray const & src) { return src.data(); }
129 static integer Length (QByteArray const & src) { return integer(src.size()); }
130 static QByteArray Construct(const nchar* b, integer l ) { return QByteArray( b, int(l) ); }
131};
132
133template<> struct ZTArrayTraits<QByteArray, nchar>
134{
135 static constexpr Policy Access = Policy::ExplicitOnly;
136 static constexpr Policy Construction = Policy::ExplicitOnly;
137 static const nchar* Buffer (QByteArray const & src) { return reinterpret_cast<const nchar*>(src.data()); }
138 static integer Length (QByteArray const & src) { return integer(src.size()); }
139 static QByteArray Construct(const nchar* b, integer l ) { return QByteArray( b, int(l) ); }
140};
141
142// QVector<uint>
143template<> struct ArrayTraits<QVector<uint>, ALIB_QTCHAR_4>
144{
145 static constexpr Policy Access = Policy::Implicit;
146 static constexpr Policy Construction = Policy::ExplicitOnly;
147 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
148 static integer Length (QVector<uint> const & src) { return integer(src.size()); }
149 static QVector<uint> Construct(const ALIB_QTCHAR_4* b, integer l )
150 {
151 QVector<uint> result;
152 result.reserve( int(l) );
153 const ALIB_QTCHAR_4* end= b + l;
154 while( b < end )
155 result.append( uint( *b++ ) );
156 return result;
157 }
158};
159
160template<> struct ZTArrayTraits<QVector<uint>, ALIB_QTCHAR_4>
161{
162 static constexpr Policy Access = Policy::ExplicitOnly;
163 static constexpr Policy Construction = Policy::ExplicitOnly;
164 static const ALIB_QTCHAR_4* Buffer (QVector<uint> const & src) { return reinterpret_cast<const ALIB_QTCHAR_4*>(src.data()); }
165 static integer Length (QVector<uint> const & src) { return integer(src.size() ); }
166 static QVector<uint> Construct(const ALIB_QTCHAR_4* b, integer l )
167 {
168 QVector<uint> result;
169 result.reserve( int(l) );
170 const ALIB_QTCHAR_4* end= b + l;
171 while( b < end )
172 result.append( uint(*b++) );
173 return result;
174 }
175};
176
177#endif //DOXYGEN
178
179} // namespace [alib::characters]
180
181
182#endif // !defined(ALIB_QT_LIB_NOT_FOUND) // this is only set in an automated test project
183#endif // HPP_ALIB_COMPATIBILITY_QT_CHARACTERS
184
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
static constexpr Policy Access
static integer Length(const TStringSource &src)
static TStringSource Construct(const TChar *array, integer length)
static constexpr Policy Construction
static const TChar * Buffer(const TStringSource &src)
static constexpr Policy Construction
static constexpr Policy Access
static const TChar * Buffer(const TStringSource &src)
static TStringSource Construct(const TChar *array, integer length)
static integer Length(const TStringSource &src)