update Makefile
[cvector.git] / vec_decl.h
blob014107975a0c6b596ac7ecf37b1d109d743de977
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_GET_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
25 _ctype_ _typename_##_get(const _typename_ vec, const size_t index)
27 #define VECTOR_SET_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
28 void _typename_##_set(const _typename_ vec, const size_t index, _ctype_ const val)
30 #define VECTOR_PUSH_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
31 void _typename_##_push(_typename_* const vec, _ctype_ const val)
33 #define VECTOR_PRINT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
34 void _typename_##_print(const _typename_ vec, char const* const element_format, char const* const separator)
36 #define VECTOR_FRONT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
37 _ctype_ _typename_##_front(const _typename_ vec)
39 #define VECTOR_BACK_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
40 _ctype_ _typename_##_back(const _typename_ vec)
42 #define VECTOR_DATA_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
43 _ctype_* _typename_##_data(const _typename_ vec)
45 #define VECTOR_EMPTY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
46 bool _typename_##_empty(const _typename_ vec)
48 #define VECTOR_SHRINK_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
49 void _typename_##_shrink(_typename_* const vec)
51 #define VECTOR_CLEAR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
52 void _typename_##_clear(_typename_* const vec)
54 #define VECTOR_INSERT_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
55 void _typename_##_insert(_typename_* const vec, const size_t pos, _ctype_ const elem)
57 #define VECTOR_ERASE_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
58 void _typename_##_erase(_typename_* const vec, const size_t pos)
60 #define VECTOR_POP_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
61 _ctype_ _typename_##_pop(_typename_* const vec)
63 #define VECTOR_SWAP_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
64 void _typename_##_swap(_typename_* const vec1, _typename_* const vec2)
66 #define VECTOR_INSERT_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
67 void _typename_##_insert_vector(_typename_* const vec, const size_t pos, const _typename_ ins_vec)
69 #define VECTOR_INSERT_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
70 void _typename_##_insert_array(_typename_* const vec, const size_t pos, _ctype_ const* const array, const size_t array_size)
72 #define VECTOR_PUSH_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
73 void _typename_##_push_array(_typename_* const vec, _ctype_ const* const array, const size_t array_size)
75 #define VECTOR_PUSH_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
76 void _typename_##_push_vector(_typename_* const vec, const _typename_ push_vec)
78 #define VECTOR_COPY_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
79 _typename_ _typename_##_copy(const _typename_ vec)
81 #define VECTOR_EQV_FUNCTION_PROTOTYPE(_typename_, _ctype_) \
82 bool _typename_##_eqv(const _typename_ vec1, const _typename_ vec2, const _typename_##_eqv_func eqv)
84 #define DECLARE_VECTOR(_typename_, _ctype_) \
85 DEFINE_VECTOR_TYPE(_typename_, _ctype_) \
86 DEFINE_VECTOR_ELEM_EQV_FUNCTION_SIGNATURE(_typename_, _ctype_) \
87 VECTOR_CREATE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
88 VECTOR_FREE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
89 VECTOR_GET_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
90 VECTOR_SET_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
91 VECTOR_PUSH_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
92 VECTOR_PRINT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
93 VECTOR_FRONT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
94 VECTOR_BACK_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
95 VECTOR_DATA_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
96 VECTOR_EMPTY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
97 VECTOR_SHRINK_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
98 VECTOR_CLEAR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
99 VECTOR_INSERT_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
100 VECTOR_ERASE_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
101 VECTOR_POP_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
102 VECTOR_SWAP_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
103 VECTOR_INSERT_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
104 VECTOR_INSERT_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
105 VECTOR_PUSH_ARRAY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
106 VECTOR_PUSH_VECTOR_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
107 VECTOR_COPY_FUNCTION_PROTOTYPE(_typename_, _ctype_); \
108 VECTOR_EQV_FUNCTION_PROTOTYPE(_typename_, _ctype_);
110 #endif // VEC_DECL_H_