libt3highlight
/home/gertjan/projects/tilde/highlight/src/vector.h
00001 /* Copyright (C) 2011 G.P. Halkes
00002    This program is free software: you can redistribute it and/or modify
00003    it under the terms of the GNU General Public License version 3, as
00004    published by the Free Software Foundation.
00005 
00006    This program is distributed in the hope that it will be useful,
00007    but WITHOUT ANY WARRANTY; without even the implied warranty of
00008    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009    GNU General Public License for more details.
00010 
00011    You should have received a copy of the GNU General Public License
00012    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00013 */
00014 #ifndef T3_HIGHLIGHT_VECTOR_H
00015 #define T3_HIGHLIGHT_VECTOR_H
00016 
00017 #include <stdlib.h>
00018 #include "highlight_api.h"
00019 
00020 typedef struct {
00021         void *data;
00022         size_t allocated,
00023                 used;
00024 } vector_base_t;
00025 
00026 #define VECTOR(type, name) struct { type *data; size_t allocated, used; } name
00027 #define VECTOR_INIT(name) do { (name).data = NULL; (name).allocated = 0; (name).used = 0; } while (0)
00028 #define VECTOR_ITERATE(name, func) do { size_t _i; for (_i = 0; _i < (name).used; _i++) func(&(name).data[_i]); } while (0)
00029 #define VECTOR_RESERVE(name) _t3_highlight_vector_reserve((vector_base_t *) &name, sizeof((name).data[0]))
00030 #define VECTOR_LAST(name) (name).data[(name).used - 1]
00031 #define VECTOR_FREE(name) free((name).data)
00032 
00033 T3_HIGHLIGHT_LOCAL t3_bool _t3_highlight_vector_reserve(vector_base_t *vector, size_t elsize);
00034 
00035 #endif
 All Data Structures Variables