Skip to content

Commit 894393f

Browse files
committed
code cleaning
1 parent 9e1b6ed commit 894393f

File tree

21 files changed

+178
-168
lines changed

21 files changed

+178
-168
lines changed

examples/count/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
using namespace reactor;
66
using namespace std::chrono_literals;
77

8-
class Count : public Reactor {
8+
class Count final : public Reactor {
99
private:
1010
// actions
1111
Timer timer{"timer", this};
1212
LogicalAction<int> counter{"counter", this};
1313

1414
// reactions_
15-
Reaction r_init{"r_init", 1, false, this, [this]() { this->init(); }};
16-
Reaction r_counter{"r_counter", 2, false, this, [this]() { this->print_count(); }};
15+
Reaction r_init{"r_init", 1, this, [this]() { this->init(); }};
16+
Reaction r_counter{"r_counter", 2, this, [this]() { this->print_count(); }};
1717

1818
public:
1919
explicit Count(Environment* env)

examples/hello/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using namespace reactor;
77
using namespace std::chrono_literals;
88

9-
class Hello : public Reactor {
9+
class Hello final : public Reactor {
1010
private:
1111
// actions
1212
Timer timer{"timer", this, 1s, 2s};

examples/multiport_mutation/consumer.hh

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,35 @@ using namespace reactor;
1111
using namespace std::chrono_literals;
1212

1313
class Consumer : public Reactor {
14-
private:
15-
class Inner: public Scope {
16-
Inner(Reactor* reactor, std::size_t index) : Scope(reactor), index_(index) {}
17-
std::size_t index_;
14+
class Inner : public Scope {
15+
Inner(Reactor* reactor, std::size_t index)
16+
: Scope(reactor)
17+
, index_(index) {}
18+
std::size_t index_ = 0;
1819

19-
[[maybe_unused]] const Inner& __lf_inner = *this;
20+
const Inner& _lf_inner = *this;
2021

21-
void reaction_1([[maybe_unused]] const Input<unsigned>& in) {
22-
std::cout << "consumer: " << index_ << " received value:" << *in.get() << std::endl;
22+
void reaction_1(const Input<unsigned>& in) const {
23+
std::cout << "consumer: " << index_ << " received value:" << *in.get() << '\n';
2324
}
2425

2526
friend Consumer;
2627
};
2728

28-
Inner __lf_inner;
29-
Reaction handle{"handle", 1, this, [this]() { __lf_inner.reaction_1(this->in); }};
29+
Inner _lf_inner;
30+
Reaction handle{"handle", 1, this, [this]() { _lf_inner.reaction_1(this->in); }};
31+
3032
public:
31-
Consumer(const std::string& name, Environment* env, std::size_t index) : Reactor(name, env), __lf_inner(this, index) {
32-
std::cout << "creating instance of consumer" << std::endl;
33+
Consumer(const std::string& name, Environment* env, std::size_t index)
34+
: Reactor(name, env)
35+
, _lf_inner(this, index) {
36+
std::cout << "creating instance of consumer" << '\n';
3337
}
34-
~Consumer() override {
35-
std::cout << "Consumer Object is deleted" << std::endl;
36-
};
38+
~Consumer() override { std::cout << "Consumer Object is deleted" << '\n'; };
3739

3840
Input<unsigned> in{"in", this};
3941

40-
void assemble() override {
41-
handle.declare_trigger(&in);
42-
}
42+
void assemble() override { handle.declare_trigger(&in); }
4343
};
4444

45-
46-
#endif //CONSUMER_HH
45+
#endif // CONSUMER_HH

examples/multiport_mutation/load_balancer.hh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ using namespace std::chrono_literals;
1515

1616
class LoadBalancer : public Reactor {
1717
private:
18-
class Inner: public MutableScope {
19-
Inner(Reactor* reactor) : MutableScope(reactor) {}
20-
[[maybe_unused]] const Inner& __lf_inner = *this;
18+
class Inner : public MutableScope {
19+
Inner(Reactor* reactor)
20+
: MutableScope(reactor) {}
21+
const Inner& __lf_inner = *this;
2122

2223
// reaction bodies
23-
void reaction_1(const Input<unsigned>& inbound, LogicalAction<unsigned>& scale_action, Multiport<Output<unsigned>>& outbound) {
24+
void reaction_1(const Input<unsigned>& inbound, LogicalAction<unsigned>& scale_action,
25+
Multiport<Output<unsigned>>& outbound) {
2426
if (rand() % 30 == 0) {
2527
scale_action.schedule(rand() % 20 + 1);
2628
}
@@ -29,13 +31,15 @@ private:
2931
outbound[sel].set(inbound.get());
3032
}
3133

32-
void reaction_2(ModifableMultiport<Output<unsigned>>&outbound, [[maybe_unused]] const LogicalAction<unsigned>& scale, Output<unsigned>& scale_bank) {
34+
void reaction_2(ModifableMultiport<Output<unsigned>>& outbound,
35+
[[maybe_unused]] const LogicalAction<unsigned>& scale, Output<unsigned>& scale_bank) {
3336
ModifableMultiport<Output<unsigned>>* temp = &outbound;
3437
std::size_t new_size = *scale.get();
3538

3639
auto antideps = (outbound[0]).anti_dependencies();
3740

38-
auto change_size = std::make_shared<MutationChangeOutputMultiportSize<unsigned>>(temp, this->reactor_, antideps, new_size);
41+
auto change_size =
42+
std::make_shared<MutationChangeOutputMultiportSize<unsigned>>(temp, this->reactor_, antideps, new_size);
3943

4044
add_to_transaction(change_size);
4145

@@ -48,16 +52,19 @@ private:
4852
};
4953

5054
Inner __lf_inner;
51-
Reaction process{"process", 2, this, [this]() { __lf_inner.reaction_1(this->inbound, this->scale_action, this->out); }};
52-
Reaction scale{"scale", 1, this, [this]() { __lf_inner.reaction_2(this->out, this->scale_action, this->scale_bank); }};
55+
Reaction process{"process", 2, this,
56+
[this]() { __lf_inner.reaction_1(this->inbound, this->scale_action, this->out); }};
57+
Reaction scale{"scale", 1, this,
58+
[this]() { __lf_inner.reaction_2(this->out, this->scale_action, this->scale_bank); }};
5359

5460
public:
5561
LoadBalancer(const std::string& name, Environment* env)
56-
: Reactor(name, env), __lf_inner(this) {
62+
: Reactor(name, env)
63+
, __lf_inner(this) {
5764
std::cout << "creating instance of load balancer" << std::endl;
5865
out.reserve(4);
5966
for (size_t _lf_idx = 0; _lf_idx < 4; _lf_idx++) {
60-
std::string _lf_port_name = out.name() + "_" + std::to_string(_lf_idx);
67+
std::string _lf_port_name = out.name() + "_" + std::to_string(_lf_idx);
6168
out.emplace_back(_lf_port_name, this);
6269
}
6370
}
@@ -78,6 +85,4 @@ public:
7885
}
7986
};
8087

81-
82-
83-
#endif //LOAD_BALANCER_HH
88+
#endif // LOAD_BALANCER_HH

examples/multiport_mutation/main.cc

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,89 @@
33
#include <reactor-cpp/mutations/bank.hh>
44
#include <reactor-cpp/mutations/connection.hh>
55

6+
#include "../../lib/mutation/bank.cc"
7+
#include "../../lib/mutation/connection.cc"
68
#include "./consumer.hh"
79
#include "./load_balancer.hh"
810
#include "./producer.hh"
9-
#include "../../lib/mutation/bank.cc"
10-
#include "../../lib/mutation/connection.cc"
1111
#include <reactor-cpp/reactor-cpp.hh>
1212

13-
class Deployment : public Reactor {
13+
class Deployment final : public Reactor {
1414
std::unique_ptr<Producer> producer_;
1515
std::unique_ptr<LoadBalancer> load_balancer_;
1616
std::vector<std::unique_ptr<Consumer>> consumers_;
1717

18-
Reaction scale_bank{"scale_bank", 1, this, [this](){this->__inner.reaction_1(this->scale, this->consumers_, load_balancer_->out);}};
18+
Reaction scale_bank{"scale_bank", 1, this,
19+
[this]() { this->__inner.reaction_1(this->scale, this->consumers_, load_balancer_->out); }};
1920

2021
public:
21-
22-
class Inner: public MutableScope {
22+
class Inner : public MutableScope {
2323
int state = 0;
24-
[[maybe_unused]] const Inner& __lf_inner = *this;
25-
public:
24+
const Inner& _lf_inner = *this;
2625

27-
Inner(Reactor* reactor) : MutableScope(reactor) {}
28-
void reaction_1(const Input<unsigned>& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank, ModifableMultiport<Output<unsigned>>& load_balancer) {
26+
public:
27+
Inner(Reactor* reactor)
28+
: MutableScope(reactor) {}
29+
void reaction_1(const Input<unsigned>& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank,
30+
ModifableMultiport<Output<unsigned>>& load_balancer) {
2931
std::size_t new_size = *scale.get();
3032
std::size_t old_size = reactor_bank.size();
3133

32-
std::function<std::unique_ptr<Consumer>(Reactor*, std::size_t)> lambda = [](Reactor* reactor, std::size_t index) {
33-
std::string __lf_inst_name = "consumer_" + std::to_string(index);
34-
return std::make_unique<Consumer>(__lf_inst_name, reactor->environment(), index);
34+
std::function lambda = [](Reactor* reactor, std::size_t index) {
35+
std::string _lf_inst_name = "consumer_" + std::to_string(index);
36+
return std::make_unique<Consumer>(_lf_inst_name, reactor->environment(), index);
3537
};
36-
auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(&reactor_bank, this->reactor_, new_size, lambda);
38+
39+
auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(
40+
&reactor_bank, this->reactor_, new_size, lambda);
3741

3842
add_to_transaction(change_size);
3943

40-
// old topology
4144
commit_transaction();
42-
// new topology
43-
44-
if (old_size > new_size) {
4545

46-
for (auto i = 0; i < old_size - new_size; i++) {
47-
}
48-
} else {
49-
std::cout << "load_balancer size:" << load_balancer.size() << " bank size: " << reactor_bank.size() << std::endl;
46+
if (old_size < new_size) {
5047
for (auto i = 0; i < new_size; i++) {
51-
auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned>, Input<unsigned>>>(&load_balancer[i], &reactor_bank[i].get()->in, reactor_);
52-
add_to_transaction(add_conn);
48+
auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned>, Input<unsigned>>>(
49+
&load_balancer[i], &reactor_bank[i].get()->in, reactor_);
50+
add_to_transaction(add_conn);
5351
}
54-
commit_transaction(true);
5552
}
5653

57-
std::cout << "new bank size:" << reactor_bank.size() << std::endl;
54+
commit_transaction(true);
5855
}
5956

6057
friend LoadBalancer;
6158
};
6259

6360
Inner __inner;
6461

65-
Deployment(const std::string& name, Environment* env) : Reactor(name, env), __inner(this),
66-
producer_(std::make_unique<Producer>("producer", environment())),
67-
load_balancer_(std::make_unique<LoadBalancer>("load_balancer", environment())) {
68-
std::cout << "creating instance of deployment" << std::endl;
62+
Deployment(const std::string& name, Environment* env)
63+
: Reactor(name, env)
64+
, __inner(this)
65+
, producer_(std::make_unique<Producer>("producer", environment()))
66+
, load_balancer_(std::make_unique<LoadBalancer>("load_balancer", environment())) {
67+
std::cout << "creating instance of deployment" << '\n';
6968
consumers_.reserve(4);
70-
for (size_t __lf_idx = 0; __lf_idx < 4; __lf_idx++) {
71-
std::string __lf_inst_name = "consumer_" + std::to_string(__lf_idx);
72-
consumers_.push_back(std::make_unique<Consumer>(__lf_inst_name, environment(), __lf_idx));
69+
for (size_t _lf_idx = 0; _lf_idx < 4; _lf_idx++) {
70+
std::string _lf_inst_name = "consumer_" + std::to_string(_lf_idx);
71+
consumers_.push_back(std::make_unique<Consumer>(_lf_inst_name, environment(), _lf_idx));
7372
}
7473
}
7574
~Deployment() override = default;
7675

7776
Input<unsigned> scale{"scale", this};
7877

7978
void assemble() override {
80-
for (size_t __lf_idx = 0; __lf_idx < 4; __lf_idx++) {
81-
environment()->draw_connection(load_balancer_->out[__lf_idx], consumers_[__lf_idx]->in, ConnectionProperties{});
79+
for (size_t _lf_idx = 0; _lf_idx < 4; _lf_idx++) {
80+
environment()->draw_connection(load_balancer_->out[_lf_idx], consumers_[_lf_idx]->in, ConnectionProperties{});
8281
environment()->draw_connection(producer_->value, load_balancer_->inbound, ConnectionProperties{});
8382
}
8483
environment()->draw_connection(load_balancer_->scale_bank, scale, ConnectionProperties{});
8584
scale_bank.declare_trigger(&this->scale);
8685
}
8786
};
8887

89-
9088
auto main() -> int {
91-
//srand(time(nullptr));
9289
Environment env{4, true};
9390
auto deployment = std::make_unique<Deployment>("c1", &env);
9491
env.optimize();

examples/multiport_mutation/producer.hh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,29 @@ using namespace std::chrono_literals;
1313
class Producer : public Reactor {
1414
private:
1515
Timer timer{"timer", this, 1s, 1s};
16-
Reaction r_timer{"r_timer", 1, this, [this]() { __lf_inner.reaction_1(this->value);}};
16+
Reaction r_timer{"r_timer", 1, this, [this]() { __lf_inner.reaction_1(this->value); }};
17+
18+
class Inner : public Scope {
19+
unsigned int counter_ = 0;
20+
const Inner& __lf_inner = *this;
1721

18-
class Inner: public Scope {
19-
unsigned itr = 0;
20-
[[maybe_unused]] const Inner& __lf_inner = *this;
2122
void reaction_1([[maybe_unused]] Output<unsigned>& out) {
22-
std::cout << "producing value:" << itr << std::endl;
23-
out.set(itr++);
23+
std::cout << "producing value:" << counter_ << std::endl;
24+
out.set(counter_++);
2425
}
25-
explicit Inner(Reactor* reactor) : Scope(reactor) {}
26+
27+
explicit Inner(Reactor* reactor)
28+
: Scope(reactor) {}
2629

2730
friend Producer;
2831
};
2932

3033
Inner __lf_inner;
34+
3135
public:
32-
Producer(const std::string& name, Environment* env) : Reactor(name, env), __lf_inner(this) {
36+
Producer(const std::string& name, Environment* env)
37+
: Reactor(name, env)
38+
, __lf_inner(this) {
3339
std::cout << "creating instance of producer" << std::endl;
3440
}
3541
Producer() = delete;
@@ -43,4 +49,4 @@ public:
4349
}
4450
};
4551

46-
#endif //PRODUCER_HH
52+
#endif // PRODUCER_HH

examples/ports/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace reactor;
66
using namespace std::chrono_literals;
77

8-
class Trigger : public Reactor {
8+
class Trigger final : public Reactor {
99
private:
1010
Timer timer;
1111
Reaction r_timer{"r_timer", 1, this, [this]() { on_timer(); }};
@@ -25,7 +25,7 @@ class Trigger : public Reactor {
2525
void on_timer() { trigger.set(); }
2626
};
2727

28-
class Counter : public Reactor {
28+
class Counter final : public Reactor {
2929
private:
3030
int value_{0};
3131
Reaction r_trigger{"r_trigger", 1, this, [this]() { on_trigger(); }};
@@ -49,7 +49,7 @@ class Counter : public Reactor {
4949
}
5050
};
5151

52-
class Printer : public Reactor {
52+
class Printer final : public Reactor {
5353
private:
5454
Reaction r_value{"r_value", 1, this, [this]() { this->on_value(); }};
5555

@@ -67,7 +67,7 @@ class Printer : public Reactor {
6767
void on_value() { std::cout << this->name() << ": " << *value.get() << '\n'; }
6868
};
6969

70-
class Adder : public Reactor {
70+
class Adder final : public Reactor {
7171
private:
7272
Reaction r_add{"r_add", 1, this, [this]() { this->add(); }};
7373

0 commit comments

Comments
 (0)