-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequential.c
213 lines (182 loc) · 4.56 KB
/
sequential.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
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
#include "containers.h"
#include "ccl_internal.h"
struct SequentialContainer {
SequentialContainerInterface *vTable;
size_t Size;
unsigned Flags;
size_t ElementSize;
};
static size_t Size(const SequentialContainer *gen)
{
if (gen == NULL) {
iError.RaiseError("iGeneric.Size",CONTAINER_ERROR_BADARG);
return 0;
}
return gen->Size;
}
static unsigned GetFlags(const SequentialContainer *gen)
{
if (gen == NULL) {
iError.RaiseError("iGneric.GetFlags",CONTAINER_ERROR_BADARG);
return 0;
}
return gen->Flags;
}
static unsigned SetFlags(SequentialContainer *gen,unsigned newFlags)
{
unsigned result;
if (gen == NULL) {
iError.RaiseError("iGeneric.SetFlags",CONTAINER_ERROR_BADARG);
return 0;
}
result = gen->Flags;
gen->Flags = newFlags;
return result;
}
static int Clear(SequentialContainer *gen)
{
return gen->vTable->Clear(gen);
}
static int Contains(const SequentialContainer *gen,const void *value)
{
return gen->vTable->Contains(gen,value);
}
static int Erase(SequentialContainer *gen,const void *elem)
{
return gen->vTable->Erase(gen,elem);
}
static int EraseAll(SequentialContainer *gen,const void *elem)
{
return gen->vTable->EraseAll(gen,elem);
}
static int Finalize(SequentialContainer *gen)
{
return gen->vTable->Finalize(gen);
}
static void Apply(SequentialContainer *Gen,int (*Applyfn)(void *,void * arg),void *arg)
{
Gen->vTable->Apply(Gen,Applyfn,arg);
}
static int Equal(const SequentialContainer *Gen1,const SequentialContainer *Gen2)
{
return Gen1->vTable->Equal(Gen1,Gen2);
}
static SequentialContainer *Copy(const SequentialContainer *src)
{
return src->vTable->Copy(src);
}
static ErrorFunction SetErrorFunction(SequentialContainer *Gen,ErrorFunction fn)
{
return Gen->vTable->SetErrorFunction(Gen,fn);
}
static size_t Sizeof(const SequentialContainer *gen)
{
return gen->vTable->Sizeof(gen);
}
static Iterator *NewIterator(SequentialContainer *gen)
{
return gen->vTable->NewIterator(gen);
}
static int InitIterator(SequentialContainer *gen,void *buf)
{
return gen->vTable->InitIterator(gen,buf);
}
static int DeleteIterator(Iterator *git)
{
SequentialIterator *GenIt = (SequentialIterator *)git;
SequentialContainer *gen = GenIt->Gen;
return gen->vTable->DeleteIterator(git);
}
static size_t SizeofIterator(const SequentialContainer *git)
{
SequentialIterator *GenIt = (SequentialIterator *)git;
SequentialContainer *gen = GenIt->Gen;
return gen->vTable->SizeofIterator(git);
}
static int Save(const SequentialContainer *gen, FILE *stream,SaveFunction saveFn,void *arg)
{
return gen->vTable->Save(gen,stream,saveFn,arg);
}
/*-----------------------------------------------------------------------------------*/
/* */
/* Sequential containers */
/* */
/*-----------------------------------------------------------------------------------*/
static int Add(SequentialContainer *sc, const void *Element)
{
return sc->vTable->Add(sc,Element);
}
static void *GetElement(const SequentialContainer *sc,size_t idx)
{
return sc->vTable->GetElement(sc,idx);
}
static int Push(SequentialContainer *gen,void *Element)
{
return gen->vTable->Push(gen,Element);
}
static int Pop(SequentialContainer *g,void *Element)
{
return g->vTable->Pop(g,Element);
}
static int InsertAt(SequentialContainer *gen,size_t idx,const void *newval)
{
return gen->vTable->InsertAt(gen,idx,newval);
}
static int EraseAt(SequentialContainer *g,size_t idx)
{
return g->vTable->EraseAt(g,idx);
}
static int ReplaceAt(SequentialContainer *s,size_t idx,const void *newelem)
{
return s->vTable->ReplaceAt(s,idx,newelem);
}
static int IndexOf(const SequentialContainer *g,const void *elemToFind,
void *args,size_t *result)
{
return g->vTable->IndexOf(g,elemToFind,args,result);
}
static int Append(SequentialContainer *g1,SequentialContainer *g2)
{
int r;
void *element;
Iterator *it1 = NewIterator((SequentialContainer *)
g2);
for (element = it1->GetFirst(it1);
element != NULL;
element = it1->GetNext(it1)) {
r = Add(g1,element);
if (r <=0) {
return r;
}
}
return 1;
}
SequentialContainerInterface iSequentialContainer = {
Size,
GetFlags,
SetFlags,
Clear,
Contains,
Erase,
EraseAll,
Finalize,
Apply,
Equal,
Copy,
SetErrorFunction,
Sizeof,
NewIterator,
InitIterator,
DeleteIterator,
SizeofIterator,
Save,
Add,
GetElement,
Push,
Pop,
InsertAt,
EraseAt,
ReplaceAt,
IndexOf,
Append,
};