/
imapmerge.h
116 lines (89 loc) · 3.08 KB
/
imapmerge.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include <memory>
#include <functional>
#include "inode.h"
namespace scene
{
namespace merge
{
enum class ActionType
{
NoAction,
AddEntity,
RemoveEntity,
AddKeyValue,
RemoveKeyValue,
ChangeKeyValue,
AddChildNode,
RemoveChildNode,
};
/**
* Represents a merge action, i.e. one single step of a merge operation.
* Only active actions will be processed when the merge run starts.
*/
class IMergeAction
{
public:
virtual ~IMergeAction() {}
using Ptr = std::shared_ptr<IMergeAction>;
// The type performed by this action
virtual ActionType getType() const = 0;
// Activate this action, it will be executed during the merge
virtual void activate() = 0;
// Deactivate this action, it will NOT be executed during the merge
virtual void deactivate() = 0;
// Returns the active state of this action
virtual bool isActive() const = 0;
// Applies all changes defined by this action (if it is active,
// deactivated action will not take any effect).
// It's the caller's responsibility to set up any Undo operations.
// Implementations are allowed to throw std::runtime_errors on failure.
virtual void applyChanges() = 0;
// Returns the node this action is affecting when applied
// This is used to identify the scene node and display it appropriately
virtual scene::INodePtr getAffectedNode() = 0;
};
class IEntityKeyValueMergeAction :
public virtual IMergeAction
{
public:
virtual ~IEntityKeyValueMergeAction() {}
using Ptr = std::shared_ptr<IEntityKeyValueMergeAction>;
// Gets the key name affected by this action
virtual const std::string& getKey() const = 0;
// Gets the value that is going to be set by this action
virtual const std::string& getValue() const = 0;
};
// A MergeOperation groups one or more merge actions
// together in order to apply a set of changes from source => base
class IMergeOperation
{
public:
using Ptr = std::shared_ptr<IMergeOperation>;
virtual ~IMergeOperation() {}
// Executes all active actions defined in this operation
virtual void applyActions() = 0;
// Invokes the given functor for each action in this operation
virtual void foreachAction(const std::function<void(const IMergeAction::Ptr&)>& visitor) = 0;
};
}
/**
* Special scene node type representing a change conducted by a merge action,
* i.e. addition, removal or changing a node in the scene.
*/
class IMergeActionNode :
public virtual scene::INode
{
public:
virtual ~IMergeActionNode() {}
// Return the action type represented by this node
virtual merge::ActionType getActionType() const = 0;
// Return the node this action is affecting
virtual scene::INodePtr getAffectedNode() = 0;
// The number of merge actions associated to this node.
// This can be 0 if the node has been cleared out after completing a merge operation
virtual std::size_t getMergeActionCount() = 0;
// Iterate over all actions of this node
virtual void foreachMergeAction(const std::function<void(const merge::IMergeAction::Ptr&)>& functor) = 0;
};
}