aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmState.h
blob: a3fd36310c6150e3c6be1880e8d997f1f04e5a71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

/*=============================================================================*\
 * File: gfsmState.h
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library: states
 *
 * Copyright (c) 2004-2007 Bryan Jurish.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *=============================================================================*/

/** \file gfsmState.h
 *  \brief Automaton state definitions & utilities
 */

#ifndef _GFSM_STATE_H
#define _GFSM_STATE_H

#include <gfsmArcList.h>

/*======================================================================
 * Types
 */

/// Automaton state structure
typedef struct {
  guint32       is_valid      : 1;  /**< whether this is a valid state */
  guint32       is_final      : 1;  /**< whether this is a final state */
  guint32       is_temp       : 1;  /**< whether this state should be freed on gfsm_state_close() */
  guint32       arc_list_temp : 1;  /**< whether arc list should be freed on gfsm_state_close() */
  guint32       arc_data_temp : 1;  /**< whether arc data should be freed on gfsm_state_close(): implies arc_list_temp=1 */
  guint32       unused        : 27; /**< reserved */
  gfsmArcList  *arcs;             /**< list of outgoing arcs */
} gfsmState;


/*======================================================================
 * Methods: gfsmState: Constructors etc.
 */
/// \name gfsmState: Constructors etc.
//@{
/** Create a new state (generic) */
GFSM_INLINE
gfsmState *gfsm_state_new_full(gboolean is_final, gfsmArcList *arcs);

/** Create a new state (empty) */
GFSM_INLINE
gfsmState *gfsm_state_new(void);

/** Copy an existing state */
GFSM_INLINE
gfsmState *gfsm_state_copy(gfsmState *dst, const gfsmState *src);

/** Clear an existing state */
GFSM_INLINE
void gfsm_state_clear(gfsmState *s);

/** Destroy a state */
GFSM_INLINE
void gfsm_state_free(gfsmState *s, gboolean free_arcs);

/** Close a state (generic) */
GFSM_INLINE
void gfsm_state_close(gfsmState *s);

//@}

/*======================================================================
 * Methods: gfsmState: Accessors
 */
///\name gfsmState: Accessors
//@{

/** Check if state is valid */
GFSM_INLINE
gboolean gfsm_state_is_ok(const gfsmState *s);

/** Check for final state */
GFSM_INLINE
gboolean gfsm_state_is_final(const gfsmState *s);

/** Set final state flag */
GFSM_INLINE
void gfsm_state_set_final(gfsmState *s, gboolean is_final);

/** Get number of outgoing arcs */
GFSM_INLINE
guint gfsm_state_out_degree(const gfsmState *s);

//@}

//-- inline definitions
#ifdef GFSM_INLINE_ENABLED
# include <gfsmState.hi>
#endif

#endif /* _GFSM_STATE_H */