diff --git a/models/diffusion_connection.h b/models/diffusion_connection.h index d7b250853a..c96ac60017 100644 --- a/models/diffusion_connection.h +++ b/models/diffusion_connection.h @@ -112,7 +112,7 @@ class diffusion_connection : public Connection< targetidentifierT > { } - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. @@ -214,10 +214,10 @@ diffusion_connection< targetidentifierT >::set_status( const DictionaryDatum& d, template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > diffusion_connection< targetidentifierT >::get_secondary_event() { - return new DiffusionConnectionEvent(); + return std::make_unique< DiffusionConnectionEvent >(); } } // namespace diff --git a/models/eprop_learning_signal_connection.h b/models/eprop_learning_signal_connection.h index cc013a028b..c40b27a296 100644 --- a/models/eprop_learning_signal_connection.h +++ b/models/eprop_learning_signal_connection.h @@ -151,7 +151,7 @@ class eprop_learning_signal_connection : public Connection< targetidentifierT > } //! Get the secondary learning signal event. - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); using ConnectionBase::get_delay_steps; using ConnectionBase::get_rport; @@ -220,10 +220,10 @@ eprop_learning_signal_connection< targetidentifierT >::set_status( const Diction } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > eprop_learning_signal_connection< targetidentifierT >::get_secondary_event() { - return new LearningSignalConnectionEvent(); + return std::make_unique< LearningSignalConnectionEvent >(); } } // namespace nest diff --git a/models/eprop_learning_signal_connection_bsshslm_2020.h b/models/eprop_learning_signal_connection_bsshslm_2020.h index 5a6f5d5e5d..cf829a46db 100644 --- a/models/eprop_learning_signal_connection_bsshslm_2020.h +++ b/models/eprop_learning_signal_connection_bsshslm_2020.h @@ -154,7 +154,7 @@ class eprop_learning_signal_connection_bsshslm_2020 : public Connection< targeti } //! Get the secondary learning signal event. - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); using ConnectionBase::get_delay_steps; using ConnectionBase::get_rport; @@ -224,10 +224,10 @@ eprop_learning_signal_connection_bsshslm_2020< targetidentifierT >::set_status( } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > eprop_learning_signal_connection_bsshslm_2020< targetidentifierT >::get_secondary_event() { - return new LearningSignalConnectionEvent(); + return std::make_unique< LearningSignalConnectionEvent >(); } } // namespace nest diff --git a/models/gap_junction.h b/models/gap_junction.h index dd25df9776..415e819cc0 100644 --- a/models/gap_junction.h +++ b/models/gap_junction.h @@ -105,7 +105,7 @@ class gap_junction : public Connection< targetidentifierT > { } - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. This avoids explicit name prefixes in all places these @@ -177,10 +177,10 @@ gap_junction< targetidentifierT >::get_status( DictionaryDatum& d ) const } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > gap_junction< targetidentifierT >::get_secondary_event() { - return new GapJunctionEvent(); + return std::make_unique< GapJunctionEvent >(); } template < typename targetidentifierT > diff --git a/models/rate_connection_delayed.h b/models/rate_connection_delayed.h index 81c3f3ea40..e5f1bf176d 100644 --- a/models/rate_connection_delayed.h +++ b/models/rate_connection_delayed.h @@ -99,7 +99,7 @@ class rate_connection_delayed : public Connection< targetidentifierT > { } - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. @@ -174,10 +174,10 @@ rate_connection_delayed< targetidentifierT >::set_status( const DictionaryDatum& } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > rate_connection_delayed< targetidentifierT >::get_secondary_event() { - return new DelayedRateConnectionEvent(); + return std::make_unique< DelayedRateConnectionEvent >(); } } // namespace diff --git a/models/rate_connection_instantaneous.h b/models/rate_connection_instantaneous.h index 4d32e41cc0..577cca889b 100644 --- a/models/rate_connection_instantaneous.h +++ b/models/rate_connection_instantaneous.h @@ -100,7 +100,7 @@ class rate_connection_instantaneous : public Connection< targetidentifierT > { } - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. @@ -189,10 +189,10 @@ rate_connection_instantaneous< targetidentifierT >::set_status( const Dictionary } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > rate_connection_instantaneous< targetidentifierT >::get_secondary_event() { - return new InstantaneousRateConnectionEvent(); + return std::make_unique< InstantaneousRateConnectionEvent >(); } } // namespace diff --git a/models/sic_connection.h b/models/sic_connection.h index 0cf806c2ac..a07c3a5b9a 100644 --- a/models/sic_connection.h +++ b/models/sic_connection.h @@ -86,7 +86,7 @@ class sic_connection : public Connection< targetidentifierT > { } - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); // Explicitly declare all methods inherited from the dependent base // ConnectionBase. This avoids explicit name prefixes in all places these @@ -154,10 +154,10 @@ sic_connection< targetidentifierT >::get_status( DictionaryDatum& d ) const } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > sic_connection< targetidentifierT >::get_secondary_event() { - return new SICEvent(); + return std::make_unique< SICEvent >(); } template < typename targetidentifierT > diff --git a/nestkernel/connection.h b/nestkernel/connection.h index 4a90eb2f0f..d3cb8f4cee 100644 --- a/nestkernel/connection.h +++ b/nestkernel/connection.h @@ -134,7 +134,7 @@ class Connection * To prevent erronous calls of this function on primary connections, the base class implementation * below just contains `assert(false)`. */ - SecondaryEvent* get_secondary_event(); + std::unique_ptr< SecondaryEvent > get_secondary_event(); /** * Get all properties of this connection and put them into a dictionary. @@ -399,7 +399,7 @@ Connection< targetidentifierT >::trigger_update_weight( const size_t, } template < typename targetidentifierT > -SecondaryEvent* +std::unique_ptr< SecondaryEvent > Connection< targetidentifierT >::get_secondary_event() { assert( false and "Non-primary connections have to provide get_secondary_event()" ); diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index 0924fb73e2..22e55c871e 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -1681,19 +1681,20 @@ nest::ConnectionManager::deliver_secondary_events( const size_t tid, { if ( positions_tid[ syn_id ].size() > 0 ) { - SecondaryEvent& prototype = kernel().model_manager.get_secondary_event_prototype( syn_id, tid ); + std::unique_ptr< SecondaryEvent > prototype = + kernel().model_manager.get_secondary_event_prototype( syn_id, tid ); size_t lcid = 0; const size_t lcid_end = positions_tid[ syn_id ].size(); while ( lcid < lcid_end ) { std::vector< unsigned int >::iterator readpos = recv_buffer.begin() + positions_tid[ syn_id ][ lcid ]; - prototype << readpos; - prototype.set_stamp( stamp ); + *prototype << readpos; + prototype->set_stamp( stamp ); // send delivers event to all targets with the same source // and returns how many targets this event was delivered to - lcid += connections_[ tid ][ syn_id ]->send( tid, lcid, cm, prototype ); + lcid += connections_[ tid ][ syn_id ]->send( tid, lcid, cm, *prototype ); } } } diff --git a/nestkernel/connector_model.h b/nestkernel/connector_model.h index 0a7f83ce8e..0884b44312 100644 --- a/nestkernel/connector_model.h +++ b/nestkernel/connector_model.h @@ -119,7 +119,7 @@ class ConnectorModel */ virtual void check_synapse_params( const DictionaryDatum& ) const = 0; - virtual SecondaryEvent* get_secondary_event() = 0; + virtual std::unique_ptr< SecondaryEvent > get_secondary_event() = 0; virtual size_t get_syn_id() const = 0; virtual void set_syn_id( synindex syn_id ) = 0; @@ -199,7 +199,7 @@ class GenericConnectorModel : public ConnectorModel void check_synapse_params( const DictionaryDatum& syn_spec ) const override; - SecondaryEvent* + std::unique_ptr< SecondaryEvent > get_secondary_event() override { return default_connection_.get_secondary_event(); diff --git a/nestkernel/model_manager.h b/nestkernel/model_manager.h index 924535a780..58c5ceafb2 100644 --- a/nestkernel/model_manager.h +++ b/nestkernel/model_manager.h @@ -174,7 +174,7 @@ class ModelManager : public ManagerInterface */ void memory_info() const; - SecondaryEvent& get_secondary_event_prototype( const synindex syn_id, const size_t tid ); + std::unique_ptr< SecondaryEvent > get_secondary_event_prototype( const synindex syn_id, const size_t tid ); private: /** @@ -319,11 +319,11 @@ ModelManager::assert_valid_syn_id( synindex syn_id, size_t t ) const } } -inline SecondaryEvent& +inline std::unique_ptr< SecondaryEvent > ModelManager::get_secondary_event_prototype( const synindex syn_id, const size_t tid ) { assert_valid_syn_id( syn_id, tid ); - return *get_connection_model( syn_id, tid ).get_secondary_event(); + return get_connection_model( syn_id, tid ).get_secondary_event(); } } // namespace nest diff --git a/nestkernel/source_table.cpp b/nestkernel/source_table.cpp index d9fcd7af1c..7007e8e60a 100644 --- a/nestkernel/source_table.cpp +++ b/nestkernel/source_table.cpp @@ -246,7 +246,7 @@ nest::SourceTable::compute_buffer_pos_for_unique_secondary_sources( const size_t ++cit ) { const size_t source_rank = kernel().mpi_manager.get_process_id_of_node_id( cit->first ); - const size_t event_size = kernel().model_manager.get_secondary_event_prototype( cit->second, tid ).size(); + const size_t event_size = kernel().model_manager.get_secondary_event_prototype( cit->second, tid )->size(); buffer_pos_of_source_node_id_syn_id.insert( std::make_pair( pack_source_node_id_and_syn_id( cit->first, cit->second ),