Dataquay 0.8
|
ContainerBuilder is a utility class which assists with storage of arbitrary container objects into variant objects and subsequently retrieving them into lists. More...
#include <dataquay/objectmapper/ContainerBuilder.h>
Public Types | |
enum | ContainerKind { UnknownKind = 0 , SequenceKind , SetKind } |
ContainerKind describes the sort of behaviour a container displays with regard to ordering and structure. More... | |
Public Member Functions | |
template<typename T , typename Container > | |
void | registerContainer (QString typeName, QString containerName, ContainerKind kind) |
Register Container as a container of kind ContainerKind holding type T. | |
bool | canExtractContainer (QString containerName) |
Return true if the container named containerName can be extracted from a variant. | |
bool | canInjectContainer (QString containerName) |
Return true if the container named containerName can be injected into a variant. | |
QString | getTypeNameForContainer (QString containerName) |
Return the typeName that is associated with the given containerName. | |
ContainerKind | getContainerKind (QString containerName) |
Return the kind of the container with the given containerName. | |
QVariantList | extractContainer (QString containerName, const QVariant &v) |
Extract the named container type from the given variant object (which must hold that container type) and return a list of variants containing the individual elements in the container. | |
QVariant | injectContainer (QString containerName, const QVariantList &vl) |
Inject the named container type into a new variant object. | |
Static Public Member Functions | |
static ContainerBuilder * | getInstance () |
Retrieve the single global instance of ContainerBuilder. | |
ContainerBuilder is a utility class which assists with storage of arbitrary container objects into variant objects and subsequently retrieving them into lists.
Given types T and Container (where Container is typically something like QList<T>), ContainerBuilder can convert a QVariantList holding type T into a QVariant holding Container, and back again.
Definition at line 55 of file ContainerBuilder.h.
ContainerKind describes the sort of behaviour a container displays with regard to ordering and structure.
A container of kind SequenceKind is externally ordered (order must be preserved when serialising, for example); kind SetKind is unordered or internally ordered (its ordering does not need to be described).
Enumerator | |
---|---|
UnknownKind | |
SequenceKind | |
SetKind |
Definition at line 71 of file ContainerBuilder.h.
|
static |
Retrieve the single global instance of ContainerBuilder.
|
inline |
Register Container as a container of kind ContainerKind holding type T.
T must be something capable of being stored in a QVariant – so typically a primitive type, a Qt utility type such as QString, or a pointer type. Both T and Container must be registered as Qt metatypes using qRegisterMetaType.
The arguments typeName and containerName give the textual names for the types T and Container; these must be the same as were used when calling qRegisterMetaType.
For example, to register QStringList:
registerContainer<QString, QStringList> ("QString", "QStringList", SequenceKind);
Definition at line 95 of file ContainerBuilder.h.
|
inline |
Return true if the container named containerName can be extracted from a variant.
This is the case if containerName was the name of a container provided to an earlier call to registerContainer.
Definition at line 107 of file ContainerBuilder.h.
Referenced by extractContainer(), getContainerKind(), and getTypeNameForContainer().
|
inline |
Return true if the container named containerName can be injected into a variant.
This is the case if containerName was the name of a container provided to an earlier call to registerContainer.
Definition at line 117 of file ContainerBuilder.h.
Referenced by injectContainer().
|
inline |
Return the typeName that is associated with the given containerName.
That is, when registerContainer was called for a container with name containerName, typeName is the name that was given as the first argument of that call.
Definition at line 127 of file ContainerBuilder.h.
References canExtractContainer().
|
inline |
Return the kind of the container with the given containerName.
That is, when registerContainer was called for a container with name containerName, return the kind that was given as the final argument of that call.
Definition at line 138 of file ContainerBuilder.h.
References canExtractContainer(), and UnknownKind.
|
inline |
Extract the named container type from the given variant object (which must hold that container type) and return a list of variants containing the individual elements in the container.
Definition at line 148 of file ContainerBuilder.h.
References canExtractContainer().
|
inline |
Inject the named container type into a new variant object.
Taking a list of variants holding the individual elements in the container, return a single variant holding the container itself.
Definition at line 159 of file ContainerBuilder.h.
References canInjectContainer().