-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelCompare.c
133 lines (104 loc) · 3.3 KB
/
ModelCompare.c
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
/*
#include <microframework/api/compare/ModelCompare.h>
#include <microframework/api/utils/ModelVisitor.h>
#include <microframework/api/utils/Utils.h>
#include <microframework/api/compare/ModelCompareVisitors.h>
*/
#include "ModelCompare.h"
#include "TraceSequence.h"
#include "ContainerRoot.h"
#include "lib/list.h"
#include "hashmap.h"
/**
* Author: [email protected]
* Date: 21/12/14
* Time: 12:40
*/
ModelCompare *new_ModelCompare()
{
ModelCompare *pModCompObj = malloc(sizeof(ModelCompare));
if(pModCompObj == NULL)
{
return NULL;
}
pModCompObj->createSequence = TraceSequence_createSequence;
pModCompObj->diff = TraceSequence_diff;
pModCompObj->merge = TraceSequence_merge;
pModCompObj->inter = TraceSequence_inter;
pModCompObj->internal_diff = Trace_sequence_internal_diff;
return pModCompObj;
}
void delete_ModelCompare(void *const this)
{
if(this != NULL)
{
free(this);
}
}
TraceSequence *TraceSequence_createSequence(ModelCompare *const this)
{
TraceSequence *ts = new_TraceSequence();
return ts;
}
TraceSequence *TraceSequence_diff(ModelCompare *const this, ContainerRoot *origin, ContainerRoot *target)
{
TraceSequence *ts = new_TraceSequence();
ts->populate(this->internal_diff(origin, target, false, false));
return ts;
}
TraceSequence *TraceSequence_merge(ModelCompare *const this, ContainerRoot *origin, ContainerRoot *target)
{
TraceSequence *ts = new_TraceSequence();
ts->populate(this->internal_diff(origin, target, false, true));
return ts;
}
TraceSequence *TraceSequence_inter(ModelCompare *const this, ContainerRoot *origin, ContainerRoot *target)
{
TraceSequence *ts = new_TraceSequence();
ts->populate(this->internal_diff(origin, target, true, false));
return ts;
}
list_t Trace_sequence_internal_diff(ModelCompare *const this, ContainerRoot *origin, ContainerRoot *target, bool inter, bool merge)
{
list_t traces_list;
ModelTrace *mt;
return NULL;
}
std::list < ModelTrace * >* ModelCompare::internal_diff (KMFContainer *origin,KMFContainer *target,bool inter, bool merge)
{
list < ModelTrace * > *traces ;
list < ModelTrace * > *tracesRef;
std::map<string,KMFContainer*> values;
traces = origin->createTraces (target, inter, merge, false, true);
tracesRef = origin->createTraces (target, inter, merge, true, false);
// visitors
ModelCompareVisitorFiller *filler = new ModelCompareVisitorFiller(&values);
origin->visit(filler, true, true, false);
delete filler;
ModelCompareVisitorCreateTraces *visitorTraces= new ModelCompareVisitorCreateTraces(&values,inter,merge,traces,tracesRef);
target->visit(visitorTraces, true, true, false);
delete visitorTraces;
if(!inter){
//if diff
if(!merge)
{
for ( std::map<string,KMFContainer*>::const_iterator it = values.begin(); it != values.end(); ++it) {
KMFContainer *diffChild;
string src;
string refNameInParent="";
diffChild =it->second;
if( diffChild-> eContainer())
{
src = diffChild-> eContainer()->path();
}
refNameInParent = diffChild-> getRefInParent();
ModelRemoveTrace *modelremovetrace= new ModelRemoveTrace(src,refNameInParent,diffChild->path());
traces->push_back(modelremovetrace);
}
}
}
std::copy(tracesRef->begin(), tracesRef->end(), std::back_insert_iterator<std::list<ModelTrace*> >(*traces));
values.clear();
delete tracesRef;
return traces;
}