aboutsummaryrefslogtreecommitdiff
path: root/gfsm/gfsm/src/libgfsm/gfsmState.hi
blob: 15b2669afc566f62d80cc11680236c7212e6ad0e (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

/*=============================================================================*\
 * File: gfsmState.hi
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: finite state machine library: states: inline definitions
 *
 * 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
 *=============================================================================*/

#include <gfsmMem.h>

/*======================================================================
 * Methods: Constructors etc.
 */

/*--------------------------------------------------------------
 * new_full()
 */
GFSM_INLINE
gfsmState *gfsm_state_new_full(gboolean is_final, gfsmArcList *arcs)
{
  gfsmState *s = g_new(gfsmState,1);
  s->is_valid = TRUE;
  s->is_final = is_final;
  s->arcs     = arcs;
  return s;
}

/*--------------------------------------------------------------
 * new()
 */
GFSM_INLINE
gfsmState *gfsm_state_new(void)
{
  return gfsm_state_new_full(FALSE, NULL);
}

/*--------------------------------------------------------------
 * clear()
 */
GFSM_INLINE
void gfsm_state_clear(gfsmState *s)
{
  gfsm_arclist_free(s->arcs);
  s->is_valid = FALSE;
  s->is_final = FALSE;
  s->arcs     = NULL;
}

/*--------------------------------------------------------------
 * clone()
 */
GFSM_INLINE
gfsmState *gfsm_state_copy(gfsmState *dst, const gfsmState *src)
{
  gfsm_state_clear(dst);
  if (!src->is_valid) return dst;
  dst->is_valid = src->is_valid;
  dst->is_final = src->is_final;
  //dst->arcs     = g_slist_concat(gfsm_arclist_clone(src->arcs), dst->arcs);
  dst->arcs     = gfsm_arclist_clone(src->arcs);
  return dst;
}


/*--------------------------------------------------------------
 * free()
 */
GFSM_INLINE
void gfsm_state_free(gfsmState *s, gboolean free_arcs)
{
  if (free_arcs && s->arcs) gfsm_arclist_free(s->arcs);
  g_free(s);
}

/*--------------------------------------------------------------
 * close()
 */
GFSM_INLINE
void gfsm_state_close(gfsmState *s)
{
  if (s->arc_data_temp) {
    //-- data=temp, list=temp
    gfsm_arclist_free(s->arcs);
    s->arcs = NULL;
  }
#if 0 //-- only sensible for GSList arclists
  else if (s->arc_list_temp) {
    //-- data=shared, list=temp
    g_slist_free(s->arcs);
    s->arcs = NULL;
  }
#endif
  if (s->is_temp) { g_free(s); }
}

/*======================================================================
 * Methods: Accessors
 */

/*--------------------------------------------------------------
 * is_ok()
 */
GFSM_INLINE
gboolean gfsm_state_is_ok(const gfsmState *s)
{ return s && s->is_valid; }


/*--------------------------------------------------------------
 * is_final()
 */
GFSM_INLINE
gboolean gfsm_state_is_final(const gfsmState *s)
{ return s && s->is_final; }

/*--------------------------------------------------------------
 * set_final()
 */
GFSM_INLINE
void gfsm_state_set_final(gfsmState *s, gboolean is_final)
{ s->is_final=is_final; }

/*--------------------------------------------------------------
 * out_degree()
 */
GFSM_INLINE
guint gfsm_state_out_degree(const gfsmState *s)
{
  return gfsm_arclist_length(s->arcs);
}