Data Structures | Typedefs | Enumerations
gfsmAlphabet.h File Reference

Map between gfsmLabelIds and external objects. More...

#include <gfsmCommon.h>
#include <gfsmSet.h>
#include <gfsmIO.h>
Include dependency graph for gfsmAlphabet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gfsmAlphabet
 Generic alphabet structure. More...
struct  gfsmIdentityAlphabet
 Sparse identity alphabet structure. More...
struct  gfsmUserAlphabetMethods
 method table for user-defined alphabets More...
struct  gfsmPointerAlphabet_
 Pointer-hashing alphabet structure. More...
struct  gfsmUserAlphabet_
 User-extendable alphabet structure. More...
struct  gfsmAlphabetSaveFileData
 datatype used for save_file() iteration More...

Typedefs

typedef gfsmAlphabet gfsmRangeAlphabet
 Ranged alphabet structure.
Alphabet: Extendible Types
typedef struct gfsmPointerAlphabet_ gfsmPointerAlphabet
 Pointer-hashing alphabet structure.
typedef gfsmPointerAlphabet gfsmStringAlphabet
 type for string alphabets
typedef struct gfsmUserAlphabet_ gfsmUserAlphabet
 User-extendable alphabet structure.

Enumerations

enum  gfsmAType {
  gfsmATUnknown = 0, gfsmATRange = 1, gfsmATIdentity = 2, gfsmATPointer = 3,
  gfsmATString = 4, gfsmATUser = 256
}

Functions

I/O
gpointer gfsm_alphabet_string2key (gfsmAlphabet *a, GString *gstr)
void gfsm_alphabet_key2string (gfsmAlphabet *a, gpointer key, GString *gstr)
gboolean gfsm_alphabet_load_handle (gfsmAlphabet *a, gfsmIOHandle *ioh, gfsmError **errp)
gboolean gfsm_alphabet_load_file (gfsmAlphabet *a, FILE *f, gfsmError **errp)
gboolean gfsm_alphabet_load_filename (gfsmAlphabet *a, const gchar *filename, gfsmError **errp)
gboolean gfsm_alphabet_save_handle (gfsmAlphabet *a, gfsmIOHandle *ioh, gfsmError **errp)
gboolean gfsm_alphabet_save_file (gfsmAlphabet *a, FILE *f, gfsmError **errp)
gboolean gfsm_alphabet_save_file_full (gfsmAlphabet *a, FILE *f, int zlevel, gfsmError **errp)
gboolean gfsm_alphabet_save_filename (gfsmAlphabet *a, const gchar *filename, gfsmError **errp)
gboolean gfsm_alphabet_save_filename_full (gfsmAlphabet *a, const gchar *filename, int zlevel, gfsmError **errp)
gboolean gfsm_alphabet_save_file_func (gfsmAlphabet *a, gpointer key, gfsmLabelVal lab, gfsmAlphabetSaveFileData *sfdata)

Alphabet: Function Types

typedef gpointer(* gfsmAlphabetKeyDupFunc )(struct gfsmPointerAlphabet_ *a, gpointer key)
typedef gfsmLabelVal(* gfsmAlphabetKeyLookupFunc )(struct gfsmUserAlphabet_ *a, gconstpointer key)
typedef gpointer(* gfsmAlphabetLabLookupFunc )(struct gfsmUserAlphabet_ *a, gfsmLabelVal lab)
typedef gfsmLabelVal(* gfsmAlphabetInsertFunc )(struct gfsmUserAlphabet_ *a, gpointer key, gfsmLabelVal lab)
typedef void(* gfsmAlphabetKeyRemoveFunc )(struct gfsmUserAlphabet_ *a, gpointer key)
typedef void(* gfsmAlphabetLabRemoveFunc )(struct gfsmUserAlphabet_ *a, gfsmLabelVal lab)
typedef gpointer(* gfsmAlphabetKeyReadFunc )(struct gfsmUserAlphabet_ *a, GString *gstr)
typedef void(* gfsmAlphabetKeyWriteFunc )(struct gfsmUserAlphabet_ *a, gconstpointer key, GString *str)
gfsmUserAlphabetMethods gfsmUserAlphabetDefaultMethods
 default methods for user-defined alphabets (dummy)

