-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateMachine.cpp
More file actions
54 lines (48 loc) · 1.49 KB
/
Copy pathStateMachine.cpp
File metadata and controls
54 lines (48 loc) · 1.49 KB
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
#include "StateMachine.h"
template <typename SignalType, typename ContentType>
StateMachine<SignalType, ContentType>::StateMachine(ContentType StartNode)
{
CurrentNode_=StateNode<SignalType, ContentType>(StartNode);
Nodes_.push_back(&CurrentNode_);
}
template <typename SignalType, typename ContentType>
void StateMachine<SignalType, ContentType>::AddNode(ContentType Content)
{
if (FindNode(Content) == nullptr)
{
Nodes_.push_back(new StateNode<SignalType, ContentType>(Content));
}
}
template <typename SignalType, typename ContentType>
void StateMachine<SignalType, ContentType>::AddConnection(ContentType FromNode, ContentType ToNode, SignalType Signal)
{
auto From = FindNode(FromNode);
auto To = FindNode(ToNode);
if((From!=nullptr)&&(To!=nullptr))
{
From->AddConnection(std::pair<SignalType, StateNode<SignalType, ContentType>>(Signal, *To));
}
}
template <typename SignalType, typename ContentType>
StateNode<SignalType, ContentType>* StateMachine<SignalType, ContentType>::FindNode(ContentType Content)
{
for (auto& Node : Nodes_)
{
if (Node->Content == Content)
{
return Node;
}
}
return nullptr;
}
template <typename SignalType, typename ContentType>
ContentType StateMachine<SignalType, ContentType>::GetNextNode(SignalType Signal)
{
CurrentNode_ = CurrentNode_.GetNextNode(Signal);
return CurrentNode_.Content;
}
template <typename SignalType, typename ContentType>
ContentType StateMachine<SignalType, ContentType>::GetCurrentNodeContent()
{
return CurrentNode_.Content;
}