-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv_in.hpp
97 lines (88 loc) · 2.08 KB
/
conv_in.hpp
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
#ifndef CONV_IN_HPP
#define CONV_IN_HPP
#include "pml_mo.hpp"
#include <string.h>
#include <stdlib.h>
class conv_in:
public pmlMos
{
std::string conveyor;
bool out_box_;
int conv_size_;
public:
conv_in(pmlState _st=ABORTED, int _conv_size=20)
{
conv_size_ = _conv_size;
conveyor.resize(conv_size_);
memset(&conveyor[0], '_', conv_size_-1);
conveyor[conv_size_] = '\0';
st_ = _st;
out_box_ = false;
};
char ** print(char** floor, int nrows, int ncols)
{
if(nrows > 0)
strncpy(*floor, conveyor.c_str(), ncols);
return floor;
};
bool out_box() {return out_box_;};
void spin( char next_box = '_')
{
switch(st_)
{
case ABORTING:
st_ = ABORTED;
break;
case CLEARING:
case STOPPING:
st_ = STOPPED;
break;
case RESETTING:
st_ = IDLE;
break;
case STARTING:
case UNSUSPENDING:
case UNHOLDING:
st_ = EXECUTE;
break;
case SUSPENDING:
st_ = SUSPENDED;
break;
case HOLDING:
st_ = HELD;
break;
case COMPLETING:
st_ = COMPLETE;
break;
case SUSPENDED:
if(next_box == 'x')
{
conveyor.insert(0, "x");
conveyor.resize(conv_size_);
this->sendCommand(UNSUSPEND);
}
break;
case EXECUTE:
if(conveyor[conveyor.length()-1] == 'x')
out_box_ = true;
else
out_box_ = false;
conveyor.insert(0, "_");
conveyor[0] = next_box;
conveyor.resize(conv_size_);
bool theres_something = false;
for( int pos=0; pos < conveyor.length(); ++pos)
{
if(conveyor[pos]=='x')
{
theres_something = true;
break;
}
}
if(!theres_something)
this->sendCommand(SUSPEND);
break;
}
};
};
#endif /* ifndef CONV_IN_HPP */