Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Implements a way to build and deal with a backend
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #ifndef THREEWAYMERGE_HPP_
11 : #define THREEWAYMERGE_HPP_
12 :
13 : #include <kdb.hpp>
14 : #include <memory>
15 : #include <merging/mergeconflictstrategy.hpp>
16 : #include <merging/mergeresult.hpp>
17 : #include <merging/mergetask.hpp>
18 : #include <string>
19 : #include <vector>
20 :
21 : namespace kdb
22 : {
23 :
24 : namespace tools
25 : {
26 :
27 : namespace merging
28 : {
29 :
30 432 : class ThreeWayMerge
31 : {
32 :
33 : public:
34 : /**
35 : * Performs a threeway merge according to the supplied MergeTask. All merged keys will
36 : * be below the given mergeParent in the MergeTask. Found conflicts will be
37 : * reported in the MergeResult. Conflicts are below the mergeParent as well and
38 : * are not part of the mergedKeys.
39 : *
40 : * @see MergeTask
41 : * @see MergeResult
42 : *
43 : * @param task a MergeTask describing the intended merge oparation
44 : * @return a MergeResult that contains the merged keys as well as all found conflicts.
45 : *
46 : **/
47 : MergeResult mergeKeySet (const KeySet & base, const KeySet & ours, const KeySet & theirs, const Key & mergeRoot);
48 :
49 : /**
50 : * Performs a threeway merge based on the supplied KeySets. The result is the same
51 : * as for ThreeWayMerge::mergeKeySet(const MergeTask&). The first key (i.e. the shortest)
52 : * in each of the supplied KeySets is considered to be the corresponding parentKey.
53 : * This means that the parent key of each KeySet MUST be part of the KeySet.
54 : *
55 : * @see ThreeWayMerge::mergeKeySet(const MergeTask&)
56 : * @return a MergeResult that contains the merged keys as well as all found conflicts.
57 : */
58 : MergeResult mergeKeySet (const MergeTask & task);
59 :
60 : /**
61 : * Adds a conflict resolution strategy to the merger. The merger tries to resolve conflicts
62 : * with the strategies registered in the order they were added. The caller is responsible for
63 : * freeing the strategy, but it must not be freed as long as the merger is used.
64 : *
65 : * @param a conflict reoslution strategy to be consulted in case of conflicts
66 : */
67 : void addConflictStrategy (MergeConflictStrategy * strategy)
68 : {
69 166 : strategies.push_back (strategy);
70 : }
71 :
72 : private:
73 : std::vector<MergeConflictStrategy *> strategies;
74 : void detectConflicts (const MergeTask & task, MergeResult & mergeResult, bool reverseConflictMeta);
75 : };
76 : } // namespace merging
77 : } // namespace tools
78 : } // namespace kdb
79 :
80 : #endif /* THREEWAYMERGE_HPP_ */
|