1010#define REACTOR_CPP_IMPL_PORT_IMPL_HH
1111
1212#include " reactor-cpp/assert.hh"
13- #include " reactor-cpp/connection.hh"
1413#include " reactor-cpp/environment.hh"
1514#include " reactor-cpp/port.hh"
15+ #include " reactor-cpp/reactor.hh"
1616
1717namespace reactor {
1818
@@ -56,8 +56,9 @@ template <class T> auto Port<T>::get() const noexcept -> const ImmutableValuePtr
5656 return value_ptr_;
5757}
5858template <class T >
59- void Port<T>::pull_connection(const ConnectionProperties& properties, const std::vector<BasePort*>& downstream) {
60- Connection<T>* connection = nullptr ;
59+ void Port<T>::instantiate_connection_to(const ConnectionProperties& properties,
60+ const std::vector<BasePort*>& downstream) {
61+ std::unique_ptr<Connection<T>> connection = nullptr ;
6162 if (downstream.empty ()) {
6263 return ;
6364 }
@@ -69,27 +70,31 @@ void Port<T>::pull_connection(const ConnectionProperties& properties, const std:
6970 auto index = this ->container ()->number_of_connections ();
7071
7172 if (properties.type_ == ConnectionType::Delayed) {
72- connection = new DelayedConnection<T>(this ->name () + " _delayed_connection_" + std::to_string (index), // NOLINT
73- this ->container (), // NOLINT
74- properties.delay_ ); // NOLINT
73+ connection =
74+ std::make_unique<DelayedConnection<T>>(this ->name () + " _delayed_connection_" + std::to_string (index), // NOLINT
75+ this ->container (), // NOLINT
76+ properties.delay_ ); // NOLINT
7577 }
7678 if (properties.type_ == ConnectionType::Physical) {
77- connection = new PhysicalConnection<T>(this ->name () + " _physical_connection_" + std::to_string (index), // NOLINT
78- this ->container (), // NOLINT
79- properties.delay_ ); // NOLINT
79+ connection = std::make_unique<PhysicalConnection<T>>(this ->name () + " _physical_connection_" +
80+ std::to_string (index), // NOLINT
81+ this ->container (), // NOLINT
82+ properties.delay_ ); // NOLINT
8083 }
8184 if (properties.type_ == ConnectionType::Enclaved) {
82- connection = // NOLINT
83- new EnclaveConnection<T>(this ->name () + " _enclave_connection_" + std::to_string (index), enclave); // NOLINT
85+ connection = // NOLINT
86+ std::make_unique<EnclaveConnection<T>>(this ->name () + " _enclave_connection_" + std::to_string (index),
87+ enclave); // NOLINT
8488 }
8589 if (properties.type_ == ConnectionType::DelayedEnclaved) {
86- connection = // NOLINT
87- new DelayedEnclaveConnection<T>(this ->name () + " _delayed_enclave_connection_" + std::to_string (index), // NOLINT
88- enclave, // NOLINT
89- properties.delay_ ); // NOLINT
90+ connection = // NOLINT
91+ std::make_unique<DelayedEnclaveConnection<T>>(this ->name () + " _delayed_enclave_connection_" +
92+ std::to_string (index), // NOLINT
93+ enclave, // NOLINT
94+ properties.delay_ ); // NOLINT
9095 }
9196 if (properties.type_ == ConnectionType::PhysicalEnclaved) {
92- connection = new PhysicalEnclaveConnection<T>( // NOLINT
97+ connection = std::make_unique< PhysicalEnclaveConnection<T>>( // NOLINT
9398 this ->name () + " _physical_enclave_connection_" + std::to_string (index), enclave); // NOLINT
9499 }
95100
@@ -98,7 +103,7 @@ void Port<T>::pull_connection(const ConnectionProperties& properties, const std:
98103 connection->bind_downstream_ports (downstream);
99104 connection->bind_upstream_port (this );
100105 this ->register_set_callback (connection->upstream_set_callback ());
101- this ->container ()->register_connection (connection);
106+ this ->container ()->register_connection (std::move ( connection) );
102107}
103108
104109} // namespace reactor
0 commit comments