/
ThreeWayMergeOperation.h
72 lines (55 loc) · 2.17 KB
/
ThreeWayMergeOperation.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <map>
#include <list>
#include "imapmerge.h"
#include "ComparisonResult.h"
#include "MergeAction.h"
#include "MergeOperationBase.h"
namespace scene
{
namespace merge
{
/**
* A Three-Way Merge Operation uses a common ancestor (base)
* to define the actions needed to integrate the missing changes
* from the source map into the target map.
*/
class ThreeWayMergeOperation :
public MergeOperationBase
{
private:
IMapRootNodePtr _baseRoot; // a common ancestor of the two maps
IMapRootNodePtr _sourceRoot; // the map to be merged
IMapRootNodePtr _targetRoot; // the map where elements are going to be merged into
// Volatile data only needed during analysis
struct ComparisonData;
public:
using Ptr = std::shared_ptr<ThreeWayMergeOperation>;
ThreeWayMergeOperation(const IMapRootNodePtr& baseRoot,
const IMapRootNodePtr& sourceRoot, const IMapRootNodePtr& targetRoot);
virtual ~ThreeWayMergeOperation();
// Creates the merge operation from the given root nodes. The base root is the common ancestor of source and target,
// and none of the three must be equal to any of them.
static Ptr Create(const IMapRootNodePtr& baseRoot, const IMapRootNodePtr& sourceRoot, const IMapRootNodePtr& targetRoot);
void setMergeSelectionGroups(bool enabled) override;
void setMergeLayers(bool enabled) override;
const IMapRootNodePtr& getSourceRoot() const
{
return _sourceRoot;
}
const IMapRootNodePtr& getTargetRoot() const
{
return _targetRoot;
}
private:
void adjustSourceEntitiesWithNameConflicts();
void compareAndCreateActions();
void processEntityModification(const ComparisonResult::EntityDifference& sourceDiff,
const ComparisonResult::EntityDifference& targetDiff);
static bool KeyValueDiffHasConflicts(const ComparisonResult::KeyValueDifference& sourceKeyValueDiff,
const ComparisonResult::KeyValueDifference& targetKeyValueDiff);
static std::list<ComparisonResult::KeyValueDifference>::const_iterator FindTargetDiffByKey(
const std::list<ComparisonResult::KeyValueDifference>& targetKeyValueDiffs, const std::string& key);
};
}
}