This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FSA_StateConverter.cpp
158 lines (142 loc) · 4.71 KB
/
FSA_StateConverter.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* @file FSA_StateConverter.cpp
* Contains the implementation of the StateConverter class.
* @author skowelek
*/
#include "FSA_StateConverter.hpp"
using namespace std;
/**
* Standard constructor.
*/
StateConverter::StateConverter()
{
}
/**
* Constructor. Creates a new StateConverter and sets the member stConvertedState to the given State.
* @param p_stState State to set stConvertedState to.
*/
StateConverter::StateConverter(State *p_stState)
{
this->stConvertedState = p_stState;
}
/**
* Constructor. Creates a new StateConverter and sets the members to the given values.
* @param p_stState State to set stConvertedState to.
* @param p_vecReferencedStates to set the referenced states vector to.
*/
StateConverter::StateConverter(State *p_stState, vector<State*> *p_vecReferencedStates)
{
this->stConvertedState = p_stState;
this->vecReferencedStates = *p_vecReferencedStates;
}
/**
* Constructor. Creates a new StateConverter and creates a new State for stConvertedState
* with the given name.
* @param p_szStateName Name for the new stConvertedState.
*/
StateConverter::StateConverter(string p_szStateName)
{
this->stConvertedState = new State(p_szStateName);
}
/**
* Constructor. Creates a new StateConverter and sets the members to the given values.
* @param p_szStateName String to use as name for the new stConvertedState.
* @param p_vecReferencedStates to set the referenced states vector to.
*/
StateConverter::StateConverter(string p_szStateName, vector<State*> *p_vecReferencedStates)
{
this->stConvertedState = new State(p_szStateName);
this->vecReferencedStates = *p_vecReferencedStates;
}
/**
* Sets the referenced states vector of a StateConverter to the given vector.
* @param p_vecReferencedStates to set the referenced states vector to.
*/
void StateConverter::setReferencedStates(vector<State*> *p_vecReferencedStates)
{
this->vecReferencedStates = *p_vecReferencedStates;
}
/**
* Adds a State to the referenced states vector of this StateConverter
* @param p_szReferencedState State to add to the referenced states vector.
*/
void StateConverter::addReferencedState(State *p_szReferencedState)
{
this->vecReferencedStates.push_back(p_szReferencedState);
}
/**
* Removes a State of the referenced states vector of this StateConverter
* @param p_szStateName State to remove of the referenced states vector.
*/
void StateConverter::removeReferencedState(string p_szStateName)
{
for(std::vector<State*>::iterator it = vecReferencedStates.begin(); it != vecReferencedStates.end(); ++it) {
if((*it)->output() == p_szStateName) {
vecReferencedStates.erase(it);
}
}
}
/**
* Clears the referenced states vector of this StateConverter.
*/
void StateConverter::clearReferencedStates()
{
this->vecReferencedStates.clear();
}
/**
* Returns the stConvertedState of this StateConverter.
* @return The stConvertedState of this StateConverter.
*/
State* StateConverter::getConvertedState()
{
return stConvertedState;
}
/**
* Returns the referenced states vector of this StateConverter.
* @return The referenced states vector of this StateConverter.
*/
vector<State*>* StateConverter::getReferencedStates()
{
return &vecReferencedStates;
}
/**
* Checks if the referenced states vector of the given StateConverter equals
* the one of this StateConverter.
* @param p_scStateConverter State to compare with.
* @return True if the referenced states vector of both StateConverters are equal, false if not.
*/
bool StateConverter::equalsReferencedStates(StateConverter *p_scStateConverter)
{
for(std::vector<State*>::iterator itref = p_scStateConverter->vecReferencedStates.begin(); itref != p_scStateConverter->vecReferencedStates.end(); ++itref) {
if(!this->isInStateList(*itref)) {
return false;
}
}
return true;
}
/**
* Checks if the given State is in the referenced states vector of this StateConverter.
* @param p_stState State to check for.
* @return True if the State is in the referenced states vector, false if not.
*/
bool StateConverter::isInStateList(State* p_stState)
{
for(std::vector<State*>::iterator it = vecReferencedStates.begin(); it != vecReferencedStates.end(); ++it) {
if((*it)->output() == p_stState->output()) {
return true;
}
}
return false;
}
/**
* Checks if any of the States in the referenced states vector is final. If it is,
* sets the stConvertedState of this StateConverter to final.
*/
void StateConverter::checkForFinalState()
{
for(std::vector<State*>::iterator it = vecReferencedStates.begin(); it != vecReferencedStates.end(); ++it) {
if((*it)->isFinalState()) {
stConvertedState->setFinalState(true);
}
}
}