Constructors etc.

#define gfsm_identity_alphabet_new()   gfsm_identity_alphabet_init((gfsmIdentityAlphabet*)gfsm_alphabet_new(gfsmATIdentity))
#define gfsm_string_alphabet_new_full(docopy)   gfsm_string_alphabet_init((gfsmStringAlphabet*)gfsm_alphabet_new(gfsmATString),(docopy))
#define gfsm_string_alphabet_new()   gfsm_string_alphabet_new_full(TRUE)
#define gfsm_range_alphabet_new()
#define gfsm_pointer_alphabet_new(key_dup_f, key_hash_f, key_eq_f, key_free_f)
gfsmAlphabetgfsm_alphabet_new (gfsmAType type)
gfsmAlphabetgfsm_alphabet_init (gfsmAlphabet *a)
gfsmAlphabetgfsm_range_alphabet_init (gfsmRangeAlphabet *a, gfsmLabelVal min, gfsmLabelVal max)
gfsmAlphabetgfsm_identity_alphabet_init (gfsmIdentityAlphabet *a)
gfsmAlphabetgfsm_pointer_alphabet_init (gfsmPointerAlphabet *a, gfsmAlphabetKeyDupFunc key_dup_func, GHashFunc key_hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func)
gfsmAlphabetgfsm_string_alphabet_init (gfsmStringAlphabet *a, gboolean do_copy)
gfsmAlphabetgfsm_user_alphabet_init (gfsmUserAlphabet *a, gfsmAlphabetKeyDupFunc key_dup_func, GHashFunc key_hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, gpointer user_data, gfsmUserAlphabetMethods *methods)
void gfsm_alphabet_clear (gfsmAlphabet *a)
gboolean gfsm_alphabet_foreach_remove_func (gfsmAlphabet *a, gpointer key, gfsmLabelVal lab, gpointer data)
void gfsm_alphabet_free (gfsmAlphabet *a)

Utilities

typedef gboolean(* gfsmAlphabetForeachFunc )(gfsmAlphabet *a, gpointer key, gfsmLabelVal lab, gpointer data)
gboolean gfsm_alphabet_foreach (gfsmAlphabet *a, gfsmAlphabetForeachFunc func, gpointer data)
gpointer gfsm_alphabet_strdup (gfsmAlphabet *a, const gchar *str)

Accessors

#define gfsm_alphabet_get_label(a, key)   gfsm_alphabet_get_full(a,key,gfsmNoLabel)
gfsmLabelVal gfsm_alphabet_size (gfsmAlphabet *a)
gboolean gfsm_alphabet_foreach_size_func (gfsmAlphabet *a, gpointer key, gfsmLabelVal lab, guint *np)
gfsmLabelVal gfsm_alphabet_insert (gfsmAlphabet *a, gpointer key, gfsmLabelVal label)
gfsmLabelVal gfsm_alphabet_get_full (gfsmAlphabet *a, gpointer key, gfsmLabelVal label)
gfsmLabelVal gfsm_alphabet_find_label (gfsmAlphabet *a, gconstpointer key)
gpointer gfsm_alphabet_find_key (gfsmAlphabet *a, gfsmLabelVal label)
gpointer gfsm_alphabet_get_key (gfsmAlphabet *a, gfsmLabelVal label)
void gfsm_alphabet_remove_key (gfsmAlphabet *a, gconstpointer key)
void gfsm_alphabet_remove_label (gfsmAlphabet *a, gfsmLabelVal label)
gfsmAlphabetgfsm_alphabet_union (gfsmAlphabet *a1, gfsmAlphabet *a2)
gboolean gfsm_alphabet_foreach_union_func (gfsmAlphabet *src, gpointer src_key, gfsmLabelVal src_id, gfsmAlphabet *dst)
void gfsm_alphabet_labels_to_array (gfsmAlphabet *alph, GPtrArray *ary)

