OpenASIP 2.2
Loading...
Searching...
No Matches
FiniteStateAutomaton.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file FiniteStateAutomaton.hh
26 *
27 * Declaration of FiniteStateAutomaton class.
28 *
29 * @author Pekka Jääskeläinen 2006 (pekka.jaaskelainen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#ifndef TTA_FINITE_STATE_AUTOMATON_HH
34#define TTA_FINITE_STATE_AUTOMATON_HH
35
36#include <string>
37#include <set>
38#include <map>
39#include <vector>
40
41#include "Exception.hh"
42
43/**
44 * Generic finite state automaton (FSA).
45 *
46 * This is a generic structure for FSA. The building and initialization of
47 * the states is the responsibility of derived classes.
48 */
50public:
51 /// Friend due to highly optimized compiled simulation versions of
52 /// the conflict detection functions.
54 /// Type used for indexing the transitions.
56 /// Type used for indexing the states.
57 typedef int FSAStateIndex;
58 /// Type for a set of state indices.
59 typedef std::set<FSAStateIndex> FSAStateIndexSet;
60 /// A state id which denotes an illegal state.
61 static const FSAStateIndex ILLEGAL_STATE = -1;
62 /// A state id which denotes an unknown (unresolved) state. Used for
63 /// lazy construction of states.
64 static const FSAStateIndex UNKNOWN_STATE = -2;
65
68 int transitionCount = 0);
69 virtual ~FiniteStateAutomaton();
70
71 virtual const std::string& transitionName(FSAStateTransitionIndex transition)
72 const;
73
74 virtual std::string stateName(FSAStateIndex state) const;
75
77 const std::string& transitionName) const;
78
80 FSAStateIndex source,
81 FSAStateTransitionIndex transition);
82
83 virtual bool isLegalTransition(
84 FSAStateIndex source,
85 FSAStateTransitionIndex transition);
86
87 virtual FSAStateIndex addState();
88
90 const std::string& name);
91
92 virtual void setTransitionName(
93 FSAStateTransitionIndex transition, const std::string& name);
94
95 virtual void setTransition(
96 FSAStateIndex source, FSAStateIndex destination,
97 FSAStateTransitionIndex transition);
98
99 virtual std::string toDotString() const;
100
101 virtual FSAStateIndex startState() const;
102
103
104protected:
105
106 /// Vector which stores the target states of for each transition type.
107 typedef std::vector<FSAStateIndex> TransitionVector;
108
109 /// Type for storing the transitions of each state. The vector
110 /// stores for each state (indexed from 0) a vector with elements as
111 /// many there are transitions. The value of the element is the target
112 /// state to which the transition leads to, or ILLEGAL_STATE_INDEX if
113 /// there is no transition for that transition type from that state.
114 /// Using this structure it's possible to find the target state using two
115 /// table (vector) lookups.
116 typedef std::vector<TransitionVector> TransitionMap;
117
118 /// The state transitions. In protected to allow fast access from
119 /// derived classes.
121
122private:
123
124 /// Type for finding the index for a transition using its name.
125 typedef std::map<std::string, FSAStateTransitionIndex>
127 /// Count of states in the automaton.
129 /// Count of different transition types in the automaton.
131 /// Names of the state transitions types (indexed from 0).
132 std::vector<std::string> transitionNames_;
133 /// Indices of the state transition types.
135 /// The default target state for state transitions.
137};
138
139#endif
virtual void setTransition(FSAStateIndex source, FSAStateIndex destination, FSAStateTransitionIndex transition)
int transitionTypeCount_
Count of different transition types in the automaton.
virtual FSAStateTransitionIndex transitionIndex(const std::string &transitionName) const
const FSAStateTransitionIndex defaultState_
The default target state for state transitions.
TransitionMap transitions_
The state transitions. In protected to allow fast access from derived classes.
virtual void setTransitionName(FSAStateTransitionIndex transition, const std::string &name)
virtual FSAStateTransitionIndex addTransitionType(const std::string &name)
virtual std::string toDotString() const
virtual const std::string & transitionName(FSAStateTransitionIndex transition) const
std::set< FSAStateIndex > FSAStateIndexSet
Type for a set of state indices.
virtual FSAStateIndex startState() const
virtual bool isLegalTransition(FSAStateIndex source, FSAStateTransitionIndex transition)
int FSAStateIndex
Type used for indexing the states.
virtual std::string stateName(FSAStateIndex state) const
TransitionNameIndex transitionIndices_
Indices of the state transition types.
static const FSAStateIndex ILLEGAL_STATE
A state id which denotes an illegal state.
std::map< std::string, FSAStateTransitionIndex > TransitionNameIndex
Type for finding the index for a transition using its name.
static const FSAStateIndex UNKNOWN_STATE
A state id which denotes an unknown (unresolved) state. Used for lazy construction of states.
virtual FSAStateIndex addState()
std::vector< FSAStateIndex > TransitionVector
Vector which stores the target states of for each transition type.
std::vector< TransitionVector > TransitionMap
Type for storing the transitions of each state. The vector stores for each state (indexed from 0) a v...
virtual FSAStateIndex destinationState(FSAStateIndex source, FSAStateTransitionIndex transition)
std::vector< std::string > transitionNames_
Names of the state transitions types (indexed from 0).
int stateCount_
Count of states in the automaton.
int FSAStateTransitionIndex
Type used for indexing the transitions.