-
Notifications
You must be signed in to change notification settings - Fork 40
/
qsfastdiffrunner.h
43 lines (39 loc) · 1.17 KB
/
qsfastdiffrunner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <priv/qsdiffrunneralgo_p.h>
#include <qspatchable.h>
template <typename T>
class QSFastDiffRunner {
public:
QSFastDiffRunner() {
}
QSPatchSet compare(const QList<T>& from, const QList<T>& to) {
QSFastDiffRunnerAlgo<T> algo;
return algo.compare(from , to);
}
bool patch(QSPatchable *patchable, const QSPatchSet& patches) const
{
QVariantMap diff;
foreach (QSPatch patch, patches) {
switch (patch.type()) {
case QSPatch::Remove:
patchable->remove(patch.from(), patch.count());
break;
case QSPatch::Insert:
patchable->insert(patch.from(), patch.data());
break;
case QSPatch::Move:
patchable->move(patch.from(), patch.to(), patch.count());
break;
case QSPatch::Update:
if (patch.data().size() > 0) {
diff = patch.data().at(0).toMap();
}
patchable->set(patch.from(), diff);
break;
default:
break;
}
}
return true;
}
};