always pass vectors by reference
[cvector.git] / vec_decl.h
blobc39deee877c19a6d22606b5386c2536a1d9f6b53
1 #ifndef VEC_DECL_H_
2 #define VEC_DECL_H_
4 #include <stddef.h>
5 #include <stdbool.h>
8 #define DEFINE_VECTOR_TYPE(_typename_, _ctype_) \
9 typedef struct _typename_ { \
10 size_t size; \
11 size_t capacity; \
12 _ctype_* data; \
13 } _typename_;
15 #define DEFINE_VECTOR_ELEM_EQV_FUNCTION_SIGNATURE(_typename_, _ctype_) \
16 typedef bool (*_typename_##_eqv_func)(_ctype_, _ctype_);
18 #define VECTOR_CREATE_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
19 _typename_ _typename_##_create(const size_t size)
21 #define VECTOR_FREE_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
22 void _typename_##_free(_typename_* const vec)
24 #define VECTOR_GETV_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
25 _ctype_ _typename_##_getv(const _typename_* const vec, const size_t index)
27 #define VECTOR_GETP_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
28 _ctype_* _typename_##_getp(const _typename_* const vec, const size_t index)
30 #define VECTOR_SET_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
31 void _typename_##_set(const _typename_* const vec, const size_t index, _ctype_ const val)
33 #define VECTOR_PUSH_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
34 void _typename_##_push(_typename_* const vec, _ctype_ const val)
36 #define VECTOR_PRINT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
37 void _typename_##_print(const _typename_* const vec, char const* const element_format, char const* const separator)
39 #define VECTOR_FRONT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
40 _ctype_ _typename_##_front(const _typename_* const vec)
42 #define VECTOR_BACK_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
43 _ctype_ _typename_##_back(const _typename_* const vec)
45 #define VECTOR_DATA_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
46 _ctype_* _typename_##_data(const _typename_* const vec)
48 #define VECTOR_EMPTY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
49 bool _typename_##_empty(const _typename_* const vec)
51 #define VECTOR_SHRINK_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
52 void _typename_##_shrink(_typename_* const vec)
54 #define VECTOR_CLEAR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
55 void _typename_##_clear(_typename_* const vec)
57 #define VECTOR_INSERT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
58 void _typename_##_insert(_typename_* const vec, const size_t pos, _ctype_ const elem)
60 #define VECTOR_ERASE_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
61 void _typename_##_erase(_typename_* const vec, const size_t pos)
63 #define VECTOR_POP_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
64 _ctype_ _typename_##_pop(_typename_* const vec)
66 #define VECTOR_SWAP_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
67 void _typename_##_swap(_typename_* const vec1, _typename_* const vec2)
69 #define VECTOR_INSERT_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
70 void _typename_##_insert_vector(_typename_* const vec, const size_t pos, const _typename_* const ins_vec)
72 #define VECTOR_INSERT_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
73 void _typename_##_insert_array(_typename_* const vec, const size_t pos, _ctype_ const* const array, const size_t array_size)
75 #define VECTOR_PUSH_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
76 void _typename_##_push_array(_typename_* const vec, _ctype_ const* const array, const size_t array_size)
78 #define VECTOR_PUSH_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
79 void _typename_##_push_vector(_typename_* const vec, const _typename_* const push_vec)
81 #define VECTOR_COPY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
82 _typename_ _typename_##_copy(const _typename_* const vec)
84 #define VECTOR_EQV_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
85 bool _typename_##_eqv(const _typename_* const vec1, const _typename_* const vec2, const _typename_##_eqv_func eqv)
87 #define DECLARE_VECTOR(_typename_, _ctype_) \
88 DEFINE_VECTOR_TYPE(_typename_, _ctype_) \
89 DEFINE_VECTOR_ELEM_EQV_FUNCTION_SIGNATURE(_typename_, _ctype_) \
90 VECTOR_CREATE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
91 VECTOR_FREE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
92 VECTOR_GETV_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
93 VECTOR_GETP_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
94 VECTOR_SET_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
95 VECTOR_PUSH_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
96 VECTOR_PRINT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
97 VECTOR_FRONT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
98 VECTOR_BACK_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
99 VECTOR_DATA_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
100 VECTOR_EMPTY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
101 VECTOR_SHRINK_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
102 VECTOR_CLEAR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
103 VECTOR_INSERT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
104 VECTOR_ERASE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
105 VECTOR_POP_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
106 VECTOR_SWAP_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
107 VECTOR_INSERT_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
108 VECTOR_INSERT_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
109 VECTOR_PUSH_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
110 VECTOR_PUSH_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
111 VECTOR_COPY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
112 VECTOR_EQV_FUNCTION_PROTOTYPE(_typename_, _ctype_);
114 #endif // VEC_DECL_H_