-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.h
90 lines (67 loc) · 2.08 KB
/
iterator.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
#ifndef ITERATOR_H
#define ITERATOR_H
#include "typdef.h"
struct _Iterator;
typedef struct _Iterator Iterator;
typedef Ret (*IteratorSetFunc)(Iterator* thiz, void* data);
typedef Ret (*IteratorGetFunc)(Iterator* thiz, void** data);
typedef Ret (*IteratorNextFunc)(Iterator* thiz);
typedef Ret (*IteratorPrevFunc)(Iterator* thiz);
typedef Ret (*IteratorAdvanceFunc)(Iterator* thiz, int offset);
typedef int (*IteratorOffsetFunc)(Iterator* thiz);
typedef Ret (*IteratorCloneFunc)(Iterator* thiz);
typedef void (*IteratorDestroyFunc)(Iterator* thiz);
struct _Iterator
{
IteratorSetFunc set;
IteratorGetFunc get;
IteratorNextFunc next;
IteratorPrevFunc prev;
IteratorAdvanceFunc advance;
IteratorCloneFunc clone;
IteratorOffsetFunc offset;
IteratorDestroyFunc destroy;
char priv[0];
}
static inline Ret iterator_set(Iterator* thiz, void* data)
{
return_val_if_fail(thiz != NULL && thiz->set != NULL, RET_INVALID_PARAMS);
return thiz->set(thiz, data);
}
static inline Ret iterator_get(Iterator* thiz, void** data)
{
return_val_if_fail(thiz != NULL && thiz->get != NULL, RET_INVALID_PARAMS);
return thiz->get(thiz, data);
}
static inline Ret iterator_next(Iterator* thiz)
{
return_val_if_fail(thiz != NULL && thiz->next != NULL, RET_INVALID_PARAMS);
return thiz->next(thiz);
}
static inline Ret iterator_prev(Iterator* thiz)
{
return_val_if_fail(thiz != NULL && thiz->prev != NULL, RET_INVALID_PARAMS);
return thiz->prev(thiz);
}
static inline Ret iterator_advance(Iterator* thiz)
{
return_val_if_fail(thiz != NULL && thiz->advance != NULL, RET_INVALID_PARAMS);
return thiz->advance(thiz, offset);
}
static inline int iterator_offset(Iterator* thiz)
{
return_val_if_fail(thiz != NULL && thiz->offset != NULL, RET_INVALID_PARAMS);
return thiz->offset(thiz);
}
static inline Ret iterator_clone(Iterator* thiz, Iterator** cloned)
{
return_val_if_fail(thiz != NULL && thiz->clone != NULL, RET_INVALID_PARAMS);
return thiz->clone(thiz, cloned);
}
static inline void iterator_destroy(Iterator* thiz)
{
return_if_fail(thiz != NULL && thiz->destroy != NULL);
thiz->destroy(thiz);
return;
}
#endif