libt3highlight
 All Data Structures Functions Variables Typedefs Enumerator Modules Pages
vector.h
1 /* Copyright (C) 2011 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_HIGHLIGHT_VECTOR_H
15 #define T3_HIGHLIGHT_VECTOR_H
16 
17 #include <stdlib.h>
18 #include "highlight_api.h"
19 
20 typedef struct {
21  void *data;
22  size_t allocated,
23  used;
24 } vector_base_t;
25 
26 #define VECTOR(type) struct { type *data; size_t allocated, used; }
27 #define VECTOR_INIT(name) do { (name).data = NULL; (name).allocated = 0; (name).used = 0; } while (0)
28 #define VECTOR_ITERATE(name, func) do { size_t _i; for (_i = 0; _i < (name).used; _i++) func(&(name).data[_i]); } while (0)
29 #define VECTOR_RESERVE(name) _t3_highlight_vector_reserve((vector_base_t *) &name, sizeof((name).data[0]))
30 #define VECTOR_LAST(name) (name).data[(name).used - 1]
31 #define VECTOR_FREE(name) free((name).data)
32 
33 T3_HIGHLIGHT_LOCAL t3_bool _t3_highlight_vector_reserve(vector_base_t *vector, size_t elsize);
34 
35 #endif
char t3_bool
A boolean type that does not clash with C++ or C99 bool.
Definition: highlight_api.h:47