Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit c6381067 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Renamings + fewer shortcut on Writer/Reader classes

parent 4c7a2f99
......@@ -57,21 +57,21 @@ protected: \
using QUtf8String = QByteArray; //!< QByteArray explicitely utf8 encoded at source level
using Name = const char*; //!< String literal explicitely utf8 encoded
using QName = const char*; //!< String literal explicitely utf8 encoded
// //////////////////////////////////////////////////////////////////////////
// Standard error names
static Name qBindExpectedNull = "Expected null" ;
static Name qBindExpectedSequence = "Expected sequence";
static Name qBindExpectedRecord = "Expected record" ;
static Name qBindExpectedText = "Expected text" ;
static Name qBindExpectedBytes = "Expected bytes" ;
static Name qBindExpectedDecimal = "Expected decimal" ;
static Name qBindExpectedBoolean = "Expected boolean" ;
static QName qBindExpectedNull = "Expected null" ;
static QName qBindExpectedSequence = "Expected sequence";
static QName qBindExpectedRecord = "Expected record" ;
static QName qBindExpectedText = "Expected text" ;
static QName qBindExpectedBytes = "Expected bytes" ;
static QName qBindExpectedDecimal = "Expected decimal" ;
static QName qBindExpectedBoolean = "Expected boolean" ;
static Name qBindIgnoredCharacter = "Ignored character";
static Name qBindIgnoredBytes = "Ignored bytes" ;
static QName qBindIgnoredCharacter = "Ignored character";
static QName qBindIgnoredBytes = "Ignored bytes" ;
template<class T>
class QScopedChoice //!< for accurate error reporting
......@@ -92,22 +92,21 @@ private:
#include <QtCore/qstring.h>
//! QMetaData is data about current data (e.g. tag, attribute, style, etc.)
using QMetaData = std::map<Name,QString>;
using QMetaData = std::map<QName,QString>;
static Name qmType = "type";
static QName qmType = "type";
// N-dimensional data structures that specific IWriter can optimize
// N-dimensional data structures for which specific IWriter may have optimized implementations
// BEWARE though that nested calls to IWriter are not guaranteed to follow the declared structure (this would prevent reusing general QBind functors for nested data structures)
//! Sequence of records projected to columns (item names are always the same in a fixed order)
static Name qmColumns = "columns";// comma-separated names
static Name qmRows = "rows"; // comma-separated names (optional)
//! Sequence of records can be implemented as table with columns below (record item names are always the same in a fixed order)
static QName qmColumns = "columns" ; //!< comma-separated names
//! Sequence of nested non-empty sequences of definite sizes
static Name qmSizes = "sizes"; // comma-separated natural numbers
//! Sequence of nested non-empty sequences of definite sizes can be implemented as multi-dimensional array
static QName qmSizes = "sizes" ; //!< comma-separated natural numbers
//! Sequence of records where item(qmNodes) contains nested trees
static Name qmChildren = "children";
//! Sequence of records where item(qmNodes) contains children can be implemented as trees
static QName qmChildren = "children"; //!< name of a sequence of records with recursively the same name
// //////////////////////////////////////////////////////////////////////////
// QBind<TResult,T>
......@@ -254,7 +253,7 @@ public:
/**/ operator bool() { return m_out.operator bool(); } //!< to drive QBind<TResult,T>() traversal
TImpl* operator ->() { return m_out.operator ->(); }
Val<Rec<T_>> item( Name name) { QUtf8String n(name); // TODO use QUtf8String::fromRawData(key,int(strlen(key)) for Writers
Val<Rec<T_>> item( QName name) { QUtf8String n(name); // TODO use QUtf8String::fromRawData(key,int(strlen(key)) for Writers
if (Q_LIKELY(m_out) && m_out->_item(n )) return Val<Rec<T_>>(std::move(*this)); else return Val<Rec<T_>>(); }
Val<Rec<T_>> item(QUtf8String& name) { if (Q_LIKELY(m_out) && m_out->_item(name)) return Val<Rec<T_>>(std::move(*this)); else return Val<Rec<T_>>(); }
/**/ T_ out ( ) { if (Q_LIKELY(m_out) && m_out->_out ( )) return std::move(m_out) ; else return T_ (); }
......@@ -263,12 +262,12 @@ public:
TResult result() { return operator TResult(); }
// Shortcuts
/**/ Val<Rec<T_>> meta (Name n, QMetaData&& m) { return item(n).meta ( m); }
/**/ Val<Rec<T_>> meta (Name n, QMetaData& m) { return item(n).meta ( m); }
/**/ Seq<Rec<T_>> sequence(Name n, quint32* s=nullptr) { return item(n).sequence ( s); }
/**/ Rec<Rec<T_>> record (Name n, quint32* s=nullptr) { return item(n).record ( s); }
/**/ Rec<T_> null (Name n ) { return item(n).null ( ); }
template<typename T> Rec<T_> bind (Name n, T&& t) { return item(n).bind(std::forward<T>(t)); }
/**/ Val<Rec<T_>> meta (QName n, QMetaData&& m) { return item(n).meta ( m); }
/**/ Val<Rec<T_>> meta (QName n, QMetaData& m) { return item(n).meta ( m); }
/**/ Seq<Rec<T_>> sequence(QName n, quint32* s=nullptr) { return item(n).sequence ( s); }
/**/ Rec<Rec<T_>> record (QName n, quint32* s=nullptr) { return item(n).record ( s); }
/**/ Rec<T_> null (QName n ) { return item(n).null ( ); }
template<typename T> Rec<T_> bind (QName n, T&& t) { return item(n).bind(std::forward<T>(t)); }
private:
template<class TSrcResult, typename TDst, typename TEnabledIf> friend struct QBind; // restricting to <TSrcResult, Val<TDst>&&, IsReader<TSrcResult>>; is not possible in C++11
Val<TResult> _unsafeItem(QUtf8String& key) { if (Q_LIKELY(m_out) && m_out->_item(key)) return Val<TResult>(m_out._unsafeCopy()); else return Val<TResult>(); }
......@@ -311,8 +310,6 @@ public:
/**/ Val<TResult> meta ( QMetaData&& m) { return value().meta ( m); }
/**/ Val<TResult> meta ( QMetaData& m) { return value().meta ( m); }
/**/ Seq<TResult> sequence(quint32* s=nullptr) { return value().sequence ( s); }
/**/ Rec<TResult> record (quint32* s=nullptr) { return value().record ( s); }
/**/ TResult null ( ) { return value().null ( ); }
template<typename T> TResult bind ( T&& t) { return value().bind(std::forward<T>(t)); }
void reportError(const char* error) { if (m) m->reportError(error); }
......@@ -352,8 +349,6 @@ public:
/**/ Val<TResult> meta ( QMetaData&& m) { return value().meta ( m); }
/**/ Val<TResult> meta ( QMetaData& m) { return value().meta ( m); }
/**/ Seq<TResult> sequence(quint32* s=nullptr) { return value().sequence ( s); }
/**/ Rec<TResult> record (quint32* s=nullptr) { return value().record ( s); }
/**/ TResult null ( ) { return value().null ( ); }
template<typename T> TResult bind ( T&& t) { return value().bind(std::forward<T>(t)); }
void reportError(const char*) {} //!< \warning Not implemented since a TResult with BindMode::Write will not encounter bind mismatches but only write errors independent from the current state
......@@ -382,7 +377,7 @@ struct IWriter
virtual bool _record (quint32* size=nullptr) = 0;
virtual bool _null ( ) = 0;
virtual bool _item ( QUtf8String& name) = 0; // TODO Implement _item(Name n) instead
virtual bool _item ( QUtf8String& name) = 0; // TODO Implement _item(QName n) instead
virtual bool _item ( ) = 0;
virtual bool _bind ( const char* utf8) = 0;
......
......@@ -112,8 +112,6 @@ public:
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
/**/ Rec<QWriter> record (quint32* s=nullptr) { return QWriter(this).record ( s); }
/**/ QWriter null ( ) { return QWriter(this).null ( ); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
bool _isOk() { return io; }
......@@ -357,10 +355,14 @@ class QCborBuilder : public IWriter
{
Q_DISABLE_COPY(QCborBuilder)
public:
QCborBuilder(QCborValue* v) : value(v) { Q_ASSERT(v); }
QCborBuilder(QCborValue* v) : cbor(v) { Q_ASSERT(v); }
// Shortcuts
template<typename T> QWriter bind(T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ Val<QWriter> value ( ) { return QWriter(this).value ( ); }
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
virtual bool _sequence(quint32* rows=nullptr) { Q_UNUSED(rows); levels.push(Step(nullptr)); return true; }
virtual bool _record (quint32* cols=nullptr) { Q_UNUSED(cols); levels.push(Step("" )); return true; }
......@@ -377,7 +379,7 @@ protected:
private:
void set(const QCborValue& v) {
if (levels.isEmpty()) {
*value = v;
*cbor = v;
}
else {
if (!levels.last().key.isNull())
......@@ -387,7 +389,7 @@ private:
}
}
QCborValue* value;
QCborValue* cbor;
struct Step { QUtf8String key; /* TODO union */ QCborMap object; QCborArray array; Step(const char* k=nullptr) : key(k) {} };
QStack<Step> levels = QStack<Step>(); //!< minimal dynamic context to implement out() and ensure actual building in case QCborBuilderImpl is abandoned
};
......
......@@ -70,7 +70,7 @@ protected:
friend class QBaseWriter<QDataWriter>;
template<class T_> friend class Val; // calls methods below
bool _isOk() { return io && io->status()==QDataStream::Ok; } // for QBaseWriter
bool _isOk() { return io && io->status()==QDataStream::Ok; }
bool _sequence(quint32* rows=nullptr) { if (rows) *io << *rows; return true; }
bool _record (quint32* cols=nullptr) { if (cols) *io << *cols; return true; }
......
......@@ -56,10 +56,12 @@ class QJsonBuilder : public IWriter
{
Q_DISABLE_COPY(QJsonBuilder)
public:
QJsonBuilder(QJsonValue* v) : value(v) { Q_ASSERT(v); }
QJsonBuilder(QJsonValue* v) : json(v) { Q_ASSERT(v); }
// Shortcuts
template<typename T> QWriter bind(T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
/**/ Val<QWriter> value ( ) { return QWriter(this).value ( ); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* rows=nullptr) { Q_UNUSED(rows); levels.push(Step(nullptr)); return true; }
bool _record (quint32* cols=nullptr) { Q_UNUSED(cols); levels.push(Step("" )); return true; }
......@@ -76,7 +78,7 @@ protected:
private:
void set(const QJsonValue& v) {
if (levels.isEmpty()) {
*value = v;
*json = v;
}
else {
if (!levels.last().key.isNull())
......@@ -86,7 +88,7 @@ private:
}
}
QJsonValue* value;
QJsonValue* json;
struct Step { QUtf8String key; /* TODO union */ QJsonObject object; QJsonArray array; Step(const char* k=nullptr) : key(k) {} };
QStack<Step> levels = QStack<Step>(); //!< minimal dynamic context to implement out() and ensure actual building in case QJsonBuilderImpl is abandoned
};
......@@ -176,11 +178,7 @@ public:
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value ( ); }
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
/**/ Rec<QWriter> record (quint32* s=nullptr) { return QWriter(this).record ( s); }
/**/ QWriter null ( ) { return QWriter(this).null ( ); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
bool _sequence(quint32* rows=nullptr) { Q_UNUSED(rows); levels.push(Step{"","]"}); return io->write("["); }
......
......@@ -56,11 +56,7 @@ public:
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value ( ); }
/**/ Val<QWriter> meta ( QMetaData&& m) { return QWriter(this).meta ( m); }
/**/ Val<QWriter> meta ( QMetaData& m) { return QWriter(this).meta ( m); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
/**/ Rec<QWriter> record (quint32* s=nullptr) { return QWriter(this).record ( s); }
/**/ QWriter null ( ) { return QWriter(this).null ( ); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
template<typename T>
......
......@@ -110,6 +110,7 @@ public:
TextWriter(QIODevice* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
/**/ Val<QWriter> value ( ) { return QWriter(this).value ( ); }
/**/ Seq<QWriter> sequence(quint32* s=nullptr) { return QWriter(this).sequence ( s); }
template<typename T> QWriter bind ( T&& t) { return QWriter(this).bind(std::forward<T>(t)); }
protected:
......@@ -124,7 +125,7 @@ protected:
bool _item( ) { return io->write(" ") ; }
bool _out ( ) { return io->write("]") ; }
private:
QIODevice* io = nullptr; // for QBaseWriter
QIODevice* io;
};
template<> struct BindSupport<TextWriter,const char*> : BindNative {};
......
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