gfsmEnum.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmEnum.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library
6  *
7  * Copyright (c) 2004-2007 Bryan Jurish.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *=============================================================================*/
23 
28 #ifndef _GFSM_ENUM_H
29 #define _GFSM_ENUM_H
30 
31 #include <gfsmMem.h>
32 #include <gfsmCommon.h>
33 
34 /*======================================================================
35  * Types
36  */
38 
39 
41 typedef struct {
42  GHashTable *table;
43  guint nxtval;
45 } gfsmEnum;
46 
49 
51 extern const guint gfsmEnumNone;
52 
54 
55 /*======================================================================
56  * Methods: Constructors etc.
57  */
59 
60 
64  GHashFunc key_hash_func,
65  GEqualFunc key_equal_func,
66  GDestroyNotify key_destroy_func);
67 
69 #define gfsm_enum_new(key_hash_f) gfsm_enum_new_full(NULL,key_hash_f,NULL,NULL)
70 
72 #define gfsm_direct_enum_new() gfsm_enum_new(g_direct_hash)
73 
76 void gfsm_enum_clear(gfsmEnum *en);
77 
80 void gfsm_enum_free(gfsmEnum *en);
82 
83 /*======================================================================
84  * Methods: Accessors
85  */
87 
88 
90 #define gfsm_enum_next_value(en) ((en)->nxtval)
91 
99  gconstpointer lookup_key,
100  gpointer *stored_key,
101  gpointer *stored_val);
102 
108 guint gfsm_enum_lookup(gfsmEnum *en, gconstpointer key);
109 
110 
116 guint gfsm_enum_insert_full(gfsmEnum *en, gpointer key, guint val);
117 
119 #define gfsm_enum_insert(en,key) gfsm_enum_insert_full(en,key,gfsmEnumNone)
120 
122 #define gfsm_enum_get(en,key) gfsm_enum_insert(en,key)
123 
124 //-- inline definitions
125 #ifdef GFSM_INLINE_ENABLED
126 # include <gfsmEnum.hi>
127 #endif
128 
129 #endif /* _GFSM_ENUM_H */