WIP: enabling QLatin1String, QStringView, QByteArrayView for GSI

This commit is contained in:
Matthias Koefferlein 2021-12-02 20:30:19 +01:00
parent bc26fd6333
commit e72060407c
3 changed files with 265 additions and 2 deletions

View File

@ -309,6 +309,7 @@ drop_class "QWeakPointer"
drop_enum_const "QEvent", /CocoaRequestModal/ # not available on WIN
drop_method "QDeadlineTimer", /QDeadlineTimer::_q_data/ # internal (@@@ TODO: QDealineTimer is present twice?)
drop_method "QObject", /QObject::bindingStorage/ # no QBindingStorage
drop_method "QPluginLoader", /QPluginLoader::staticPlugins/ # no QStaticPlugin
drop_method "QKeyCombination", /QKeyCombination::operator<\(/ # deleted
@ -444,8 +445,8 @@ drop_method "", /::operator\s*==\(const\s+QVariant\s*&\w+,\s*const\s+QVariantCom
drop_method "", /::operator\s*!=\(const\s+QVariant\s*&\w+,\s*const\s+QVariantComparisonHelper/ # requires QVariantComparisonHelper
drop_method "QByteArrayMatcher", /QByteArrayMatcher::indexIn\(const\s+QByteArray/ # clashes with const char * variant
drop_method "QRegion", /QRegion::setRects/ # gets a new implementation
drop_method "QRegion", /QRegion::crbegin/ # iterator not available
drop_method "QRegion", /QRegion::crend/ # iterator not available
drop_method "QRegion", /QRegion::c?rbegin/ # iterator not available
drop_method "QRegion", /QRegion::c?rend/ # iterator not available
drop_method "QTimer", /static\s+void\s+QTimer::singleShot\(/ # requires slots, alternative impl?
drop_method "QDebug", /QDebug::operator\s*<<\((?!const\s+QString\s*&)/ # don't map the others right now - too many (TODO: how to map?)
drop_method "", /::operator\s*<<\(QDebug\s*\w*\s*,\s*(?!const\s+QString\s*&)/ # don't map the others right now - too many (TODO: how to map?)
@ -836,6 +837,8 @@ drop_method "QTextDocument", /QTextDocument::resourceProvider/ # needs std::func
drop_method "QTextDocument", /QTextDocument::setResourceProvider/ # needs std::function
drop_method "QTextDocument", /QTextDocument::defaultResourceProvider/ # needs std::function
drop_method "QTextDocument", /QTextDocument::setDefaultResourceProvider/ # needs std::function
drop_method "QLabel", /QLabel::resourceProvider/ # needs std::function
drop_method "QLabel", /QLabel::setResourceProvider/ # needs std::function
drop_method "QAccessibleInterface", /QAccessibleInterface::editableTextInterface/ # requires QAccessibleEditableTextInterface which is not available
drop_method "QAccessibleInterface", /QAccessibleInterface::tableInterface/ # requires QAccessibleTableInterface which is not available
drop_method "QAccessibleInterface", /QAccessibleInterface::textInterface/ # requires QAccessibleTextInterface which is not available

View File

@ -895,6 +895,158 @@ private:
mutable QByteArray m_s_utf8;
};
#if QT_VERSION >= 0x60000
/**
* @brief Specialization for QString
*/
template <>
class GSI_PUBLIC StringAdaptorImpl<QStringView>
: public StringAdaptor
{
public:
StringAdaptorImpl (QStringView *s)
: mp_s (s), m_is_const (false)
{
// .. nothing yet ..
}
StringAdaptorImpl (const QStringView *s)
: mp_s (const_cast<QStringView *> (s)), m_is_const (true)
{
// .. nothing yet ..
}
StringAdaptorImpl (const QStringView &s)
: m_is_const (false), m_s (s)
{
mp_s = &m_s;
}
StringAdaptorImpl ()
: m_is_const (false)
{
mp_s = &m_s;
}
virtual ~StringAdaptorImpl ()
{
// .. nothing yet ..
}
virtual size_t size () const
{
return mp_s->toUtf8 ().size ();
}
virtual const char *c_str () const
{
m_s_utf8 = mp_s->toUtf8 ();
return m_s_utf8.constData ();
}
virtual void set (const char *c_str, size_t s, tl::Heap &heap)
{
if (! m_is_const) {
QString *hstr = heap.create<QString> ();
*hstr = QString::fromUtf8 (c_str, int (s));
*mp_s = QStringView (hstr->constData (), hstr->size ());
}
}
virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const
{
StringAdaptorImpl<QStringView> *s = dynamic_cast<StringAdaptorImpl<QStringView> *>(target);
if (s) {
QString *hstr = heap.create<QString> ();
*hstr = mp_s->toString ();
*s->mp_s = QStringView (hstr->constData (), hstr->size ());
} else {
StringAdaptor::copy_to (target, heap);
}
}
private:
QStringView *mp_s;
bool m_is_const;
QStringView m_s;
mutable QByteArray m_s_utf8;
};
/**
* @brief Specialization for QLatin1String
*/
template <>
class GSI_PUBLIC StringAdaptorImpl<QLatin1String>
: public StringAdaptor
{
public:
StringAdaptorImpl (QLatin1String *s)
: mp_s (s), m_is_const (false)
{
// .. nothing yet ..
}
StringAdaptorImpl (const QLatin1String *s)
: mp_s (const_cast<QLatin1String *> (s)), m_is_const (true)
{
// .. nothing yet ..
}
StringAdaptorImpl (const QLatin1String &s)
: m_is_const (false), m_s (s)
{
mp_s = &m_s;
}
StringAdaptorImpl ()
: m_is_const (false)
{
mp_s = &m_s;
}
virtual ~StringAdaptorImpl ()
{
// .. nothing yet ..
}
virtual size_t size () const
{
return mp_s->toString ().toUtf8 ().size ();
}
virtual const char *c_str () const
{
m_s_utf8 = mp_s->toString ().toUtf8 ();
return m_s_utf8.constData ();
}
virtual void set (const char *c_str, size_t s, tl::Heap &)
{
if (! m_is_const) {
*mp_s = QLatin1String (QString::fromUtf8 (c_str, int (s)).toLatin1 ());
}
}
virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const
{
StringAdaptorImpl<QLatin1String> *s = dynamic_cast<StringAdaptorImpl<QLatin1String> *>(target);
if (s) {
*s->mp_s = *mp_s;
} else {
StringAdaptor::copy_to (target, heap);
}
}
private:
QLatin1String *mp_s;
bool m_is_const;
QLatin1String m_s;
mutable QByteArray m_s_utf8;
};
#endif
#endif
/**
@ -1211,6 +1363,84 @@ private:
QByteArray m_s;
};
#if QT_VERSION > 0x60000
/**
* @brief Specialization for QByteArray
*/
template <>
class GSI_PUBLIC ByteArrayAdaptorImpl<QByteArrayView>
: public ByteArrayAdaptor
{
public:
ByteArrayAdaptorImpl (QByteArrayView *s)
: mp_s (s), m_is_const (false)
{
// .. nothing yet ..
}
ByteArrayAdaptorImpl (const QByteArrayView *s)
: mp_s (const_cast<QByteArrayView *> (s)), m_is_const (true)
{
// .. nothing yet ..
}
ByteArrayAdaptorImpl (const QByteArrayView &s)
: m_is_const (false), m_s (s)
{
mp_s = &m_s;
}
ByteArrayAdaptorImpl ()
: m_is_const (false)
{
mp_s = &m_s;
}
virtual ~ByteArrayAdaptorImpl ()
{
// .. nothing yet ..
}
virtual size_t size () const
{
return mp_s->size ();
}
virtual const char *c_str () const
{
return mp_s->constData ();
}
virtual void set (const char *c_str, size_t s, tl::Heap &heap)
{
if (! m_is_const) {
QByteArray *str = heap.create<QByteArray> ();
*str = QByteArray (c_str, s);
*mp_s = QByteArrayView (str->constData (), str->size ());
}
}
virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const
{
ByteArrayAdaptorImpl<QByteArrayView> *s = dynamic_cast<ByteArrayAdaptorImpl<QByteArrayView> *>(target);
if (s) {
QByteArray *str = heap.create<QByteArray> ();
*str = QByteArray (mp_s->constData (), mp_s->size ());
*s->mp_s = *str;
} else {
ByteArrayAdaptor::copy_to (target, heap);
}
}
private:
QByteArrayView *mp_s;
bool m_is_const;
QByteArrayView m_s;
};
#endif
#endif
/**

View File

@ -46,6 +46,11 @@
#include <QSet>
#include <QList>
#include <QStringList>
# if QT_VERSION >= 0x60000
# include <QByteArrayView>
# include <QLatin1String>
# include <QStringView>
# endif
#endif
namespace tl
@ -440,6 +445,11 @@ template <> struct type_traits<QStringRef> : generic_type_trait
template <> struct type_traits<QByteArray> : generic_type_traits<byte_array_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<std::vector<char> > : generic_type_traits<byte_array_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<QVariant> : generic_type_traits<var_tag, VariantAdaptor, T_var> { };
#if QT_VERSION >= 0x60000
template <> struct type_traits<QStringView> : generic_type_traits<string_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QLatin1String> : generic_type_traits<string_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QByteArrayView> : generic_type_traits<byte_array_tag, StringAdaptor, T_byte_array> { };
#endif
#endif
template <> struct type_traits<tl::Variant> : generic_type_traits<var_tag, VariantAdaptor, T_var> { };
@ -473,6 +483,11 @@ template <> struct type_traits<const QStringRef &> : generic_type_trait
template <> struct type_traits<const QByteArray &> : generic_type_traits<byte_array_cref_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<const std::vector<char> &> : generic_type_traits<byte_array_cref_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<const QVariant &> : generic_type_traits<var_cref_tag, VariantAdaptor, T_var> { };
#if QT_VERSION >= 0x60000
template <> struct type_traits<const QStringView &> : generic_type_traits<string_cref_tag, StringAdaptor, T_string> { };
template <> struct type_traits<const QLatin1String &> : generic_type_traits<string_cref_tag, StringAdaptor, T_string> { };
template <> struct type_traits<const QByteArrayView &> : generic_type_traits<byte_array_cref_tag, StringAdaptor, T_byte_array> { };
#endif
#endif
template <> struct type_traits<const tl::Variant &> : generic_type_traits<var_cref_tag, VariantAdaptor, T_var> { };
template <> struct type_traits<const char * const &> : generic_type_traits<string_cref_tag, StringAdaptor, T_string> { };
@ -503,6 +518,11 @@ template <> struct type_traits<QStringRef &> : generic_type_trait
template <> struct type_traits<QByteArray &> : generic_type_traits<byte_array_ref_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<std::vector<char> &> : generic_type_traits<byte_array_ref_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<QVariant &> : generic_type_traits<var_ref_tag, VariantAdaptor, T_var> { };
#if QT_VERSION >= 0x60000
template <> struct type_traits<QStringView &> : generic_type_traits<string_ref_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QLatin1String &> : generic_type_traits<string_ref_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QByteArrayView &> : generic_type_traits<byte_array_ref_tag, StringAdaptor, T_byte_array> { };
#endif
#endif
template <> struct type_traits<tl::Variant &> : generic_type_traits<var_ref_tag, VariantAdaptor, T_var> { };
template <> struct type_traits<const char * &> : generic_type_traits<string_ref_tag, StringAdaptor, T_string> { };
@ -534,6 +554,11 @@ template <> struct type_traits<const QStringRef *> : generic_type_trait
template <> struct type_traits<const QByteArray *> : generic_type_traits<byte_array_cptr_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<const std::vector<char> *> : generic_type_traits<byte_array_cptr_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<const QVariant *> : generic_type_traits<var_cptr_tag, VariantAdaptor, T_var> { };
#if QT_VERSION >= 0x60000
template <> struct type_traits<const QStringView *> : generic_type_traits<string_cptr_tag, StringAdaptor, T_string> { };
template <> struct type_traits<const QLatin1String *> : generic_type_traits<string_cptr_tag, StringAdaptor, T_string> { };
template <> struct type_traits<const QByteArrayView *> : generic_type_traits<byte_array_cptr_tag, StringAdaptor, T_byte_array> { };
#endif
#endif
template <> struct type_traits<const tl::Variant *> : generic_type_traits<var_cptr_tag, VariantAdaptor, T_var> { };
template <> struct type_traits<const char * const *> : generic_type_traits<string_cptr_tag, StringAdaptor, T_string> { };
@ -565,6 +590,11 @@ template <> struct type_traits<QStringRef *> : generic_type_trait
template <> struct type_traits<QByteArray *> : generic_type_traits<byte_array_ptr_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<std::vector<char> *> : generic_type_traits<byte_array_ptr_tag, StringAdaptor, T_byte_array> { };
template <> struct type_traits<QVariant *> : generic_type_traits<var_ptr_tag, VariantAdaptor, T_var> { };
#if QT_VERSION >= 0x60000
template <> struct type_traits<QStringView *> : generic_type_traits<string_ptr_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QLatin1String *> : generic_type_traits<string_ptr_tag, StringAdaptor, T_string> { };
template <> struct type_traits<QByteArrayView *> : generic_type_traits<byte_array_ptr_tag, StringAdaptor, T_byte_array> { };
#endif
#endif
template <> struct type_traits<tl::Variant *> : generic_type_traits<var_ptr_tag, VariantAdaptor, T_var> { };
template <> struct type_traits<const char * *> : generic_type_traits<string_ptr_tag, StringAdaptor, T_string> { };