19 #ifndef OMNI_SERIALIZATION_PROPERTYMAP_H_
20 #define OMNI_SERIALIZATION_PROPERTYMAP_H_
28 #include <QDataStream>
36 namespace serialization {
43 ChecksumError(QString _got, QString _expected, QString const& _id = QString()) :
49 QString _s(
"ChecksumError: Expected %1, got %2.");
54 _s += QString(
" On id %1.").arg(QString(
id_));
72 return QString(
"Property with id %1 already exists!").arg(QString(
id_));
86 return QString(
"Property with id %1 does not exist!").arg(
id_);
104 template<
typename T,
typename ... ARGS>
110 _buf.open(QIODevice::WriteOnly);
111 QDataStream _s(&_buf);
118 template<
typename T,
typename ... ARGS>
119 PropertyMap const&
get(QString
const& _id, T& _t, ARGS&& ... _args)
const {
132 template<
typename T,
typename ... ARGS>
133 PropertyMap const&
get(QString
const& _id, T *_t, ARGS&& ... _args)
const {
146 T
getValue(QString
const& _id, T
const& _default = T())
const {
157 template<
typename FACTORY_FUNCTOR,
typename ... ARGS>
160 ARGS&& ... _args)
const {
171 template<
typename T,
typename CLASS,
typename MEM_FN>
175 T
const& _default = T())
const {
180 _memFn(_class, _value);
188 template<
typename T,
typename ... ARGS>
200 std::vector<QString>
ids()
const {
201 std::vector<QString> _ids;
203 _ids.push_back(_idValue.first);
T getValue(QString const &_id, T const &_default=T()) const
Get value from id (with optional default value when id is not present)
Definition: PropertyMap.h:146
QString id_
Definition: PropertyMap.h:62
std::vector< QString > ids() const
Return list of ids.
Definition: PropertyMap.h:200
QString message() const
Definition: PropertyMap.h:48
Abstract interface for serialization Holds two member functions for serialization and deserializatio...
Definition: Interface.h:31
void toStream(QDataStream &) const
Write property map to stream.
Definition: PropertyMap.cpp:36
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
QString message() const
Definition: PropertyMap.h:85
PropertyMap()
Definition: PropertyMap.cpp:28
#define OMNI_EXCEPTION(EXCEPTION)
Definition: exception.h:55
#define OMNI_DECL_STREAM_OPERATORS(CLASS)
Definition: Interface.h:53
QString got_
Definition: PropertyMap.h:60
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
STREAM & deserializePtr(STREAM &_stream, F _f, ARGS &&..._args)
Deserialize a pointer from stream. Functor f must return a pointer which is constructed from a facto...
Definition: pointer.h:78
property_map properties_
Definition: PropertyMap.h:226
QString id_
Definition: PropertyMap.h:76
Checksum exception which is raids when checksums mismatch.
Definition: PropertyMap.h:39
PropertyMap & put(QString const &_id, T const &_t, ARGS &&..._args)
Put an object of type T with id into property map.
Definition: PropertyMap.h:105
Definition: PropertyMap.h:65
PropertyMap const & operator()(QString const &_id, T &_t) const
Read an object from property map.
Definition: PropertyMap.h:195
PropertyMap const & getPtr(QString const &_id, FACTORY_FUNCTOR _f, ARGS &&..._args) const
Read an object of type T with id from property map.
Definition: PropertyMap.h:158
static QString makeChecksum(QByteArray const &_b)
Make MD5 checksum from byte array.
Definition: PropertyMap.cpp:74
Property map to store properties in a QBuffer with an id.
Definition: PropertyMap.h:96
std::map< QString, QByteArray > property_map
Definition: PropertyMap.h:215
QString message() const
Definition: PropertyMap.h:71
void fromStream(QDataStream &)
Read property map from stream.
Definition: PropertyMap.cpp:48
QString id_
Definition: PropertyMap.h:90
QString expected_
Definition: PropertyMap.h:61
PropertyMap & operator()(QString const &_id, T const &_t)
Write an object into property map.
Definition: PropertyMap.h:189
Definition: PropertyMap.h:79