String Alphabet Utilities

#define gfsm_alphabet_gstring_to_labels(abet, gstr, vec, warn)   gfsm_alphabet_string_to_labels((abet),(gstr)->str,(vec),(warn))
gfsmLabelVectorgfsm_alphabet_string_to_labels (gfsmAlphabet *abet, const gchar *str, gfsmLabelVector *vec, gboolean warn_on_undefined)
gfsmLabelVectorgfsm_alphabet_att_string_to_labels (gfsmAlphabet *abet, const gchar *str, gfsmLabelVector *vec, gboolean warn_on_undefined)
gfsmLabelVectorgfsm_alphabet_generic_string_to_labels (gfsmAlphabet *abet, const gchar *str, gfsmLabelVector *vec, gboolean warn_on_undefined, gboolean att_mode)
GString * gfsm_alphabet_labels_to_gstring (gfsmAlphabet *abet, gfsmLabelVector *vec, GString *gstr, gboolean warn_on_undefined, gboolean att_style)
char * gfsm_alphabet_labels_to_string (gfsmAlphabet *abet, gfsmLabelVector *vec, gboolean warn_on_undefined, gboolean att_style)
void gfsm_alphabet_label_to_gstring (gfsmAlphabet *abet, gfsmLabelVal lab, GString *gstr, gboolean warn_on_undefined, gboolean att_style, GString *gsym)

Detailed Description

Macro Definition Documentation

#define gfsm_identity_alphabet_new ( )    gfsm_identity_alphabet_init((gfsmIdentityAlphabet*)gfsm_alphabet_new(gfsmATIdentity))

Create and initialize a new identity alphabet. You do not need to call an init() function for the returned alphabet.

#define gfsm_string_alphabet_new_full (   docopy)    gfsm_string_alphabet_init((gfsmStringAlphabet*)gfsm_alphabet_new(gfsmATString),(docopy))

Create and initialize a new string alphabet. You do not need to call an init() function for the returned alphabet.

#define gfsm_string_alphabet_new ( )    gfsm_string_alphabet_new_full(TRUE)

Create and initialize a new string alphabet which copies keys. You do not need to call an init() function for the returned alphabet.

#define gfsm_range_alphabet_new ( )
Value:

Create and initialize a new range alphabet. You do not need to call an init() function for the returned alphabet.

#define gfsm_pointer_alphabet_new (   key_dup_f,
  key_hash_f,
  key_eq_f,
  key_free_f 
)
Value:
key_dup_f, key_hash_f, key_eq_f, key_free_f)

Create and initialize a new pointer alphabet. You do not need to call an init() function for the returned alphabet.

#define gfsm_alphabet_get_label (   a,
  key 
)    gfsm_alphabet_get_full(a,key,gfsmNoLabel)

Get label for key or assign a new one if none exists.

Returns
label for key
#define gfsm_alphabet_gstring_to_labels (   abet,
  gstr,
  vec,
  warn 
)    gfsm_alphabet_string_to_labels((abet),(gstr)->str,(vec),(warn))

Convert an ASCII GString character-wise to a vector of (gfsmLabel)s. vec is not cleared – use g_ptr_array_set_size() for that.

Returns
vec if non-NULL, otherwise a new gfsmLabelVector. abet should be a gfsmStringAlphabet.

Typedef Documentation

typedef gpointer(* gfsmAlphabetKeyDupFunc)(struct gfsmPointerAlphabet_ *a, gpointer key)

Type for key-duplication functions

typedef gfsmLabelVal(* gfsmAlphabetKeyLookupFunc)(struct gfsmUserAlphabet_ *a, gconstpointer key)

