@@ -18,40 +18,24 @@ void Output<T>::connect(Output<T>& input) {
1818template <typename T>
1919void Output<T>::connect(MultiportInput<T>& input) {
2020 if (is_accumulated) {
21- auto input_itr = input. begin () ;
22-
23- if (accumulated. size () < input. get_nports ()) {
24- reactor::log::Warn () << " There are more right ports than left ports. "
25- << " Not all ports will be connected! " ;
26- } else if (accumulated. size () > input. get_nports () ) {
27- reactor::log::Warn () << " There are more left ports than right ports. "
28- << " Not all ports will be connected! " ;
21+ std::set<reactor::Port<T>*> left_ports ;
22+ std::set<reactor::Port<T>*> right_ports;
23+ bool result = false ;
24+ result = left_ports. insert ( this ). second ;
25+ reactor_assert (result) ;
26+ for ( auto *l_port : accumulated ) {
27+ result = left_ports. insert (l_port). second ;
28+ reactor_assert (result) ;
2929 }
3030
31- this ->environment ()->draw_connection (*this , *input_itr, reactor::ConnectionProperties{});
32- ++input_itr;
33-
34- for (auto *l_port : accumulated) {
35- if (input_itr != input.end ()) {
36- break ;
37- }
38- this ->environment ()->draw_connection (*l_port, *input_itr, reactor::ConnectionProperties{});
39- ++input_itr;
31+ for (auto & right_port : input) {
32+ result = right_ports.insert (&right_port).second ;
33+ reactor_assert (result);
4034 }
35+ connect_ (left_ports, right_ports, reactor::ConnectionProperties{});
4136 is_accumulated = false ;
4237 accumulated.clear ();
4338 } else {
44- // auto input_itr = input.begin();
45-
46- // if (1 < input.get_nports()) {
47- // reactor::log::Warn() << "There are more right ports than left ports. "
48- // << "Not all ports will be connected!";
49- // }
50-
51- // if (input_itr != input.end())
52- // {
53- // this->environment()->draw_connection(*this, *input_itr, reactor::ConnectionProperties{});
54- // }
5539 std::set<reactor::Port<T>*> left_ports;
5640 std::set<reactor::Port<T>*> right_ports;
5741 bool result = left_ports.insert (this ).second ;
@@ -67,41 +51,24 @@ void Output<T>::connect(MultiportInput<T>& input) {
6751template <typename T>
6852void Output<T>::connect_fanout(MultiportInput<T>& input) {
6953 if (is_accumulated) {
70- auto input_itr = input. begin () ;
71-
72- if (accumulated. size () < input. get_nports ()) {
73- reactor::log::Warn () << " There are more right ports than left ports. "
74- << " Not all ports will be connected! " ;
75- } else if (accumulated. size () > input. get_nports () ) {
76- reactor::log::Warn () << " There are more left ports than right ports. "
77- << " Not all ports will be connected! " ;
54+ std::set<reactor::Port<T>*> left_ports ;
55+ std::set<reactor::Port<T>*> right_ports;
56+ bool result = false ;
57+ result = left_ports. insert ( this ). second ;
58+ reactor_assert (result) ;
59+ for ( auto *l_port : accumulated ) {
60+ result = left_ports. insert (l_port). second ;
61+ reactor_assert (result) ;
7862 }
7963
80- this ->environment ()->draw_connection (*this , *input_itr, reactor::ConnectionProperties{});
81- ++input_itr;
82-
83- for (auto *l_port : accumulated) {
84- if (input_itr != input.end ()) {
85- break ;
86- }
87- this ->environment ()->draw_connection (*l_port, *input_itr, reactor::ConnectionProperties{});
88- ++input_itr;
64+ for (auto & right_port : input) {
65+ result = right_ports.insert (&right_port).second ;
66+ reactor_assert (result);
8967 }
68+ connect_ (left_ports, right_ports, reactor::ConnectionProperties{});
9069 is_accumulated = false ;
9170 accumulated.clear ();
9271 } else {
93- // auto input_itr = input.begin();
94-
95- // if (1 < input.get_nports()) {
96- // reactor::log::Warn() << "Fanning out input to all right output ports";
97- // }
98-
99- // while (input_itr != input.end())
100- // {
101- // this->environment()->draw_connection(*this, *input_itr, reactor::ConnectionProperties{});
102- // ++input_itr;
103- // }
104-
10572 std::set<reactor::Port<T>*> left_ports;
10673 std::set<reactor::Port<T>*> right_ports;
10774 bool result = left_ports.insert (this ).second ;
@@ -139,23 +106,42 @@ void Output<T>::connect(ReactorBankInputPort<ReactorType, T> &&other_bank_ports)
139106 for (auto &p_reactor : other_bank_ports) {
140107 auto *reactor = p_reactor.get ();
141108 this ->environment ()->draw_connection (*this , reactor->*(other_bank_ports.get_member ()), reactor::ConnectionProperties{});
109+ break ;
142110 }
143111}
144112
145113template <typename T>
146114template <typename ReactorType>
147115void Output<T>::connect(ReactorBankInputPortOffset<ReactorType, T> &&other_bank_ports) {
148-
149- if (1 < other_bank_ports.size ()) {
150- reactor::log::Warn () << " There are more right ports than left ports. "
151- << " Not all ports will be connected!" ;
116+ std::set<reactor::Port<T>*> left_ports;
117+ std::set<reactor::Port<T>*> right_ports;
118+ bool result = left_ports.insert (this ).second ;
119+ reactor_assert (result);
120+ for (auto &p_reactor : other_bank_ports) {
121+ auto *reactor = p_reactor.get ();
122+ char * reactor_base = reinterpret_cast <char *>(reactor);
123+ Input<T>* port = reinterpret_cast <Input<T>*>(reactor_base + other_bank_ports.get_offset ());
124+ result = right_ports.insert (port).second ;
125+ reactor_assert (result);
152126 }
127+ connect_ (left_ports, right_ports, reactor::ConnectionProperties{});
128+ }
129+
130+ template <typename T>
131+ template <typename ReactorType>
132+ void Output<T>::connect_fanout(ReactorBankInputPortOffset<ReactorType, T> &&other_bank_ports) {
133+ std::set<reactor::Port<T>*> left_ports;
134+ std::set<reactor::Port<T>*> right_ports;
135+ bool result = left_ports.insert (this ).second ;
136+ reactor_assert (result);
153137 for (auto &p_reactor : other_bank_ports) {
154138 auto *reactor = p_reactor.get ();
155139 char * reactor_base = reinterpret_cast <char *>(reactor);
156140 Input<T>* port = reinterpret_cast <Input<T>*>(reactor_base + other_bank_ports.get_offset ());
157- this ->environment ()->draw_connection (*this , *port, reactor::ConnectionProperties{});
141+ result = right_ports.insert (port).second ;
142+ reactor_assert (result);
158143 }
144+ connect_fanout_ (left_ports, right_ports, reactor::ConnectionProperties{});
159145}
160146
161147} // namespace sdk
0 commit comments