Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Types | Static Private Member Functions | Private Attributes
omni::serialization::PropertyMap Class Reference

Property map to store properties in a QBuffer with an id. More...

#include <PropertyMap.h>

Inheritance diagram for omni::serialization::PropertyMap:
Inheritance graph
[legend]
Collaboration diagram for omni::serialization::PropertyMap:
Collaboration graph
[legend]

Public Member Functions

 PropertyMap ()
 
 PropertyMap (QDataStream &)
 Construct from stream. More...
 
template<typename T , typename... ARGS>
PropertyMapput (QString const &_id, T const &_t, ARGS &&..._args)
 Put an object of type T with id into property map. More...
 
template<typename T , typename... ARGS>
PropertyMap const & get (QString const &_id, T &_t, ARGS &&..._args) const
 Read an object of type T with id from property map. More...
 
template<typename T , typename... ARGS>
PropertyMap const & get (QString const &_id, T *_t, ARGS &&..._args) const
 Read an object of type T with id from property map. More...
 
template<typename T >
getValue (QString const &_id, T const &_default=T()) const
 Get value from id (with optional default value when id is not present) More...
 
template<typename FACTORY_FUNCTOR , typename... ARGS>
PropertyMap const & getPtr (QString const &_id, FACTORY_FUNCTOR _f, ARGS &&..._args) const
 Read an object of type T with id from property map. More...
 
template<typename T , typename CLASS , typename MEM_FN >
PropertyMap const & get (QString const &_id, CLASS &_class, MEM_FN _memFn, T const &_default=T()) const
 Get value from. More...
 
template<typename T , typename... ARGS>
PropertyMapoperator() (QString const &_id, T const &_t)
 Write an object into property map. More...
 
template<typename T >
PropertyMap const & operator() (QString const &_id, T &_t) const
 Read an object from property map. More...
 
std::vector< QString > ids () const
 Return list of ids. More...
 
void toStream (QDataStream &) const
 Write property map to stream. More...
 
void fromStream (QDataStream &)
 Read property map from stream. More...
 
- Public Member Functions inherited from omni::serialization::Interface
virtual ~Interface ()
 
virtual bool equal (Interface const *_that) const
 Optional virtual member method for testing equality of two. More...
 

Private Types

typedef std::map< QString,
QByteArray > 
property_map
 

Static Private Member Functions

static QString makeChecksum (QByteArray const &_b)
 Make MD5 checksum from byte array. More...
 
static QString makeChecksum (QString const &_s)
 Make MD5 checksum from byte array. More...
 
static QString makeChecksum (property_map const &_properties)
 Make MD5 checksum from property map. More...
 

Private Attributes

property_map properties_
 

Detailed Description

Property map to store properties in a QBuffer with an id.

Member Typedef Documentation

typedef std::map<QString, QByteArray> omni::serialization::PropertyMap::property_map
private

Constructor & Destructor Documentation

omni::serialization::PropertyMap::PropertyMap ( )
29  {
30  }
omni::serialization::PropertyMap::PropertyMap ( QDataStream &  _stream)

Construct from stream.

32  {
33  fromStream(_stream);
34  }
void fromStream(QDataStream &)
Read property map from stream.
Definition: PropertyMap.cpp:48

Member Function Documentation

void omni::serialization::PropertyMap::fromStream ( QDataStream &  _is)
virtual

Read property map from stream.

Implements omni::serialization::Interface.

48  {
49  QString _hash;
50  deserialize(_is,_hash);
51  uint32_t _size = 0;
52  _is >> _size;
53 
54  for (size_t i = 0; i < _size; ++i) {
55  QString _propertyHash;
56  QString _propertyId;
57  QByteArray _propertyData;
58  deserialize(_is,_propertyHash);
59  deserialize(_is,_propertyId);
60  deserialize(_is,_propertyData);
61  properties_[_propertyId] = _propertyData;
62 
63  if (_propertyHash != makeChecksum(_propertyData)) {
64  throw exception::ChecksumError(_propertyHash, makeChecksum(
65  properties_), _propertyId);
66  }
67  }
68 
69  if (_hash != makeChecksum(properties_)) {
70  throw exception::ChecksumError(_hash, makeChecksum(properties_));
71  }
72  }
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
property_map properties_
Definition: PropertyMap.h:226
static QString makeChecksum(QByteArray const &_b)
Make MD5 checksum from byte array.
Definition: PropertyMap.cpp:74
template<typename T , typename... ARGS>
PropertyMap const& omni::serialization::PropertyMap::get ( QString const &  _id,
T &  _t,
ARGS &&...  _args 
) const
inline

Read an object of type T with id from property map.

119  {
120  if (properties_.count(_id) == 0) {
121  //throw exception::PropertyNotExisting(_id);
122  //return;
123  return *this;
124  }
125 
126  QDataStream _s(properties_.at(_id));
127  deserialize(_s, _t, _args ...);
128  return *this;
129  }
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
property_map properties_
Definition: PropertyMap.h:226
template<typename T , typename... ARGS>
PropertyMap const& omni::serialization::PropertyMap::get ( QString const &  _id,
T *  _t,
ARGS &&...  _args 
) const
inline

