Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Class modelling the result of a three way merge
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #ifndef MERGERESULT_HPP_
11 : #define MERGERESULT_HPP_
12 :
13 : #include <kdb.hpp>
14 : #include <merging/mergeconflict.hpp>
15 :
16 : namespace kdb
17 : {
18 :
19 : namespace tools
20 : {
21 :
22 : namespace merging
23 : {
24 :
25 42 : class MergeResult
26 : {
27 : public:
28 : MergeResult ();
29 : MergeResult (KeySet & conflictSet, KeySet & mergedKeys);
30 : ~MergeResult ()
31 1586 : {
32 : }
33 :
34 : void addConflict (Key & key, ConflictOperation ourOperation, ConflictOperation theirOperation);
35 :
36 : void resolveConflict (Key & key);
37 :
38 662 : bool isConflict (const Key & key)
39 : {
40 2648 : return conflictSet.lookup (key);
41 : }
42 :
43 : bool hasConflicts ()
44 : {
45 1948 : return conflictSet.size () != 0;
46 : }
47 :
48 819 : void addMergeKey (const Key & key)
49 : {
50 3276 : if (!mergedKeys.lookup (key))
51 : {
52 566 : mergedKeys.append (key);
53 : }
54 819 : }
55 :
56 392 : void removeMergeKey (const Key & key)
57 : {
58 1176 : mergedKeys.lookup (key, KDB_O_POP);
59 392 : }
60 :
61 : KeySet getConflictSet ()
62 : {
63 320 : return conflictSet;
64 : }
65 :
66 : KeySet getMergedKeys ()
67 : {
68 912 : return mergedKeys;
69 : }
70 :
71 : unsigned int getNumberOfResolvedKeys ()
72 : {
73 : return resolvedKeys;
74 : }
75 :
76 : unsigned int getNumberOfEqualKeys ()
77 : {
78 12 : return mergedKeys.size () - resolvedKeys;
79 : }
80 :
81 : private:
82 : KeySet conflictSet;
83 : KeySet mergedKeys;
84 : unsigned int resolvedKeys;
85 :
86 : void addConflictMeta (Key & key, std::string const & who, ConflictOperation operation);
87 : };
88 : } // namespace merging
89 : } // namespace tools
90 : } // namespace kdb
91 :
92 : #endif /* MERGERESULT_HPP_ */
|