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 3a5c4123 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

small changes

parent 4c8a5b4a
This diff is collapsed.
/****************************************************************************
* **
* ** Copyright (C) 2018 MinMaxMedical.
* ** All rights reserved.
* ** Contact: MinMaxMedical <InCAS@MinMaxMedical.com>
* **
* ** This file is part of the modmedLog module.
* **
* ** $QT_BEGIN_LICENSE:BSD$
* ** You may use this file under the terms of the BSD license as follows:
* **
* ** "Redistribution and use in source and binary forms, with or without
* ** modification, are permitted provided that the following conditions are
* ** met:
* ** * Redistributions of source code must retain the above copyright
* ** notice, this list of conditions and the following disclaimer.
* ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in
* ** the documentation and/or other materials provided with the
* ** distribution.
* ** * Neither the name of MinMaxMedical S.A.S. and its Subsidiary(-ies) nor
* ** the names of its contributors may be used to endorse or promote
* ** products derived from this software without specific prior written
* ** permission.
* **
* ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
* ** $QT_END_LICENSE$
* **
* ****************************************************************************/
#pragma once
#include <type_traits>
#include <QtCore/qdatastream.h>
#include <QtCore/qvariant.h>
#include "QBind_impl.h"
// //////////////////////////////////////////////////////////////////////////
// QBind<QDataStream*,T> support using operator<< for all registered types and containers, or GenericBind with DataTag
//! \warning As with QDataStream, QDataWriter and QDataReader must:
//! - bind the same C++ root data type (when unknown, QVariant can be used on both side)
//! - use the same set of registered QMetaTypeIds with operator<< defined
//! - use compatible ByteOrder, FloatingPointPrecision, and Version
class QDataWriter : public IWriter// allows runtime flexibility using a compile-time QWriter but loses smaller numeric types
{
Q_DISABLE_COPY(QDataWriter)
public:
QDataWriter(QDataStream* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
Val<Cur<QDataWriter>> value ( ) { return Cur<QDataWriter>(this).value() ; }
Val<Cur<QDataWriter>> meta ( QMetaData&& m) { return Cur<QDataWriter>(this).value().meta (m); }
Val<Cur<QDataWriter>> meta ( QMetaData& m) { return Cur<QDataWriter>(this).value().meta (m); }
Seq<Cur<QDataWriter>> sequence(quint32* s=nullptr) { return Cur<QDataWriter>(this).value().sequence(s); }
template<typename T> QWriter bind(T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); } //!< Only the standard QWriter is compatible with QWritable
protected:
friend class Cur<QDataWriter>;
bool _sequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _record (quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _null ( ) { *io << nullptr; return true; }
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); }
template<typename T>
bool _bind ( T& t) { *io << t; return true; } // Use QVariant to explicit the parts that may be unknown to the reader
bool _isOk() { return io && io->status()==QDataStream::Ok; }
bool _out( ) { return true; }
bool _item( ) { return true; }
bool _item(QUtf8String&) { return true; } // record keys are implicit, maps should be serialized as a sequence of records with key and value items
bool _item( QName) { return true; } // for QBaseWriter
private:
QDataStream* io;
};
template<typename T> struct BindSupport<QDataWriter,T> : BindSupport<IWriter,T> {};
// TODO BindNative smallest numeric types
template<> struct BindSupport<QDataWriter, qint32&> : BindNative {};
template<> struct BindSupport<QDataWriter,quint32&> : BindNative {};
// TODO BindNative all types for which T stream operators are defined : QMetaTypeId<typename std::remove_reference<typename std::remove_cv<T>>>::Defined ?
template<> struct BindSupport<QDataWriter, QColor&> : BindNative {};
template<typename T> struct BindSupport<QDataWriter, T&,typename std::enable_if<
QtPrivate::IsAssociativeContainer<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::Value // Not handled correctly by _record()._item(k) which makes the keys implicit
>::type
> : BindNative {};
// --------------------------------------------------------------------------
// Providing a general QDataStreamReader may be deceiving because the QDataStream structure is implicit:
// A reader is assumed to specify exactly what to read based on the stream origin and version
// QVariant could be used though for parts which type are not known in advance
/****************************************************************************
* **
* ** Copyright (C) 2018 MinMaxMedical.
* ** All rights reserved.
* ** Contact: MinMaxMedical <InCAS@MinMaxMedical.com>
* **
* ** This file is part of the modmedLog module.
* **
* ** $QT_BEGIN_LICENSE:BSD$
* ** You may use this file under the terms of the BSD license as follows:
* **
* ** "Redistribution and use in source and binary forms, with or without
* ** modification, are permitted provided that the following conditions are
* ** met:
* ** * Redistributions of source code must retain the above copyright
* ** notice, this list of conditions and the following disclaimer.
* ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in
* ** the documentation and/or other materials provided with the
* ** distribution.
* ** * Neither the name of MinMaxMedical S.A.S. and its Subsidiary(-ies) nor
* ** the names of its contributors may be used to endorse or promote
* ** products derived from this software without specific prior written
* ** permission.
* **
* ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
* ** $QT_END_LICENSE$
* **
* ****************************************************************************/
#pragma once
#include <type_traits>
#include <QtCore/qdatastream.h>
#include <QtCore/qvariant.h>
#include "QBind_impl.h"
// //////////////////////////////////////////////////////////////////////////
// QBind<QDataStream*,T> support using operator<< for all registered types and containers, or GenericBind with DataTag
//! \warning As with QDataStream, QDataWriter and QDataReader must:
//! - bind the same C++ root data type (when unknown, QVariant can be used on both side)
//! - use the same set of registered QMetaTypeIds with operator<< defined
//! - use compatible ByteOrder, FloatingPointPrecision, and Version
class QDataWriter : public IWriter // allows runtime flexibility using a compile-time QWriter but handles smaller numeric types
{
Q_DISABLE_COPY(QDataWriter)
public:
QDataWriter(QDataStream* io) : io(io) { Q_ASSERT(io); }
// Shortcuts
Val<Cur<QDataWriter>> value ( ) { return Cur<QDataWriter>(this).value() ; }
Val<Cur<QDataWriter>> meta ( QMetaData&& m) { return Cur<QDataWriter>(this).value().meta (m); }
Val<Cur<QDataWriter>> meta ( QMetaData& m) { return Cur<QDataWriter>(this).value().meta (m); }
Seq<Cur<QDataWriter>> sequence(quint32* s=nullptr) { return Cur<QDataWriter>(this).value().sequence(s); }
template<typename T> QWriter bind(T&& t) { return QWriter(this).value().bind(std::forward<T>(t)); } //!< Only the standard QWriter is compatible with QWritable
protected:
friend class Cur<QDataWriter>;
bool _sequence(quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _record (quint32* s=nullptr) { if (s) *io << *s; return true; }
bool _null ( ) { *io << nullptr; return true; }
bool _bind ( const char* s) { QByteArray ba = QByteArray::fromRawData(s, int(qstrlen(s))); return _bind(ba); }
template<typename T>
bool _bind ( T&& t) { *io << t; return true; } // Use QVariant to explicit the parts that may be unknown to the reader
bool _isOk() { return io && io->status()==QDataStream::Ok; }
bool _out ( ) { return true; }
bool _item( ) { return true; }
bool _item(QUtf8String&) { return true; } // record keys are implicit, maps should be serialized as a sequence of records with key and value items
bool _item( QName) { return true; } // for QBaseWriter
private:
QDataStream* io;
};
template<typename T> struct BindSupport<QDataWriter,T> : BindSupport<IWriter,T> {};
// TODO BindNative smallest numeric types
template<> struct BindSupport<QDataWriter, qint32&> : BindNative {};
template<> struct BindSupport<QDataWriter,quint32&> : BindNative {};
// TODO BindNative all types for which T stream operators are defined : QMetaTypeId<typename std::remove_reference<typename std::remove_cv<T>>>::Defined ?
template<> struct BindSupport<QDataWriter, QColor&> : BindNative {};
template<typename T> struct BindSupport<QDataWriter, T&,typename std::enable_if<
QtPrivate::IsAssociativeContainer<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::Value // Not handled correctly by _record()._item(k) which makes the keys implicit
>::type
> : BindNative {};
// --------------------------------------------------------------------------
// Providing a general QDataStreamReader may be deceiving because the QDataStream structure is implicit:
// A reader is assumed to specify exactly what to read based on the stream origin and version
// QVariant could be used though for parts which type are not known in advance
This diff is collapsed.
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