Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

template<class SrcItem , class TrgItem , class TreeData >
TrgItem createSubTree ( const SrcItem &  src,
const TrgItem &  parent,
const TrgItem &  after,
const TreeData &  td 
)
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()
template<class SrcItem , class TrgItem , class TreeData >
QList< DiffItem< SrcItem, TrgItem > > diffSiblings ( const SrcItem &  src,
const TrgItem &  trg,
const TreeData &  td 
)
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.

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 
)
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 if the correspondence is found or iterator last if the correspondence is not found
See Also
synchronize()
template<class SrcItem , class TrgItem , class TreeData >
TrgItem synchronize ( const SrcItem &  r1,
const TrgItem &  r2,
const TreeData &  td 
)
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.