The writer class for associative containers. More...
#include <metawriters.h>
Inherited by QtJsonSerializer::MetaWriters::Implementations::AssociativeWriterImpl< TContainer, TKey, TValue >, QtJsonSerializer::MetaWriters::Implementations::AssociativeWriterImpl< QHash, QString, QVariant >, and QtJsonSerializer::MetaWriters::Implementations::AssociativeWriterImpl< QMap, QString, QVariant >.
Classes | |
struct | AssociationInfo |
Information about a associative container. More... | |
Public Member Functions | |
virtual AssociationInfo | info () const =0 |
Return the information for the wrapped container. | |
virtual void | add (const QVariant &key, const QVariant &value)=0 |
Inserts the given value for the given key into the container. | |
Static Public Member Functions | |
template<template< typename, typename > class TContainer, typename TKey , typename TValue > | |
static void | registerWriter () |
Registers a container factory for the given container, key and value classes. More... | |
static void | registerWriter (int metaTypeId, AssociativeWriterFactory *factory) |
Registers a container factory for the given container, key and value classes. More... | |
static bool | canWrite (int metaTypeId) |
Checks if a writer exists for the given type. | |
static QSharedPointer< AssociativeWriter > | getWriter (QVariant &data) |
Returns a writer instance for the given data, or nullptr if none found. | |
static AssociationInfo | getInfo (int metaTypeId) |
Returns the information details of the given type. | |
The writer class for associative containers.
The associative writer is used to provide write access to such containers. They must first be registered via Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE
and then via AssociativeWriter::registerWriter. For most containers, you can simply use the generic variant of this method. If you have containers that are not supported by the generic variant, extend the writer instead and use the non-generic variant of the method.
Definition at line 73 of file metawriters.h.
struct QtJsonSerializer::MetaWriters::AssociativeWriter::AssociationInfo |
Information about a associative container.
Definition at line 79 of file metawriters.h.
Class Members | ||
---|---|---|
int | keyType | The type of the associations keys. |
int | valueType | The type of the associations values. |
|
static |
Registers a container factory for the given container, key and value classes.
TContainer | The container class to register the writer for |
TKey | The type of keys used to access elements of the container |
TValue | The type of elements held by the container |
This methods assumes a type of the format TContainer<TKey, TValue>
exists. Furthermore, the container must provide the following method:
TReturn insert(TKey, TValue)
Definition at line 290 of file metawriters.h.
|
static |
Registers a container factory for the given container, key and value classes.
metaTypeId | The type to register the writer for |
factory | A factory to create writer instances for the given type |
Use this method if the generic one does not work for you. You have to implement the AssociativeWriter and provide a AssociativeWriterFactory that generates it.