Version: 9.12.0
SUIT_TreeSync.h File Reference
#include <QList>

Go to the source code of this file.

Classes

struct  DiffItem< SrcItem, TrgItem >
 The structure representing difference between source and destination items. More...
 

Functions

template<class SrcItem , class TrgItem , class TreeData >
TrgItem synchronize (const SrcItem &r1, const TrgItem &r2, const TreeData &td)
 Synchronize two data trees by recurive comparing of the corresponding items. More...
 
template<class SrcItem , class TrgItem , class TreeData >
QList< DiffItem< SrcItem, TrgItem > > diffSiblings (const SrcItem &src, const TrgItem &trg, const TreeData &td)
 Compare children of the source and target trees to find differences. More...
 
template<class SrcItem , class TrgItem , class TreeData >
TrgItem createSubTree (const SrcItem &src, const TrgItem &parent, const TrgItem &after, const TreeData &td)
 Create an item with all its children recursively in the target tree. More...
 
template<class SrcItem , class TrgItem , class TreeData >
const QList< TrgItem >::const_iterator findEqual (const SrcItem &it, const typename QList< TrgItem >::const_iterator &first, const typename QList< TrgItem >::const_iterator &last, const TreeData &td)
 Find the item in the target tree which correspond to the specified source tree item. More...
 

Function Documentation

◆ createSubTree()

template<class SrcItem , class TrgItem , class TreeData >
TrgItem createSubTree ( const SrcItem &  src,
const TrgItem &  parent,
const TrgItem &  after,
const TreeData &  td 
)

Create an item with all its children recursively in the target tree.

Parameters
srcsource tree item
parentparent item in the target tree
afteritem in the target tree after which new item shoud be inserted
tdfunctor class
Returns
created item
See also
synchronize()

◆ diffSiblings()

template<class SrcItem , class TrgItem , class TreeData >
QList< DiffItem< SrcItem, TrgItem > > diffSiblings ( const SrcItem &  src,
const TrgItem &  trg,
const TreeData &  td 
)

Compare children of the source and target trees to find differences.

Parameters
srcparent source item
trgparent target item
tdfunctor class
Returns
list of the differences
See also
synchronize()

References DiffItem< SrcItem, TrgItem >::mySrc, and DiffItem< SrcItem, TrgItem >::myTrg.

◆ findEqual()

template<class SrcItem , class TrgItem , class TreeData >
const QList< TrgItem >::const_iterator findEqual ( const SrcItem &  it,
const typename QList< TrgItem >::const_iterator &  first,
const typename QList< TrgItem >::const_iterator &  last,
const TreeData &  td 
)

Find the item in the target tree which correspond to the specified source tree item.

Parameters
itsource item for which correspondence is to be found
firstiterator pointing to the item in the list l from which search shoud be started
lastiterator pointing to the item in the list l the search to be finished at
tdfunctor class
Returns
iterator pointing to the item in the list \l if the correspondence is found or iterator last if the correspondence is not found
See also
synchronize()

◆ synchronize()

template<class SrcItem , class TrgItem , class TreeData >
TrgItem synchronize ( const SrcItem &  r1,
const TrgItem &  r2,
const TreeData &  td 
)

Synchronize two data trees by recurive comparing of the corresponding items.

Parameters
r1starting item from the source data tree
r2starting item from the target data tree
tdfunctor class
Returns
the target tree item (updated or just created) corresponding to the starting data object

Actual comparing of the items and the syncronization of the trees is performed by the functor class which is passed as the last parameter of the function. The functor class should implement the following methods:

  • bool isEqual( const SrcItem& src, const TrgItem& tgt ) const;
    • src source tree item
    • tgt target tree item
    • compares items and returns true if the items are equal (correspond to each other)
  • SrcItem nullSrc() const;
    • returns null source tree itemm
  • TrgItem nullTrg() const
    • returns null target tree item
  • TrgItem createItem( const SrcItem& src, const TrgItem& parent, const TrgItem& after ) const;
    • src source item
    • parent parent target item
    • after target tree item after which new item shoud be inserted (if null, the item is added to the end)
    • creates new ite in the target tree which correspond to the source item and returns created item
  • void updateItem( const SrcItem& src, const TrgItem& tgt ) const;
    • src source tree item
    • tgt the item in the target tree to be updated
    • updates target treeitem
  • void deleteItemWithChildren( const TrgItem& tgt ) const;
    • tgt the item in the target tree to be removed
    • deletes target tree item (recursively)
  • QList<SrcItem> children( const SrcItem& parent ) const;
    • parent the parent item in the source tree
    • returns the child items list
  • QList<TrgItem> children( const TrgItem& parent ) const;
    • parent the parent item in the target tree
    • returns the child items list
  • TrgItem parent( const TrgItem& tgt ) const;
    • tgt target tree item
    • returns the item which is parent for the specified source tree item

References createSubTree(), diffSiblings(), DiffItem< SrcItem, TrgItem >::mySrc, and DiffItem< SrcItem, TrgItem >::myTrg.