QtJsonSerializer  4.0.0
A library to perform generic seralization and deserialization of QObjects
Classes | Public Member Functions | Static Public Member Functions | List of all members
QtJsonSerializer::MetaWriters::AssociativeWriter Class Referenceabstract

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< AssociativeWritergetWriter (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.
 

Detailed Description

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.

See also
MetaWriters::AssociativeWriterFactory, MetaWriters::SequentialWriter

Definition at line 73 of file metawriters.h.


Class Documentation

◆ QtJsonSerializer::MetaWriters::AssociativeWriter::AssociationInfo

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.

Member Function Documentation

◆ registerWriter() [1/2]

template<template< typename, typename > class TContainer, typename TKey , typename TValue >
QtJsonSerializer::MetaWriters::AssociativeWriter::registerWriter ( )
static

Registers a container factory for the given container, key and value classes.

Template Parameters
TContainerThe container class to register the writer for
TKeyThe type of keys used to access elements of the container
TValueThe 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)
See also
AssociativeWriter::getWriter

Definition at line 290 of file metawriters.h.

◆ registerWriter() [2/2]

QtJsonSerializer::MetaWriters::AssociativeWriter::registerWriter ( int  metaTypeId,
AssociativeWriterFactory factory 
)
static

Registers a container factory for the given container, key and value classes.

Parameters
metaTypeIdThe type to register the writer for
factoryA 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.

See also
AssociativeWriter::getWriter, AssociativeWriterFactory

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