26 #ifndef SUIT_TREESYNC_H
27 #define SUIT_TREESYNC_H
41 template <
class SrcItem,
class TrgItem>
53 template <
class SrcItem,
class TrgItem,
class TreeData>
54 TrgItem
synchronize(
const SrcItem&,
const TrgItem&,
const TreeData& );
56 template <
class SrcItem,
class TrgItem,
class TreeData>
61 template <
class SrcItem,
class TrgItem,
class TreeData>
62 TrgItem
createSubTree(
const SrcItem&,
const TrgItem&,
const TrgItem&,
const TreeData& );
64 template <
class SrcItem,
class TrgItem,
class TreeData>
117 template <
class SrcItem,
class TrgItem,
class TreeData>
118 TrgItem
synchronize(
const SrcItem& r1,
const TrgItem& r2,
const TreeData& td )
120 if ( td.isEqual( r1, r2 ) ) {
122 td.updateItem( r1, r2 );
128 TrgItem lastItem = td.nullTrg();
130 for ( ; anIt != aLast; anIt++ ) {
132 if ( item.
mySrc == td.nullSrc() ) {
133 if ( item.
myTrg == td.nullTrg() )
136 qDebug(
"error: both null" );
141 td.deleteItemWithChildren( item.
myTrg );
144 if ( item.
myTrg == td.nullTrg() ) {
147 if ( nitem != td.nullTrg() )
153 lastItem = item.
myTrg;
160 TrgItem new_r2 = td.nullTrg();
161 if ( r1 != td.nullSrc() ) {
165 if ( r2 != td.nullTrg() ) {
167 td.deleteItemWithChildren( r2 );
183 template <
class SrcItem,
class TrgItem,
class TreeData>
190 for ( ; cur != last; cur++ ) {
191 if ( td.isEqual( it, *cur ) )
205 template <
class SrcItem,
class TrgItem,
class TreeData>
220 for ( ; src_it != src_last; src_it++ ) {
222 findEqual<SrcItem, TrgItem, TreeData>( *src_it, cur, trg_last, td );
223 if ( f != trg_last ) {
228 ndiff.
mySrc = td.nullSrc();
234 ndiff.
mySrc = *src_it;
242 ndiff.
mySrc = *src_it;
243 ndiff.
myTrg = td.nullTrg();
248 for ( ; cur != trg_last; cur++ ) {
250 ndiff.
mySrc = td.nullSrc();
267 template <
class SrcItem,
class TrgItem,
class TreeData>
269 const TrgItem& after,
const TreeData& td )
271 if ( src == td.nullSrc() )
274 TrgItem nitem = td.createItem( src, parent, after );
275 if ( nitem == td.nullTrg() )
280 TrgItem last = td.nullTrg();
281 for( ; anIt != aLast; anIt++ )
TrgItem synchronize(const SrcItem &, const TrgItem &, const TreeData &)
Synchronize two data trees by recurive comparing of the corresponding items.
Definition: SUIT_TreeSync.h:118
QList< DiffItem< SrcItem, TrgItem > > diffSiblings(const SrcItem &, const TrgItem &, const TreeData &)
Compare children of the source and target trees to find differences.
Definition: SUIT_TreeSync.h:206
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.
Definition: SUIT_TreeSync.h:184
TrgItem createSubTree(const SrcItem &, const TrgItem &, const TrgItem &, const TreeData &)
Create an item with all its children recursively in the target tree.
Definition: SUIT_TreeSync.h:268
The structure representing difference between source and destination items.
Definition: SUIT_TreeSync.h:43
SrcItem mySrc
source tree item
Definition: SUIT_TreeSync.h:44
TrgItem myTrg
target tree item
Definition: SUIT_TreeSync.h:45