-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathclist.h
77 lines (62 loc) · 3.87 KB
/
clist.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
/******************************************/
/* */
/* Alexander Agdgomlishvili */
/* */
/* cdevelopment@mail.com */
/* */
/******************************************/
#ifndef CLIST_H
#define CLIST_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct CList
{
void * (* add) (struct CList *l, void *o); /* Add object to the end of a list */
void * (* insert) (struct CList *l, void *o, int n); /* Insert object at position 'n' */
void * (* replace) (struct CList *l, void *o, int n); /* Replace object at position 'n' */
void (* remove) (struct CList *l, int n); /* Remove object at position 'n' */
void * (* at) (struct CList *l, int n); /* Get object at position 'n' */
int (* realloc) (struct CList *l, int n); /* Reallocate list to 'size' items */
int (* count) (struct CList *l); /* Get list size in items */
void * (* firstMatch) (struct CList *l, const void *o, size_t shift, size_t size, int string);
/* Returns object with first match of string or byte compare */
void * (* lastMatch) (struct CList *l, const void *o, size_t shift, size_t size, int string);
/* Returns object with last match of string or byte compare */
int (* index) (struct CList *l); /* Get index of previos search match */
int (* swap) (struct CList *l, int a, int b); /* Swap, replace two items with index a b */
int (* allocSize) (struct CList *l); /* Get allocated size in items */
size_t (* itemSize) (struct CList *l); /* Get item size in bytes */
void (* print) (struct CList *l, size_t shift, int n, const char *type); /* Print list data */
void (* clear) (struct CList *l); /* Clear list */
void (* free) (struct CList *l); /* Destroy struct CList and all data */
void *priv; /* NOT FOR USE, private data */
} CList;
CList *CList_init(size_t objSize); /* Set list object size in bytes */
/* void *add(struct CList *l, void *o);
Returns pointer to added object; Returns NULL if failed.
void *insert(struct CList *l, void *o, int n);
Returns pointer to inserted object; Returns NULL if failed.
void *replace(struct CList *l, void *o, int n);
Returns pointer to replaced object; Returns NULL if failed.
void *at(struct CList *l, int n);
Returns pointer to object at index n;
int realloc(struct CList *l, int n);
Return 1 when success. Returns 0 if failed.
void *firstMatch(struct CList *l, const void *o, size_t shift, size_t size, int string);
Returns pointer to list item when first match found. Straight scanning, from 0 to list end.
Returns NULL if search failed.
void *lastMatch(struct CList *l, const void *o, size_t shift, size_t size, int string);
Returns pointer to list item when first match found. Reverse scanning, from list end to 0.
Returns NULL if search failed.
int index(struct CList *l);
Returns index of last search firstMatch or lastMatch. Returns -1 if search failed.
void print(struct CList *l, size_t shift, int n, const char *type);
Prints data of "int n" list items with offset "size_t shift" and type "const char *type".
Supported types: char, short, int, long, uintptr_t, size_t, double, string.
If type is NULL just pointers data will be printed.
*/
#ifdef __cplusplus
}
#endif
#endif /* CLIST_H */