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_VECTOR_IF_H_
25 #define _LIBAST_VECTOR_IF_H_
26 
27 /*
28  * interface goop
29  */
30 
31 /* Standard typecast macros.... */
32 #define SPIF_VECTOR(o)                                    (SPIF_CAST(vector) (o))
33 #define SPIF_VECTOR_CLASS(o)                              (SPIF_CAST(vectorclass) SPIF_OBJ_CLASS(o))
34 
35 /* Name of class variable associated with vector interface */
36 #define SPIF_VECTORCLASS_VAR(type)                        spif_ ## type ## _vectorclass
37 
38 /* Check if a vector is NULL */
39 #define SPIF_VECTOR_ISNULL(o)                             (SPIF_VECTOR(o) == SPIF_NULL_TYPE(vector))
40 
41 /* Check if an object is a vector */
42 #define SPIF_OBJ_IS_VECTOR(o)                             SPIF_OBJ_IS_TYPE(o, vector)
43 
44 /* Call a method on an instance of an implementation class */
45 #define SPIF_VECTOR_CALL_METHOD(o, meth)                  SPIF_VECTOR_CLASS(o)->meth
46 
47 /* Calls to the basic functions. */
48 #define SPIF_VECTOR_NEW(type)                             SPIF_VECTOR((SPIF_CLASS(SPIF_VECTORCLASS_VAR(type)))->noo())
49 #define SPIF_VECTOR_INIT(o)                               SPIF_OBJ_INIT(o)
50 #define SPIF_VECTOR_DONE(o)                               SPIF_OBJ_DONE(o)
51 #define SPIF_VECTOR_DEL(o)                                SPIF_OBJ_DEL(o)
52 #define SPIF_VECTOR_SHOW(o, b, i)                         SPIF_OBJ_SHOW(o, b, i)
53 #define SPIF_VECTOR_COMP(o1, o2)                          SPIF_OBJ_COMP(o1, o2)
54 #define SPIF_VECTOR_DUP(o)                                SPIF_OBJ_DUP(o)
55 #define SPIF_VECTOR_TYPE(o)                               SPIF_OBJ_TYPE(o)
56 
57 #define SPIF_VECTOR_CONTAINS(o, item)                     SPIF_CAST(bool) ((SPIF_VECTOR_CALL_METHOD((o), contains))(o, item))
58 #define SPIF_VECTOR_COUNT(o)                              SPIF_CAST_C(size_t) ((SPIF_VECTOR_CALL_METHOD((o), count))(o))
59 #define SPIF_VECTOR_FIND(o, item)                         SPIF_CAST(obj) ((SPIF_VECTOR_CALL_METHOD((o), find))(o, item))
60 #define SPIF_VECTOR_INSERT(o, item)                       SPIF_CAST(bool) ((SPIF_VECTOR_CALL_METHOD((o), insert))(o, item))
61 #define SPIF_VECTOR_ITERATOR(o)                           SPIF_CAST(iterator) ((SPIF_VECTOR_CALL_METHOD((o), iterator))(o))
62 #define SPIF_VECTOR_REMOVE(o, item)                       SPIF_CAST(obj) ((SPIF_VECTOR_CALL_METHOD((o), remove))(o, item))
63 #define SPIF_VECTOR_TO_ARRAY(o)                           SPIF_CAST_PTR(obj) ((SPIF_VECTOR_CALL_METHOD((o), to_array))(o))
64 
65 typedef spif_obj_t spif_vector_t;
66 
SPIF_DECL_OBJ(vectorclass)67 SPIF_DECL_OBJ(vectorclass) {
68     SPIF_DECL_PARENT_TYPE(class);
69 
70     spif_func_t contains;
71     spif_func_t count;
72     spif_func_t find;
73     spif_func_t insert;
74     spif_func_t iterator;
75     spif_func_t remove;
76     spif_func_t to_array;
77 };
78 
79 #endif /* _LIBAST_VECTOR_IF_H_ */
80