gfsmAlphabet.h
Go to the documentation of this file.
1 
2 /*=============================================================================*\
3  * File: gfsmAlphabet.h
4  * Author: Bryan Jurish <moocow.bovine@gmail.com>
5  * Description: finite state machine library: alphabet
6  *
7  * Copyright (c) 2004-2014 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_ALPHABET_H
29 #define _GFSM_ALPHABET_H
30 
31 #include <gfsmCommon.h>
32 #include <gfsmSet.h>
33 #include <gfsmIO.h>
34 
35 /*======================================================================
36  * Alphabet: Flags
37  */
39 typedef enum {
45  gfsmATUser = 256
46 } gfsmAType;
47 
48 /*======================================================================
49  * Alphabet: Basic Types
50  */
52 typedef struct {
56  gboolean utf8;
57 } gfsmAlphabet;
58 
61 
63 typedef struct {
67 
68 // Pointer-hashing alphabet structure (forward decl)
70 
71 // User-extendable alphabet structure (forward decl)
72 struct gfsmUserAlphabet_;
73 
75 
76 /*======================================================================
77  * Alphabet: Function types
78  */
80 
81 
82 typedef gpointer (*gfsmAlphabetKeyDupFunc) (struct gfsmPointerAlphabet_ *a, gpointer key);
83 
85 typedef gfsmLabelVal (*gfsmAlphabetKeyLookupFunc) (struct gfsmUserAlphabet_ *a, gconstpointer key);
86 
88 typedef gpointer (*gfsmAlphabetLabLookupFunc) (struct gfsmUserAlphabet_ *a, gfsmLabelVal lab);
89 
91 typedef gfsmLabelVal (*gfsmAlphabetInsertFunc) (struct gfsmUserAlphabet_ *a, gpointer key, gfsmLabelVal lab);
92 
94 typedef void (*gfsmAlphabetKeyRemoveFunc) (struct gfsmUserAlphabet_ *a, gpointer key);
95 
97 typedef void (*gfsmAlphabetLabRemoveFunc) (struct gfsmUserAlphabet_ *a, gfsmLabelVal lab);
98 
100 typedef gpointer (*gfsmAlphabetKeyReadFunc) (struct gfsmUserAlphabet_ *a, GString *gstr);
101 
103 typedef void (*gfsmAlphabetKeyWriteFunc) (struct gfsmUserAlphabet_ *a, gconstpointer key, GString *str);
104 
106 typedef struct {
114 
118 
119 /*======================================================================
120  * Alphabet: Extendible types
121  */
123 
124 
125 typedef struct gfsmPointerAlphabet_ {
127  GPtrArray *labels2keys;
128  GHashTable *keys2labels;
131 
134 
136 typedef struct gfsmUserAlphabet_
137 {
139  gpointer data;
143 
144 /*======================================================================
145  * Methods: Constructors etc.
146  */
148 
149 
156 
157 
161 #define gfsm_identity_alphabet_new() \
162  gfsm_identity_alphabet_init((gfsmIdentityAlphabet*)gfsm_alphabet_new(gfsmATIdentity))
163 
167 #define gfsm_string_alphabet_new_full(docopy) \
168  gfsm_string_alphabet_init((gfsmStringAlphabet*)gfsm_alphabet_new(gfsmATString),(docopy))
169 
173 #define gfsm_string_alphabet_new() gfsm_string_alphabet_new_full(TRUE)
174 
177 #define gfsm_range_alphabet_new() \
178  gfsm_range_alphabet_init((gfsmRangeAlphabet*)gfsm_alphabet_new(gfsmATRange), \
179  gfsmNoLabel, gfsmNoLabel)
180 
183 #define gfsm_pointer_alphabet_new(key_dup_f, key_hash_f, key_eq_f, key_free_f) \
184  gfsm_pointer_alphabet_init((gfsmPointerAlphabet*)gfsm_alphabet_new(gfsmATPointer),\
185  key_dup_f, key_hash_f, key_eq_f, key_free_f)
186 
187 
194 
195 
198 
201 
204  gfsmAlphabetKeyDupFunc key_dup_func,
205  GHashFunc key_hash_func,
206  GEqualFunc key_equal_func,
207  GDestroyNotify key_destroy_func);
208 
211 
212 
215  gfsmAlphabetKeyDupFunc key_dup_func,
216  GHashFunc key_hash_func,
217  GEqualFunc key_equal_func,
218  GDestroyNotify key_destroy_func,
219  gpointer user_data,
220  gfsmUserAlphabetMethods *methods);
221 
224 
227  gpointer key,
228  gfsmLabelVal lab,
229  gpointer data);
230 
234 
235 /*======================================================================
236  * Methods: Utilties
237  */
239 
240 
243 typedef gboolean (*gfsmAlphabetForeachFunc) (gfsmAlphabet *a,
244  gpointer key,
245  gfsmLabelVal lab,
246  gpointer data);
247 
251  gpointer data);
252 
254 gpointer gfsm_alphabet_strdup(gfsmAlphabet *a, const gchar *str);
256 
257 /*======================================================================
258  * Methods: Accessors
259  */
262 
264 
267  gpointer key,
268  gfsmLabelVal lab,
269  guint *np);
270 
279 
285 
289 #define gfsm_alphabet_get_label(a,key) gfsm_alphabet_get_full(a,key,gfsmNoLabel)
290 
294 gfsmLabelVal gfsm_alphabet_find_label(gfsmAlphabet *a, gconstpointer key);
295 
300 
305 
307 void gfsm_alphabet_remove_key(gfsmAlphabet *a, gconstpointer key);
308 
311 
314 
317  gpointer src_key,
318  gfsmLabelVal src_id,
319  gfsmAlphabet *dst);
320 
322 void gfsm_alphabet_labels_to_array(gfsmAlphabet *alph, GPtrArray *ary);
323 
325 
326 /*======================================================================
327  * Methods: I/O
328  */
330 
331 
335 gpointer gfsm_alphabet_string2key(gfsmAlphabet *a, GString *gstr);
336 
338 void gfsm_alphabet_key2string(gfsmAlphabet *a, gpointer key, GString *gstr);
339 
340 
343 
345 gboolean gfsm_alphabet_load_file (gfsmAlphabet *a, FILE *f, gfsmError **errp);
346 
348 gboolean gfsm_alphabet_load_filename (gfsmAlphabet *a, const gchar *filename, gfsmError **errp);
349 
350 
353 
355 gboolean gfsm_alphabet_save_file (gfsmAlphabet *a, FILE *f, gfsmError **errp);
356 
358 gboolean gfsm_alphabet_save_file_full (gfsmAlphabet *a, FILE *f, int zlevel, gfsmError **errp);
359 
361 gboolean gfsm_alphabet_save_filename (gfsmAlphabet *a, const gchar *filename, gfsmError **errp);
362 
364 gboolean gfsm_alphabet_save_filename_full (gfsmAlphabet *a, const gchar *filename, int zlevel, gfsmError **errp);
365 
367 typedef struct {
370  GString *gstr;
371  gchar *field_sep;
372  gchar *record_sep;
374 
377  gpointer key,
378  gfsmLabelVal lab,
379  gfsmAlphabetSaveFileData *sfdata);
381 
382 /*======================================================================
383  * String Alphabet Utilties
384  */
386 
387 
394  const gchar *str,
395  gfsmLabelVector *vec,
396  gboolean warn_on_undefined);
397 
403 #define gfsm_alphabet_gstring_to_labels(abet,gstr,vec,warn) \
404  gfsm_alphabet_string_to_labels((abet),(gstr)->str,(vec),(warn))
405 
406 
413  const gchar *str,
414  gfsmLabelVector *vec,
415  gboolean warn_on_undefined);
416 
424  const gchar *str,
425  gfsmLabelVector *vec,
426  gboolean warn_on_undefined,
427  gboolean att_mode);
428 
435  gfsmLabelVector *vec,
436  GString *gstr,
437  gboolean warn_on_undefined,
438  gboolean att_style);
439 
446  gfsmLabelVector *vec,
447  gboolean warn_on_undefined,
448  gboolean att_style);
449 
457  gfsmLabelVal lab,
458  GString *gstr,
459  gboolean warn_on_undefined,
460  gboolean att_style,
461  GString *gsym);
463 
464 #endif /*_GFSM_ALPHABET_H */