1 /*
2 * Copyright (C) 1997-2004, Michael Jennings
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies of the Software, its documentation and marketing & publicity
13 * materials, and acknowledgment shall be given in the documentation, materials
14 * and software packages that this Software was used.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef _LIBAST_LIST_IF_H_
25 #define _LIBAST_LIST_IF_H_
26
27 /*
28 * interface goop
29 */
30
31 /* Standard typecast macros.... */
32 #define SPIF_LIST(o) (SPIF_CAST(list) (o))
33 #define SPIF_LIST_CLASS(o) (SPIF_CAST(listclass) SPIF_OBJ_CLASS(o))
34
35 /* Name of class variable associated with list interface */
36 #define SPIF_LISTCLASS_VAR(type) spif_ ## type ## _listclass
37
38 /* Check if a list is NULL */
39 #define SPIF_LIST_ISNULL(o) (SPIF_LIST(o) == SPIF_NULL_TYPE(list))
40
41 /* Check if an object is a list */
42 #define SPIF_OBJ_IS_LIST(o) SPIF_OBJ_IS_TYPE(o, list)
43
44 /* Call a method on an instance of an implementation class */
45 #define SPIF_LIST_CALL_METHOD(o, meth) SPIF_LIST_CLASS(o)->meth
46
47 /* Calls to the basic functions. */
48 #define SPIF_LIST_NEW(type) SPIF_LIST((SPIF_CLASS(SPIF_LISTCLASS_VAR(type)))->noo())
49 #define SPIF_LIST_INIT(o) SPIF_OBJ_INIT(o)
50 #define SPIF_LIST_DONE(o) SPIF_OBJ_DONE(o)
51 #define SPIF_LIST_DEL(o) SPIF_OBJ_DEL(o)
52 #define SPIF_LIST_SHOW(o, b, i) SPIF_OBJ_SHOW(o, b, i)
53 #define SPIF_LIST_COMP(o1, o2) SPIF_OBJ_COMP(o1, o2)
54 #define SPIF_LIST_DUP(o) SPIF_OBJ_DUP(o)
55 #define SPIF_LIST_TYPE(o) SPIF_OBJ_TYPE(o)
56
57 #define SPIF_LIST_APPEND(o, item) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), append))(o, item))
58 #define SPIF_LIST_CONTAINS(o, item) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), contains))(o, item))
59 #define SPIF_LIST_COUNT(o) SPIF_CAST_C(size_t) ((SPIF_LIST_CALL_METHOD((o), count))(o))
60 #define SPIF_LIST_FIND(o, item) SPIF_CAST(obj) ((SPIF_LIST_CALL_METHOD((o), find))(o, item))
61 #define SPIF_LIST_GET(o, index) SPIF_CAST(obj) ((SPIF_LIST_CALL_METHOD((o), get))(o, index))
62 #define SPIF_LIST_INDEX(o, item) SPIF_CAST_C(size_t) ((SPIF_LIST_CALL_METHOD((o), index))(o, item))
63 #define SPIF_LIST_INSERT(o, item) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), insert))(o, item))
64 #define SPIF_LIST_INSERT_AT(o, item, index) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), insert_at))(o, item, index))
65 #define SPIF_LIST_ITERATOR(o) SPIF_CAST(iterator) ((SPIF_LIST_CALL_METHOD((o), iterator))(o))
66 #define SPIF_LIST_PREPEND(o, item) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), prepend))(o, item))
67 #define SPIF_LIST_REMOVE(o, item) SPIF_CAST(obj) ((SPIF_LIST_CALL_METHOD((o), remove))(o, item))
68 #define SPIF_LIST_REMOVE_AT(o, index) SPIF_CAST(obj) ((SPIF_LIST_CALL_METHOD((o), remove_at))(o, index))
69 #define SPIF_LIST_REVERSE(o) SPIF_CAST(bool) ((SPIF_LIST_CALL_METHOD((o), reverse))(o))
70 #define SPIF_LIST_TO_ARRAY(o) SPIF_CAST_PTR(obj) ((SPIF_LIST_CALL_METHOD((o), to_array))(o))
71
72 typedef spif_obj_t spif_list_t;
73 typedef spif_int32_t spif_listidx_t;
74
SPIF_DECL_OBJ(listclass)75 SPIF_DECL_OBJ(listclass) {
76 SPIF_DECL_PARENT_TYPE(class);
77
78 spif_func_t append;
79 spif_func_t contains;
80 spif_func_t count;
81 spif_func_t find;
82 spif_func_t get;
83 spif_func_t index;
84 spif_func_t insert;
85 spif_func_t insert_at;
86 spif_func_t iterator;
87 spif_func_t prepend;
88 spif_func_t remove;
89 spif_func_t remove_at;
90 spif_func_t reverse;
91 spif_func_t to_array;
92 };
93
94 #endif /* _LIBAST_LIST_IF_H_ */
95