-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoc_ref.h
234 lines (198 loc) · 5.57 KB
/
doc_ref.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* @file doc_ref.h
*/
/*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either vers* ion 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef DOC_REF_H
#define DOC_REF_H
#include <stdlib.h>
#include "gl_list.h"
#include "doc_stream.h"
struct doc_elt;
typedef struct doc_elt doc_elt;
typedef struct merge_ctxt merge_ctxt;
typedef struct doc_ref doc_ref;
/**
* Indicates an input document (ancestor, local, or source). Used to
* indicate the document from which a doc_* object originates.
*/
typedef enum doc_src
{
ANC_SRC = 1,
REM_SRC = 2,
LOC_SRC = 4
} doc_src;
/**
* A reference to a doc_elt. It is used to keep track of what files a
* merged document represents.
*/
typedef struct doc_ref
{
doc_src src;
doc_elt *elt;
doc_ref *parent;
bool circular_conflict;
} doc_ref;
/* Constructor and destructor */
static inline doc_ref *doc_ref_create_empty ();
static inline void doc_ref_free (doc_ref *ref);
/* Set the doc_elt reference */
static inline doc_elt * doc_ref_get_elt (doc_ref *ref);
static inline void doc_ref_set_elt (doc_ref *ref, doc_elt *elt);
/* Set the doc_src this file represents */
static inline doc_src doc_ref_get_src (doc_ref *ref);
static inline void doc_ref_set_src (doc_ref *ref, doc_src src);
static inline void doc_ref_add_src (doc_ref *ref, doc_src src);
static inline bool doc_ref_isexactly (doc_ref *ref, doc_src src);
static inline bool doc_ref_contains (doc_ref *ref, doc_src src);
static inline doc_ref *doc_ref_get_parent (doc_ref *ref);
static inline void doc_ref_set_parent (doc_ref *ref, doc_ref* parent);
void doc_reflist_note_insert (gl_list_t reflist, merge_ctxt *ctxt);
void doc_reflist_note_delete (gl_list_t reflist, merge_ctxt *ctxt);
/* circular conflict */
static inline bool doc_ref_is_circular_conflict (doc_ref *ref);
static inline void doc_ref_set_circular_conflict (doc_ref *ref, bool conflict);
/* check for a circulor conflic, and mark it in all doc_refs */
static inline bool dec_ref_check_for_circular_conflict (doc_ref *ref);
/*
* doc_reflist
*/
/**
* @brief Check to see if any of the elemets in a list of doc_refs are
* updated.
* This depends on the element's implementation of this.
* This function will stop early if it finds a response.
*/
bool doc_reflist_isupdated (gl_list_t reflist);
/**
* @brief Merge two doc_ref lists together. This function changes ancestor.
*/
void doc_reflist_merge (doc_ref *parent, gl_list_t ancestor, gl_list_t descendant, merge_ctxt *ctxt);
/**
* @brief print a list of ref_docs
*/
void doc_reflist_print (gl_list_t reflist, void *context, doc_stream *out);
/*
* Implementation Details
*/
static inline doc_ref *
doc_ref_create_empty ()
{
doc_ref *d = malloc (sizeof (doc_ref));
d->elt = NULL;
d->src = 0;
d->parent = NULL;
d->circular_conflict = false;
return d;
}
static inline void
doc_ref_free (doc_ref *ref)
{
free (ref);
}
static inline doc_elt *
doc_ref_get_elt (doc_ref *ref)
{
return ref->elt;
}
static inline void
doc_ref_set_elt (doc_ref *ref, doc_elt *elt)
{
ref->elt = elt;
return;
}
static inline doc_src
doc_ref_get_src (doc_ref *ref)
{
return ref->src;
}
static inline void
doc_ref_set_src (doc_ref *ref, doc_src src)
{
ref->src = src;
return;
}
static inline void
doc_ref_add_src (doc_ref *ref, doc_src src)
{
ref->src = ref->src | src;
return;
}
static inline bool
doc_ref_isexactly (doc_ref *ref, doc_src src)
{
return (ref->src == src);
}
static inline bool
doc_ref_contains (doc_ref *ref, doc_src src)
{
return (ref->src & src);
}
static inline doc_ref *doc_ref_get_parent (doc_ref *ref)
{
return ref->parent;
}
static inline void doc_ref_set_parent (doc_ref *ref, doc_ref* parent)
{
ref->parent = parent;
return;
}
static inline bool doc_ref_is_circular_conflict (doc_ref *ref)
{
return ref->circular_conflict;
}
static inline void doc_ref_set_circular_conflict (doc_ref *ref, bool conflict)
{
ref->circular_conflict = conflict;
}
/* check for a circulor conflict, and mark it in all doc_refs */
static inline bool doc_ref_check_for_circular_conflict (doc_ref *ref)
{
bool exit = false;
bool conflict = false;
doc_ref *parent = doc_ref_get_parent (ref);
while ((parent != NULL)
&& (!conflict)
&& !(doc_ref_is_circular_conflict(parent)))
{
printf ("checking parent par=%d, ref=%d\n",
doc_ref_get_elt (parent), doc_ref_get_elt (ref));
if (doc_ref_get_elt (parent) == doc_ref_get_elt (ref))
{
printf ("CIRCULAR CONFLICT\n");
conflict = true;
}
parent = doc_ref_get_parent ( parent );
}
/* set the doc_refs as having a conflict, if there was one */
exit = false;
if (conflict)
{
doc_ref * parent = doc_ref_get_parent (ref);
while ( (parent != NULL) && (!exit))
{
if (doc_ref_get_elt (parent) == doc_ref_get_elt (ref))
{
exit = true;
}
doc_ref_set_circular_conflict (parent, true);
parent = doc_ref_get_parent (parent);
}
}
printf ("conflict = %d\n", conflict);
return conflict;
}
#endif /* DOC_REF_H */