Read an object of type T with id from property map.

133  {
134  if (properties_.count(_id) == 0) {
135  //throw exception::PropertyNotExisting(_id);
136  return *this;
137  }
138 
139  QDataStream _s(properties_.at(_id));
140  deserialize(_s, _t, _args ...);
141  return *this;
142  }
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
property_map properties_
Definition: PropertyMap.h:226
template<typename T , typename CLASS , typename MEM_FN >
PropertyMap const& omni::serialization::PropertyMap::get ( QString const &  _id,
CLASS &  _class,
MEM_FN  _memFn,
T const &  _default = T() 
) const
inline

Get value from.

175  {
176  T _value = _default;
177 
178  try {
179  get<T>(_id, _value);
180  _memFn(_class, _value);
181  } catch (exception::PropertyNotExisting& e) {
182  return *this;
183  }
184  return *this;
185  }
template<typename FACTORY_FUNCTOR , typename... ARGS>
PropertyMap const& omni::serialization::PropertyMap::getPtr ( QString const &  _id,
FACTORY_FUNCTOR  _f,
ARGS &&...  _args 
) const
inline

Read an object of type T with id from property map.

160  {
161  if (properties_.count(_id) == 0) {
162  throw exception::PropertyNotExisting(_id);
163  }
164  QDataStream _s(properties_.at(_id));
165  deserializePtr(_s, _f, _args ...);
166  return *this;
167  }
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
template<typename T >
T omni::serialization::PropertyMap::getValue ( QString const &  _id,
T const &  _default = T() 
) const
inline

Get value from id (with optional default value when id is not present)

146  {
147  if (properties_.count(_id) == 0) {
148  return _default;
149  }
150  T _t;
151  QDataStream _s(properties_.at(_id));
152  deserialize(_s, _t);
153  return _t;
154  }
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
property_map properties_
Definition: PropertyMap.h:226
std::vector<QString> omni::serialization::PropertyMap::ids ( ) const
inline

Return list of ids.

200  {
201  std::vector<QString> _ids;
202  for (auto& _idValue : properties_) {
203  _ids.push_back(_idValue.first);
204  }
205  return _ids;
206  }
property_map properties_
Definition: PropertyMap.h:226
QString omni::serialization::PropertyMap::makeChecksum ( QByteArray const &  _b)
staticprivate

Make MD5 checksum from byte array.

74  {
75  return QString(QCryptographicHash::hash(_b,QCryptographicHash::Sha1).toHex());
76  }
QString omni::serialization::PropertyMap::makeChecksum ( QString const &  _s)
staticprivate

Make MD5 checksum from byte array.

78  {
79  return makeChecksum(_s.toLatin1());
80  }
static QString makeChecksum(QByteArray const &_b)
Make MD5 checksum from byte array.
Definition: PropertyMap.cpp:74
QString omni::serialization::PropertyMap::makeChecksum ( property_map const &  _properties)
staticprivate

Make MD5 checksum from property map.

82  {
83  QString _merged;
84  _merged += QString("%1").arg(_properties.size());
85  for (auto& _property : _properties) {
86  _merged += _property.first;
87  _merged += makeChecksum(_property.second);
88  }
89  return makeChecksum(_merged);
90  }
static QString makeChecksum(QByteArray const &_b)
Make MD5 checksum from byte array.
Definition: PropertyMap.cpp:74
template<typename T , typename... ARGS>
PropertyMap& omni::serialization::PropertyMap::operator() ( QString const &  _id,
T const &  _t 
)
inline

Write an object into property map.

189  {
190  return put(_id, _t);
191  }
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
template<typename T >
PropertyMap const& omni::serialization::PropertyMap::operator() ( QString const &  _id,
T &  _t 
) const
inline

Read an object from property map.

195  {
196  return get(_id, _t);
197  }
template<typename T , typename... ARGS>
PropertyMap& omni::serialization::PropertyMap::put ( QString const &  _id,
T const &  _t,
ARGS &&...  _args 
)
inline

Put an object of type T with id into property map.

105  {
106  if (properties_.count(_id) != 0) {
107  throw exception::PropertyExisting(_id);
108  }
109  QBuffer _buf;
110  _buf.open(QIODevice::WriteOnly);
111  QDataStream _s(&_buf); // ,QIODevice::WriteOnly);
112  serialize(_s, _t, _args ...);
113  properties_[_id] = _buf.data();
114  return *this;
115  }
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
property_map properties_
Definition: PropertyMap.h:226
void omni::serialization::PropertyMap::toStream ( QDataStream &  _os) const
virtual

Write property map to stream.

Implements omni::serialization::Interface.

36  {
37 
39  _os << uint32_t(properties_.size());
40 
41  for (auto& _property : properties_) {
42  serialize(_os,makeChecksum(_property.second));
43  serialize(_os,_property.first);
44  serialize(_os,_property.second);
45  }
46  }
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
property_map properties_
Definition: PropertyMap.h:226
static QString makeChecksum(QByteArray const &_b)
Make MD5 checksum from byte array.
Definition: PropertyMap.cpp:74

Field Documentation

property_map omni::serialization::PropertyMap::properties_
private

The documentation for this class was generated from the following files: