Skip to content

Commit 9872ebc

Browse files
committed
bugfix, don't use unitialized type attribute of ports
1 parent f26c378 commit 9872ebc

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

include/reactor-cpp/port.hh

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class BasePort : public ReactorElement {
2929

3030
protected:
3131
BasePort(const std::string& name, PortType type, Reactor* container)
32-
: ReactorElement(name, ReactorElement::Type::Port, container)
32+
: ReactorElement(name,
33+
type == PortType::Input ? ReactorElement::Type::Input
34+
: ReactorElement::Type::Output,
35+
container)
3336
, type(type) {}
3437

3538
void base_bind_to(BasePort* port);
@@ -89,7 +92,6 @@ class Port : public BasePort {
8992

9093
const ImmutableValuePtr<T>& get() const;
9194
bool is_present() const;
92-
9395
};
9496

9597
template <>

include/reactor-cpp/reactor.hh

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace reactor {
1919

2020
class ReactorElement {
2121
public:
22-
enum class Type { Action, Port, Reaction, Reactor };
22+
enum class Type { Action, Input, Output, Reaction, Reactor };
2323

2424
private:
2525
const std::string _name;
@@ -62,7 +62,8 @@ class Reactor : public ReactorElement {
6262
std::set<Reactor*> _reactors;
6363

6464
void register_action(BaseAction* action);
65-
void register_port(BasePort* port);
65+
void register_input(BasePort* port);
66+
void register_output(BasePort* port);
6667
void register_reaction(Reaction* reaction);
6768
void register_reactor(Reactor* reactor);
6869

lib/reactor.cc

+23-15
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ ReactorElement::ReactorElement(const std::string& name,
3737
case Type::Action:
3838
container->register_action(reinterpret_cast<BaseAction*>(this));
3939
break;
40-
case Type::Port:
41-
container->register_port(reinterpret_cast<BasePort*>(this));
40+
case Type::Input:
41+
container->register_input(reinterpret_cast<BasePort*>(this));
42+
break;
43+
case Type::Output:
44+
container->register_output(reinterpret_cast<BasePort*>(this));
4245
break;
4346
case Type::Reaction:
4447
container->register_reaction(reinterpret_cast<Reaction*>(this));
@@ -73,29 +76,34 @@ Reactor::Reactor(const std::string& name, Environment* environment)
7376
environment->register_reactor(this);
7477
}
7578

76-
void Reactor::register_action([[maybe_unused]]BaseAction* action) {
79+
void Reactor::register_action([[maybe_unused]] BaseAction* action) {
7780
toggle_assert(action != nullptr);
78-
reactor::validate(this->environment()->phase() == Environment::Phase::Construction,
79-
"Actions can only be registered during construction phase!");
81+
reactor::validate(
82+
this->environment()->phase() == Environment::Phase::Construction,
83+
"Actions can only be registered during construction phase!");
8084
toggle_assert(_actions.insert(action).second);
8185
}
82-
void Reactor::register_port(BasePort* port) {
86+
void Reactor::register_input(BasePort* port) {
8387
toggle_assert(port != nullptr);
84-
reactor::validate(this->environment()->phase() == Environment::Phase::Construction,
85-
"Ports can only be registered during construction phase!");
86-
if (port->is_input()) {
87-
toggle_assert(_inputs.insert(port).second);
88-
} else {
89-
toggle_assert(_outputs.insert(port).second);
90-
}
88+
reactor::validate(
89+
this->environment()->phase() == Environment::Phase::Construction,
90+
"Ports can only be registered during construction phase!");
91+
toggle_assert(_inputs.insert(port).second);
92+
}
93+
void Reactor::register_output(BasePort* port) {
94+
toggle_assert(port != nullptr);
95+
reactor::validate(
96+
this->environment()->phase() == Environment::Phase::Construction,
97+
"Ports can only be registered during construction phase!");
98+
toggle_assert(_outputs.insert(port).second);
9199
}
92-
void Reactor::register_reaction([[maybe_unused]]Reaction* reaction) {
100+
void Reactor::register_reaction([[maybe_unused]] Reaction* reaction) {
93101
toggle_assert(reaction != nullptr);
94102
validate(this->environment()->phase() == Environment::Phase::Construction,
95103
"Reactions can only be registered during construction phase!");
96104
toggle_assert(_reactions.insert(reaction).second);
97105
}
98-
void Reactor::register_reactor([[maybe_unused]]Reactor* reactor) {
106+
void Reactor::register_reactor([[maybe_unused]] Reactor* reactor) {
99107
toggle_assert(reactor != nullptr);
100108
validate(this->environment()->phase() == Environment::Phase::Construction,
101109
"Reactions can only be registered during construction phase!");

0 commit comments

Comments
 (0)