Commit 915b93fc authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

Minor QData* improvements

parent b59d09c6
......@@ -253,7 +253,7 @@ protected:
bool _sequence(quint32* =nullptr) { if (current().isArray ()) { steps.push(Step()); return true; } _reportError(qBindExpectedSequence); return false; }
bool _record (quint32* =nullptr) { if (current().isMap ()) { steps.push(Step()); return true; } _reportError(qBindExpectedRecord ); return false; }
bool _null ( ) { if (current().isNull ()) { return true; } _reportError(qBindExpectedNull ); return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s) ) { u . set (s.toUtf8() ); return true; } return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool _bind ( QString& v) { if (current().isString ()) { v = current().toString (); return true; } _reportError(qBindExpectedText ); return false; }
bool _bind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } _reportError(qBindExpectedBoolean ); return false; }
bool _bind ( qint64& t) { if (current().isInteger ()) { t = current().toInteger (); return true; } _reportError(qBindExpectedInteger ); return false; }
......@@ -304,7 +304,7 @@ protected:
skipTag(); if (isMap () && enterContainer()) { levels.push(Level()); return true; } _reportError(qBindExpectedRecord ); return false; }
bool _null ( ) { if (caching) { cacheLevel++; return caching->_null() && cacheOut(); }
skipTag(); if (isNull () && next ()) { return true; } _reportError(qBindExpectedNull ); return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s)) { u.set(s.toUtf8()); return true; } return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s)) { u = s.toUtf8(); return true; } return false; }
bool _bind ( QString& s) { if (caching) { cacheLevel++; return caching->_bind(s) && cacheOut(); }
skipTag(); if (isString()) {
s.resize(0);
......
......@@ -13,7 +13,7 @@ struct Latin1 { static bool isValid(const char* s, int size); };
struct Utf8 { static bool isValid(const char* s, int size); };
template<class TContent> class QDataView;
// ...
//! Associates a QByteArray with TContent type to allow static checks and optimizations when data is transferred
template<class TContent> class QData
{
......@@ -30,10 +30,10 @@ public:
constexpr bool isNull() const noexcept { return m_bytes.isNull (); }
constexpr bool isEmpty() const noexcept { return m_bytes.isEmpty(); }
constexpr int size() const noexcept { return m_bytes.size (); }
constexpr const char* data() const noexcept { return m_bytes.data(); }
constexpr const char* data() const noexcept { return m_bytes.data (); }
void set(QByteArray&& b) noexcept { m_bytes=b; }
void set(QByteArray& b) noexcept { m_bytes=b; }
QData& operator=( QByteArray&& b) noexcept { m_bytes=b; Q_ASSERT(Content::isValid(m_bytes.data(), m_bytes.size())); return *this; }
QData& operator=(const QByteArray& b) noexcept { m_bytes=b; Q_ASSERT(Content::isValid(m_bytes.data(), m_bytes.size())); return *this; }
protected:
template<class T> friend bool operator==(const QData <T> &a, const QData <T> &b) noexcept;
template<class T> friend bool operator!=(const QData <T> &a, const QData <T> &b) noexcept;
......@@ -159,8 +159,9 @@ class QUtf8Data : public QData<Utf8>
{
public:
using QData::QData;
using QData::operator=;
const QByteArray& utf8() const noexcept { return m_bytes; }
const QByteArray utf8() const noexcept { return m_bytes; }
protected:
friend QDataStream &operator<<(QDataStream &out, const QUtf8Data &p) { return out << QString(p.m_bytes); }
friend QDataStream &operator>>(QDataStream &out, QUtf8Data &p) { QString s; out >> s; p.m_bytes = s.toUtf8(); return out; }
......@@ -174,7 +175,7 @@ class QAsciiData : public QData<Ascii>
public:
using QData::QData;
const QByteArray& utf8() const noexcept { return m_bytes; }
const QByteArray utf8() const noexcept { return m_bytes; }
constexpr QLatin1String latin1() const noexcept { return QLatin1String(m_bytes.data(), m_bytes.size()); }
};
Q_DECLARE_METATYPE(QAsciiData)
......
......@@ -126,7 +126,7 @@ protected:
bool _record (quint32* =nullptr) { if (current().isObject()) { steps.push(Step());
return true; } _reportError(qBindExpectedRecord ); return false; }
bool _null ( ) { if (current().isNull ()) { return true; } _reportError(qBindExpectedNull ); return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s) ) { u . set(s.toUtf8() ); return true; } return false; }
bool _bind ( QUtf8Data& u) { QString s; if (_bind(s) ) { u = s .toUtf8 (); return true; } return false; }
bool _bind ( QString& v) { if (current().isString()) { v = current().toString(); return true; } _reportError(qBindExpectedText ); return false; }
bool _bind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } _reportError(qBindExpectedBoolean ); return false; }
bool _bind ( qint64& t) { double d; if (_bind(d) ) { t = qint64(d) ; return true; } return false; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment