17 #ifndef NURIA_SERIALIZER_HPP
18 #define NURIA_SERIALIZER_HPP
20 #include "essentials.hpp"
21 #include "metaobject.hpp"
22 #include <QStringList>
28 class SerializerPrivate;
76 InfiniteRecursion = -3
109 ValueConverter valueConverter = defaultValueConverter);
117 QVector< QByteArray > exclude ()
const;
124 void setExclude (
const QVector< QByteArray > &list);
130 QVector< QByteArray > allowedTypes ()
const;
135 void setAllowedTypes (
const QVector< QByteArray > &list)
const;
140 QStringList failedFields ()
const;
146 int recursionDepth ()
const;
151 void setRecursionDepth (
int maxDepth);
165 void *deserialize (
const QVariantMap &data, MetaObject *meta);
168 void *deserialize (
const QVariantMap &data,
const QByteArray &typeName);
171 template<
typename T >
173 MetaObject *meta = MetaObject::of< T > ();
174 return meta ?
reinterpret_cast< T *
> (deserialize (data, meta)) :
nullptr;
182 bool populate (
void *
object, MetaObject *meta,
const QVariantMap &data);
185 bool populate (
void *
object,
const QByteArray &typeName,
const QVariantMap &data);
188 template<
typename T >
189 bool populate (T *
object,
const QVariantMap &data) {
190 MetaObject *meta = MetaObject::of< T > ();
191 return meta ? populate (
object, meta, data) :
false;
208 QVariantMap serialize (
void *
object, MetaObject *meta);
211 QVariantMap serialize (
void *
object,
const QByteArray &typeName);
217 static MetaObject *defaultMetaObjectFinder (
const QByteArray &typeName);
223 static void *defaultInstanceCreator (MetaObject *metaObject, QVariantMap &data);
229 static bool defaultValueConverter (QVariant &variant,
int toType);
232 SerializerPrivate *d;
234 QVariantMap serializeImpl (
void *
object, MetaObject *meta);
235 bool populateImpl (
void *
object, MetaObject *meta,
const QVariantMap &data);
236 bool variantToField (QVariant &value,
const QByteArray &targetType,
237 int targetId,
int sourceId,
int pointerId,
bool &ignored);
238 bool fieldToVariant (QVariant &value,
bool &ignore);
240 bool writeField (
void *
object,
Nuria::MetaField &field,
const QVariantMap &data);
245 #endif // NURIA_SERIALIZER_HPP
(De-)Serializer for arbitary types based on Nuria::MetaObject.
Definition: serializer.hpp:71
bool populate(T *object, const QVariantMap &data)
Definition: serializer.hpp:189
T * deserialize(const QVariantMap &data)
Definition: serializer.hpp:172
Definition: abstractsessionmanager.hpp:24
std::function< MetaObject *(const QByteArray &) > MetaObjectFinder
Definition: serializer.hpp:84
std::function< bool(QVariant &, int) > ValueConverter
Definition: serializer.hpp:102
std::function< void *(MetaObject *, QVariantMap &) > InstanceCreator
Definition: serializer.hpp:95