QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Member Functions | Protected Member Functions | List of all members
QtDataSync::GenericConflictResolver< T1, Args > Class Template Referenceabstract

A generic variant of the ConflictResolver to handel dataobjects instead of json data. More...

#include <conflictresolver.h>

Public Member Functions

 GenericConflictResolver (QObject *parent=nullptr)
 Default constructor.
 
QJsonObject resolveConflict (int typeId, const QJsonObject &data1, const QJsonObject &data2) const override
 The method called to resolve conflicts between two datasets. More...
 

Protected Member Functions

virtual T1 resolveConflict (T1 data1, T1 data2, QObject *parent) const =0
 

Detailed Description

template<typename T1, typename... Args>
class QtDataSync::GenericConflictResolver< T1, Args >

A generic variant of the ConflictResolver to handel dataobjects instead of json data.

Template Parameters
ArgsThe types this resolver should be able resolve conflicts for

The class is basically a wrapper around the ConflictResolver that deserializes all incoming data and that passes the objects to a generic resolveConflict() method. The result is then serialized again and returned. In order to handle a type it must be passed as a template parameter. The resulting generic class will have one pure virtual method for any passed type you need to reimplement. In order to handle types that have not been captured that way you can reimplement the resolveUnknownConflict() method.

See also
ConflictResolver, QJsonSerializer

Definition at line 50 of file conflictresolver.h.

Member Function Documentation

◆ resolveConflict() [1/2]

template<typename T1 , typename... Args>
QJsonObject QtDataSync::GenericConflictResolver< T1, Args >::resolveConflict ( int  typeId,
const QJsonObject data1,
const QJsonObject data2 
) const
inlineoverride

The method called to resolve conflicts between two datasets.

Parameters
typeIdThe id of the type of which the two conflicted objects are
data1The first dataset
data2The second dataset
Returns
The independent merge result of the two datasets
Exceptions
QExceptionIn case data corruption was detected an exception can be thrown to abort the synchronization. This will put the engine in an (unrecoverable) error state.

Must be implemented as the main method of the resolver. The method must always return something. If you find that you cannot decide how to merge, simply return a default constructed json object. In that case, the library will ignore the result and proceed to merge as if no conflict resolver was present.

Warning
This method must be deterministic and independent of the parameter order. This means if you assume you have 2 objects, no matter at what point in time and in which order they are passed to this method, the returned object must always be the same. If thats not the case it can lead to infinite synchronisation loops.
See also
ConflictResolver, GenericConflictResolver::resolveConflict

Definition at line 59 of file conflictresolver.h.

◆ resolveConflict() [2/2]

template<typename T1 , typename... Args>
virtual T1 QtDataSync::GenericConflictResolver< T1, Args >::resolveConflict ( T1  data1,
T1  data2,
QObject parent 
) const
protectedpure virtual

The method called to resolve conflicts between two datasets.

Parameters
data1The first dataset
data2The second dataset
parentA temporary qobject to use as parent for created QObjects
Returns
The independent merge result of the two datasets
Exceptions
NoConflictResultExceptionThrown if resolving was not possible and the default JSON-based resolving should be used instead
QExceptionIn case data corruption was detected an exception can be thrown to abort the synchronization. This will put the engine in an (unrecoverable) error state.

Must be implemented as the main method of the resolver. The method must always return something. If you find that you cannot decide how to merge, simply throw the NoConflictResultException. In that case, the library will ignore the result and proceed to merge as if no conflict resolver was present. It's basically this methods equivalent of returning an empty JSON object on the non generic variant of this method.

Warning
This method must be deterministic and independent of the parameter order. This means if you assume you have 2 objects, no matter at what point in time and in which order they are passed to this method, the returned object must always be the same. If thats not the case it can lead to infinite synchronisation loops.
See also
GenericConflictResolver::resolveUnknownConflict, ConflictResolver::resolveConflict

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