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_Group.cpp
118 lines (106 loc) · 3.08 KB
/
FSA_Group.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
/**
* @file FSA_Group.cpp
* Contains the implementation of the Group class.
*/
#include "FSA_Group.hpp"
using namespace std;
/**
* Standard constructor. Gets the edges of the automaton and saves them to the automata edges vector.
* @param p_fsaAutomata A reference to the automata this group belongs to.
* @author skowelek, fabiani
*/
Group::Group(FiniteStateAutomaton* p_fsaAutomata)
{
fsaAutomata = p_fsaAutomata;
vecAutomataEdges = fsaAutomata->getEdgesFromTransitionList();
}
/**
* Constructor. Gets the edges of the automaton, saves them to the automata edges vector
* and sets the name of the group to the given name.
* @param p_fsaAutomata A reference to the automata this group belongs to.
* @param p_szName Name for this group.
* @author skowelek, fabiani
*/
Group::Group(FiniteStateAutomaton* p_fsaAutomata, string p_szName)
{
fsaAutomata = p_fsaAutomata;
vecAutomataEdges = fsaAutomata->getEdgesFromTransitionList();
szName = p_szName;
}
/**
* Adds a group element to the elements vector.
* @param p_geElement Group element to add to the vector.
* @author skowelek, fabiani
*/
void Group::addElementToGroup(GroupElement* p_geElement)
{
vecElements.push_back(p_geElement);
}
/**
* Removes a group element from the elements vector.
* @param p_geElement Group element to remove from the vector.
* @author skowelek, fabiani
*/
void Group::removeElementFromGroup(GroupElement* p_geElement)
{
for(std::vector<GroupElement*>::iterator it = vecElements.begin(); it != vecElements.end(); ++it) {
if((*it)->getState()->output() == p_geElement->getState()->output()) {
vecElements.erase(it);
break;
}
}
}
/**
* Returns the name of this group.
* @return The name of this group.
* @author skowelek, fabiani
*/
string Group::getName()
{
return szName;
}
/**
* Sets the name of this group.
* @param p_szName The name of this group.
* @author skowelek, fabiani
*/
void Group::setName(string p_szName)
{
szName = p_szName;
}
/**
* Compares two group elements by their target groups.
* @param p_geElementA First element of the comparison.
* @param p_geElementB Second element of the comparison.
* @return True if the elements have the same target groups (in same order), false if not
* @author skowelek, fabiani
*/
bool Group::compareElements(GroupElement* p_geElementA, GroupElement* p_geElementB)
{
for(unsigned int idx = 0; idx < vecAutomataEdges.size() ; idx++) {
string szGroupA = p_geElementA->getTargetGroups()->at(idx);
string szGroupB = p_geElementB->getTargetGroups()->at(idx);
if(szGroupA != szGroupB) {
return false;
}
}
return true;
}
/**
* Returns the elements vector of this group.
* @return The elements vector of this group.
* @author skowelek, fabiani
*/
vector<GroupElement*>* Group::getElements()
{
return &vecElements;
}
/**
* Returns the automata edges vector of this group.
* @return The automata edges vector of this group.
* @author skowelek, fabiani
*/
vector<string>* Group::getEdges()
{
return &vecAutomataEdges;
}