78a9cc51c5a0569e1c7bff1cd243be81911786ab
[swftools.git] / lib / as3 / utils.h
1 /* utils.c
2
3    Extension module for the rfxswf library.
4    Part of the swftools package.
5
6    Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #ifndef __as3_utils_h__
23 #define __as3_utils_h__
24
25 #define NEW(t,y) t*y = (t*)malloc(sizeof(t));memset(y, 0, sizeof(t));
26
27 #define DECLARE(x) struct _##x;typedef struct _##x x##_t;
28 #define DECLARE_LIST(x) \
29 struct _##x##_list { \
30     struct _##x* x; \
31     struct _##x##_list*next; \
32 }; \
33 typedef struct _##x##_list x##_list_t; \
34
35 int list_length(void*_list);
36 void list_append(void*_list, void*entry);
37
38 typedef struct _dict_entry {
39     const char*name;
40     void*data;
41 } dict_entry_t;
42
43 typedef struct _dict {
44     int num;
45     int size;
46     dict_entry_t*d;
47 } dict_t;
48
49 dict_t* dict_new();
50 void dict_free(dict_t*dict);
51 const char*dict_getstr(dict_t*dict, int nr);
52 char*dict_getdata(dict_t*dict, int nr);
53 int dict_append(dict_t*dict, const char*name, void*data);
54 int dict_find(dict_t*dict, const char*name);
55 int dict_find2(dict_t*dict, const char*name, void*data);
56 int dict_update(dict_t*dict, const char*name, void*data);
57 int dict_append_if_new(dict_t*dict, const char*name, void*data);
58
59 #endif