This repository was archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport.cpp
More file actions
110 lines (88 loc) · 1.75 KB
/
Copy pathport.cpp
File metadata and controls
110 lines (88 loc) · 1.75 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
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
#include "port.h"
InputPort::InputPort() : otherPort(nullptr) {}
InputPort::~InputPort() {
if (otherPort) {
otherPort->disconnect();
}
}
bool InputPort::ready() const
{
return otherPort && otherPort->valid();
}
const Item *InputPort::receive() {
if (otherPort && otherPort->valid()) {
return otherPort->transmit();
} else {
return nullptr;
}
}
void InputPort::connect(Port *o) {
if (o == otherPort)
return;
if (otherPort) {
otherPort->disconnect();
}
otherPort = dynamic_cast<OutputPort *>(o);
}
void InputPort::disconnect() { otherPort = nullptr; }
OutputPort::OutputPort() : otherPort(nullptr), buffer(nullptr) {}
OutputPort::~OutputPort() {
if (buffer) {
delete buffer;
}
if (otherPort) {
otherPort->disconnect();
}
}
bool OutputPort::send(const Item *item) {
if (!item) {
return false;
}
if (buffer) {
return false;
}
buffer = item;
return true;
}
bool OutputPort::ready() const
{
return buffer == nullptr;
}
const Item *OutputPort::getBuffer()
{
return buffer;
}
bool OutputPort::valid() const
{
return buffer != nullptr;
}
const Item *OutputPort::transmit() {
const Item *ret = buffer;
buffer = nullptr;
return ret;
}
void OutputPort::connect(Port *o) {
if (otherPort) {
otherPort->disconnect();
}
otherPort = dynamic_cast<InputPort *>(o);
}
void OutputPort::disconnect() { otherPort = nullptr; }
Port::~Port() {}
PortHint::PortHint(const std::array<Port *, 4> &otherPorts)
: otherPorts(otherPorts)
{
}
PortHint::PortHint(const PortHint &o)
: otherPorts(o.otherPorts)
{
}
const PortHint &PortHint::operator=(const PortHint &o)
{
otherPorts = o.otherPorts;
return *this;
}
Port *PortHint::operator[](rotate_t direction) const
{
return otherPorts[direction];
}