Type for alphabet (key->label) lookup functions

typedef gpointer(* gfsmAlphabetLabLookupFunc)(struct gfsmUserAlphabet_ *a, gfsmLabelVal lab)

Type for alphabet (label->key) lookup functions

typedef gfsmLabelVal(* gfsmAlphabetInsertFunc)(struct gfsmUserAlphabet_ *a, gpointer key, gfsmLabelVal lab)

Type for alphabet insertion functions

typedef void(* gfsmAlphabetKeyRemoveFunc)(struct gfsmUserAlphabet_ *a, gpointer key)

Type for alphabet key removal functions (unused)

typedef void(* gfsmAlphabetLabRemoveFunc)(struct gfsmUserAlphabet_ *a, gfsmLabelVal lab)

Type for alphabet label removal functions

typedef gpointer(* gfsmAlphabetKeyReadFunc)(struct gfsmUserAlphabet_ *a, GString *gstr)

Type for alphabet string input functions (should return a static key)

typedef void(* gfsmAlphabetKeyWriteFunc)(struct gfsmUserAlphabet_ *a, gconstpointer key, GString *str)

Type for alphabet string output functions (should write to )

typedef gboolean(* gfsmAlphabetForeachFunc)(gfsmAlphabet *a, gpointer key, gfsmLabelVal lab, gpointer data)

Type for alphabet iterator functions. Functions should return TRUE to stop the traversal

Enumeration Type Documentation

enum gfsmAType

Enumeration of builtin alphabet types

Enumerator:
gfsmATUnknown 

unknown alphabet type

gfsmATRange 

alphabet type for label ranges

gfsmATIdentity 

alphabet type for sparse identity alphabets

gfsmATPointer 

pointer-hashing alphabet

gfsmATString 

string alphabet

gfsmATUser 

user-defined alphabet

Function Documentation

gfsmAlphabet* gfsm_alphabet_new ( gfsmAType  type)

Create a new alphabet. The alphabet will be uninitialized until you call one of the gfsm_*_alphabet_init() functions.

Parameters
typeType of alphabet to create.
gfsmAlphabet* gfsm_alphabet_init ( gfsmAlphabet a)

Initialize a builtin alphabet (depending on a->type) This really only works well for identity, range, and string alphabets, as well as for literal pointer alphabets (without copy and/or free) and for user alphabets using literal pointers.

gfsmAlphabet* gfsm_range_alphabet_init ( gfsmRangeAlphabet a,
gfsmLabelVal  min,
gfsmLabelVal  max 
)

Initialize a range alphabet

gfsmAlphabet* gfsm_identity_alphabet_init ( gfsmIdentityAlphabet a)

Initialize a sparse identity alphabet

gfsmAlphabet* gfsm_pointer_alphabet_init ( gfsmPointerAlphabet a,
gfsmAlphabetKeyDupFunc  key_dup_func,
GHashFunc  key_hash_func,
GEqualFunc  key_equal_func,
GDestroyNotify  key_destroy_func 
)

Initialize a pointer alphabet

gfsmAlphabet* gfsm_string_alphabet_init ( gfsmStringAlphabet a,
gboolean  do_copy 
)

Initialize a string alphabet

gfsmAlphabet* gfsm_user_alphabet_init ( gfsmUserAlphabet a,
gfsmAlphabetKeyDupFunc  key_dup_func,
GHashFunc  key_hash_func,
GEqualFunc  key_equal_func,
GDestroyNotify  key_destroy_func,
gpointer  user_data,
gfsmUserAlphabetMethods methods 
)

Initialize a user alphabet

void gfsm_alphabet_clear ( gfsmAlphabet a)

Clear all labels and keys from a gfsmAlphabet

gboolean gfsm_alphabet_foreach_remove_func ( gfsmAlphabet a,
gpointer  key,
gfsmLabelVal  lab,
gpointer  data 
)

foreach utility function to clear user alphabets

