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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* Copyright (c) 2012 Mateusz Piękos
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Whiteboard/WhiteboardTransformer.h>
#include <boost/smart_ptr/make_shared.hpp>
namespace Swift {
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardOperation::ref clientOp, WhiteboardOperation::ref serverOp) {
WhiteboardInsertOperation::ref clientInsert = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(clientOp);
WhiteboardInsertOperation::ref serverInsert = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(serverOp);
WhiteboardUpdateOperation::ref clientUpdate = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(clientOp);
WhiteboardUpdateOperation::ref serverUpdate = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(serverOp);
WhiteboardDeleteOperation::ref clientDelete = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(clientOp);
WhiteboardDeleteOperation::ref serverDelete = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(serverOp);
if (clientInsert && serverInsert) {
return transform(clientInsert, serverInsert);
} else if (clientUpdate && serverUpdate) {
return transform(clientUpdate, serverUpdate);
} else if (clientInsert && serverUpdate) {
return transform(clientInsert, serverUpdate);
} else if (clientUpdate && serverInsert) {
return transform(clientUpdate, serverInsert);
} else if (clientDelete && serverDelete) {
return transform(clientDelete, serverDelete);
} else if (clientInsert && serverDelete) {
return transform(clientInsert, serverDelete);
} else if (clientDelete && serverInsert) {
return transform(clientDelete, serverInsert);
} else if (clientUpdate && serverDelete) {
return transform(clientUpdate, serverDelete);
} else if (clientDelete && serverUpdate) {
return transform(clientDelete, serverUpdate);
} else {
return std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref>();
}
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardInsertOperation::ref clientOp, WhiteboardInsertOperation::ref serverOp) {
std::pair<WhiteboardInsertOperation::ref, WhiteboardInsertOperation::ref> result;
result.first = boost::make_shared<WhiteboardInsertOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.first->setPos(result.first->getPos()+1);
result.second = boost::make_shared<WhiteboardInsertOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardUpdateOperation::ref clientOp, WhiteboardUpdateOperation::ref serverOp) {
std::pair<WhiteboardUpdateOperation::ref, WhiteboardUpdateOperation::ref> result;
result.first = boost::make_shared<WhiteboardUpdateOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
if (clientOp->getPos() == serverOp->getPos()) {
result.second = boost::make_shared<WhiteboardUpdateOperation>(*serverOp.get());
result.second->setID(clientOp->getID());
result.second->setParentID(serverOp->getID());
} else {
result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
}
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardUpdateOperation::ref clientOp, WhiteboardInsertOperation::ref serverOp) {
std::pair<WhiteboardInsertOperation::ref, WhiteboardUpdateOperation::ref> result;
result.first = boost::make_shared<WhiteboardInsertOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (serverOp->getPos() <= clientOp->getPos()) {
result.second->setPos(result.second->getPos()+1);
}
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardInsertOperation::ref clientOp, WhiteboardUpdateOperation::ref serverOp) {
std::pair<WhiteboardUpdateOperation::ref, WhiteboardInsertOperation::ref> result;
result.first = boost::make_shared<WhiteboardUpdateOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardInsertOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (serverOp->getPos() >= clientOp->getPos()) {
result.first->setPos(result.first->getPos()+1);
}
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardDeleteOperation::ref clientOp, WhiteboardDeleteOperation::ref serverOp) {
std::pair<WhiteboardDeleteOperation::ref, WhiteboardDeleteOperation::ref> result;
result.first = boost::make_shared<WhiteboardDeleteOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardDeleteOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (clientOp->getPos() < serverOp->getPos()) {
result.first->setPos(result.first->getPos()-1);
} else if (clientOp->getPos() < serverOp->getPos()) {
result.second->setPos(result.second->getPos()-1);
}
//TODO: situation with deletion of the same item
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardInsertOperation::ref clientOp, WhiteboardDeleteOperation::ref serverOp) {
std::pair<WhiteboardDeleteOperation::ref, WhiteboardInsertOperation::ref> result;
result.first = boost::make_shared<WhiteboardDeleteOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardInsertOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (clientOp->getPos() <= serverOp->getPos()) {
result.first->setPos(result.first->getPos()+1);
} else {
result.second->setPos(result.second->getPos()-1);
}
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardDeleteOperation::ref clientOp, WhiteboardInsertOperation::ref serverOp) {
std::pair<WhiteboardInsertOperation::ref, WhiteboardDeleteOperation::ref> result;
result.first = boost::make_shared<WhiteboardInsertOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardDeleteOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (serverOp->getPos() <= clientOp->getPos()) {
result.second->setPos(result.second->getPos()+1);
} else {
result.first->setPos(result.first->getPos()-1);
}
return result;
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardUpdateOperation::ref clientOp, WhiteboardDeleteOperation::ref serverOp) {
std::pair<WhiteboardDeleteOperation::ref, WhiteboardUpdateOperation::ref> result;
result.first = boost::make_shared<WhiteboardDeleteOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (clientOp->getPos() > serverOp->getPos()) {
result.second->setPos(result.second->getPos()-1);
}
return result;
//TODO: situation with the same pos
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardDeleteOperation::ref clientOp, WhiteboardUpdateOperation::ref serverOp) {
std::pair<WhiteboardUpdateOperation::ref, WhiteboardDeleteOperation::ref> result;
result.first = boost::make_shared<WhiteboardUpdateOperation>(*serverOp.get());
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardDeleteOperation>(*clientOp.get());
result.second->setParentID(serverOp->getID());
if (clientOp->getPos() < serverOp->getPos()) {
result.first->setPos(result.first->getPos()-1);
}
return result;
//TODO: situation with the same pos
}
}
|