void gfsm_alphabet_free ( gfsmAlphabet a)

Free all memory allocated by a gfsmAlphabet

gboolean gfsm_alphabet_foreach ( gfsmAlphabet a,
gfsmAlphabetForeachFunc  func,
gpointer  data 
)

General iteration utility

gpointer gfsm_alphabet_strdup ( gfsmAlphabet a,
const gchar *  str 
)

dup function for string alphabets

gfsmLabelVal gfsm_alphabet_size ( gfsmAlphabet a)

Get number of elements in the alphabet

gboolean gfsm_alphabet_foreach_size_func ( gfsmAlphabet a,
gpointer  key,
gfsmLabelVal  lab,
guint *  np 
)

Utility for counting size of user alphabets (linear time)

gfsmLabelVal gfsm_alphabet_insert ( gfsmAlphabet a,
gpointer  key,
gfsmLabelVal  label 
)

Insert a (key,label) pair into the alphabet. If label is gfsmNoLabel, a new label will be assigned.

Note
No sanity checks are performed.
Returns
the new label for key
gfsmLabelVal gfsm_alphabet_get_full ( gfsmAlphabet a,
gpointer  key,
gfsmLabelVal  label 
)

Get or assign a label for key. If label is gfsmNoLabel, a new label will be assigned for key if none exists.

Returns
label for key
gfsmLabelVal gfsm_alphabet_find_label ( gfsmAlphabet a,
gconstpointer  key 
)

Lookup label for key.

Returns
label for key, or gfsmNoLabel if none is defined.
gpointer gfsm_alphabet_find_key ( gfsmAlphabet a,
gfsmLabelVal  label 
)

Lookup key for label

Returns
pointer to key for label, or NULL if no key is defined.
gpointer gfsm_alphabet_get_key ( gfsmAlphabet a,
gfsmLabelVal  label 
)

Get key for label or assign gfsmNoKey if none exists.

Returns
key for label
void gfsm_alphabet_remove_key ( gfsmAlphabet a,
gconstpointer  key 
)

Remove mapping for key (and associated label, if any)

void gfsm_alphabet_remove_label ( gfsmAlphabet a,
gfsmLabelVal  label 
)

Remove mapping for label (and associated key, if any)

gfsmAlphabet* gfsm_alphabet_union ( gfsmAlphabet a1,
gfsmAlphabet a2 
)

Add all keys from alphabet a2 to a1.

Returns
a1
gboolean gfsm_alphabet_foreach_union_func ( gfsmAlphabet src,
gpointer  src_key,
gfsmLabelVal  src_id,
gfsmAlphabet dst 
)

foreach utility func for union()

void gfsm_alphabet_labels_to_array ( gfsmAlphabet alph,
GPtrArray *  ary 
)

Append all defined labels to a GPtrArray of (gfsmLabelVal)s

gpointer gfsm_alphabet_string2key ( gfsmAlphabet a,
GString *  gstr 
)

Convert a string to a temporary key, used by load(). If you allocate anything here, you need to free it yourself.

void gfsm_alphabet_key2string ( gfsmAlphabet a,
gpointer  key,
GString *  gstr 
)

Convert a key to a constant string, used by save()

gboolean gfsm_alphabet_load_handle ( gfsmAlphabet a,
gfsmIOHandle ioh,
gfsmError **  errp 
)

Load a string alphabet from a stream. Returns true on success

gboolean gfsm_alphabet_load_file ( gfsmAlphabet a,
FILE *  f,
gfsmError **  errp 
)

Load a string alphabet from a stream. Returns true on success

gboolean gfsm_alphabet_load_filename ( gfsmAlphabet a,
const gchar *  filename,
gfsmError **  errp 
)

Load a string alphabet from a named file

gboolean gfsm_alphabet_save_handle ( gfsmAlphabet a,
gfsmIOHandle ioh,
gfsmError **  errp 
)

Save a string alphabet to a gfsmIOHandle*

gboolean gfsm_alphabet_save_file ( gfsmAlphabet a,
FILE *  f,
gfsmError **  errp 
)

Save a string alphabet to a stream (uncompressed)

gboolean gfsm_alphabet_save_file_full ( gfsmAlphabet a,
FILE *  f,
int  zlevel,
gfsmError **  errp 
)

Save a string alphabet to a (compressed) stream

gboolean gfsm_alphabet_save_filename ( gfsmAlphabet a,
const gchar *  filename,
gfsmError **  errp 
)

Save a string alphabet to a named file (uncompressed)

gboolean gfsm_alphabet_save_filename_full ( gfsmAlphabet a,
const gchar *  filename,
int  zlevel,
gfsmError **  errp 
)

Save a string alphabet to a (compressed) named file

gboolean gfsm_alphabet_save_file_func ( gfsmAlphabet a,
gpointer  key,
gfsmLabelVal  lab,
gfsmAlphabetSaveFileData sfdata 
)

save_file iterator func

gfsmLabelVector* gfsm_alphabet_string_to_labels ( gfsmAlphabet abet,
const gchar *  str,
gfsmLabelVector vec,
gboolean  warn_on_undefined 
)

Convert an ASCII string character-wise to a vector of (gfsmLabel)s. vec is not cleared – use g_ptr_array_set_size() for that.

Returns
vec if non-NULL, otherwise a new gfsmLabelVector. abet should be a gfsmStringAlphabet.
gfsmLabelVector* gfsm_alphabet_att_string_to_labels ( gfsmAlphabet abet,
const gchar *  str,
gfsmLabelVector vec,
gboolean  warn_on_undefined 
)

Convert an ASCII string in AT&T syntax to a vector of (gfsmLabel)s. vec is not cleared – use g_ptr_array_set_size() for that.

Returns
vec if non-NULL, otherwise a new gfsmLabelVector. abet should be a gfsmStringAlphabet.
gfsmLabelVector* gfsm_alphabet_generic_string_to_labels ( gfsmAlphabet abet,
const gchar *  str,
gfsmLabelVector vec,
gboolean  warn_on_undefined,
gboolean  att_mode 
)

Convert an ASCII string to a vector of (gfsmLabel)s, using either gfsm_alphabet_string_to_labels() or gfsm_alphabet_att_string_to_labels().

Parameters
abet,str,vec,warn_undefas for gfsm_alphabet_string_to_labels().
att_modeif true, str is parsed as att-syntax, otherwise character-wise
Returns
as for gfsm_alphabet_string_to_labels()
GString* gfsm_alphabet_labels_to_gstring ( gfsmAlphabet abet,
gfsmLabelVector vec,
GString *  gstr,
gboolean  warn_on_undefined,
gboolean  att_style 
)

Convert a gfsmLabelVector to a GString. gstr is not cleared.

Returns
gstr if non-NULL, otherwise a new GString*. abet should be a gfsmStringAlphabet.
char* gfsm_alphabet_labels_to_string ( gfsmAlphabet abet,
gfsmLabelVector vec,
gboolean  warn_on_undefined,
gboolean  att_style 
)

Convert a gfsmLabelVector to a new string. gstr is not cleared.

Returns
gstr if non-NULL, otherwise a new GString*. abet should be a gfsmStringAlphabet.
void gfsm_alphabet_label_to_gstring ( gfsmAlphabet abet,
gfsmLabelVal  lab,
GString *  gstr,
gboolean  warn_on_undefined,
gboolean  att_style,
GString *  gsym 
)

Append a single gfsmLabelVal to a GString*.

  • gstr is not cleared.
  • gsym is a temporary which may be overwritten by this function
    Returns
    gstr if non-NULL, otherwise a new GString*.
    Note
    abet should really be a gfsmStringAlphabet.

Variable Documentation

gfsmUserAlphabetMethods gfsmUserAlphabetDefaultMethods