Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move connection flags to Connection static const member #2517

Merged
merged 18 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions libnestutil/enum_bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace nest
* A templated struct `EnableBitMaskOperators` is defined, that, regardless of the template type, contains a single
* static constant member `enable`, set to false. This is the "default", as the template may be specialised with any
* type. However, we can override this behaviour by explicitly providing a template specialisation of
* `EnableBitMaskOperators` for a particular type--namely, our bitfield enum class `MyFlags`--with a static constant
* member by the same name but with value set to true. If we then want to ask during function definition of bitmask
* operations whether they should be defined for an arbitrary type `T`, all we have to do is specalise
* `EnableBitMaskOperators` for a particular type--namely, our bitfield enum class `MyFlags`--with a static
* constant member by the same name but with value set to true. If we then want to ask during function definition of
* bitmask operations whether they should be defined for an arbitrary type `T`, all we have to do is specalise
* `EnableBitMaskOperators` by this type `T`, and check the value of its `enable` member using `enable_if`.
*
* To enable the bitfield operators for our `MyFlags` class, we thus specialise the template:
Expand All @@ -68,7 +68,7 @@ namespace nest
*
* MyFlags my_flags = MyFlags::FIRST_FLAG | MyFlags::FOURTH_FLAG;
* my_flags |= MyFlags::THIRD_FLAG;
* if ( enumFlagSet( my_flags, MyFlags::FOURTH_FLAG ) )
* if ( flag_is_set( my_flags, MyFlags::FOURTH_FLAG ) )
* {
* std::cout << "Fourth flag is set!" << std::endl;
* }
Expand All @@ -81,27 +81,27 @@ struct EnableBitMaskOperators
};

template < typename Enum >
typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator|( Enum lhs, Enum rhs )
constexpr typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator|( const Enum lhs, const Enum rhs )
{
using underlying = typename std::underlying_type< Enum >::type;
return static_cast< Enum >( static_cast< underlying >( lhs ) | static_cast< underlying >( rhs ) );
using underlying = typename std::underlying_type< const Enum >::type;
return static_cast< const Enum >( static_cast< underlying >( lhs ) | static_cast< underlying >( rhs ) );
}

template < typename Enum >
typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator&( Enum lhs, Enum rhs )
constexpr typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator&( const Enum lhs, const Enum rhs )
{
using underlying = typename std::underlying_type< Enum >::type;
return static_cast< Enum >( static_cast< underlying >( lhs ) & static_cast< underlying >( rhs ) );
return static_cast< const Enum >( static_cast< underlying >( lhs ) & static_cast< underlying >( rhs ) );
}

template < typename Enum >
typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator^( Enum& lhs, Enum rhs )
constexpr typename std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type
operator^( const Enum& lhs, const Enum rhs )
{
using underlying = typename std::underlying_type< Enum >::type;
return static_cast< Enum >( static_cast< underlying >( lhs ) ^ static_cast< underlying >( rhs ) );
return static_cast< const Enum >( static_cast< underlying >( lhs ) ^ static_cast< underlying >( rhs ) );
}

template < typename Enum >
Expand Down Expand Up @@ -133,7 +133,7 @@ operator^=( Enum& lhs, Enum rhs )

template < typename Enum >
bool
enumFlagSet( const Enum en, const Enum flag )
flag_is_set( const Enum en, const Enum flag )
{
using underlying = typename std::underlying_type< Enum >::type;
return static_cast< underlying >( en & flag ) != 0;
Expand Down
7 changes: 7 additions & 0 deletions models/bernoulli_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class bernoulli_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::SUPPORTS_HPC
| ConnectionModelProperties::SUPPORTS_LBL;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -188,6 +192,9 @@ class bernoulli_synapse : public Connection< targetidentifierT >
double p_transmit_;
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties bernoulli_synapse< targetidentifierT >::properties;

template < typename targetidentifierT >
void
bernoulli_synapse< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down
8 changes: 8 additions & 0 deletions models/clopath_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "connection.h"
#include "connector_model.h"
#include "event.h"
#include "nest.h"
#include "ring_buffer.h"

// Includes from sli:
Expand Down Expand Up @@ -116,6 +117,11 @@ class clopath_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::REQUIRES_CLOPATH_ARCHIVING
| ConnectionModelProperties::SUPPORTS_HPC | ConnectionModelProperties::SUPPORTS_LBL
| ConnectionModelProperties::SUPPORTS_WFR;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -211,6 +217,8 @@ class clopath_synapse : public Connection< targetidentifierT >
double t_lastspike_;
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties clopath_synapse< targetidentifierT >::properties;

/**
* Send an event to the receiver of this connection.
Expand Down
7 changes: 7 additions & 0 deletions models/cont_delay_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class cont_delay_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::SUPPORTS_HPC
| ConnectionModelProperties::SUPPORTS_LBL | ConnectionModelProperties::SUPPORTS_WFR;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -232,6 +236,9 @@ cont_delay_synapse< targetidentifierT >::send( Event& e, thread t, const CommonS
e.set_offset( orig_event_offset );
}

template < typename targetidentifierT >
constexpr ConnectionModelProperties cont_delay_synapse< targetidentifierT >::properties;

} // of namespace nest

#endif // of #ifndef CONT_DELAY_SYNAPSE_H
19 changes: 16 additions & 3 deletions models/diffusion_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ EndUserDocs */
template < typename targetidentifierT >
class DiffusionConnection : public Connection< targetidentifierT >
{

public:
// this line determines which common properties to use
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;
typedef DiffusionConnectionEvent EventType;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::SUPPORTS_WFR;

/**
* Default Constructor.
Expand All @@ -105,6 +105,8 @@ class DiffusionConnection : public Connection< targetidentifierT >
{
}

SecondaryEvent* get_secondary_event();

// Explicitly declare all methods inherited from the dependent base
// ConnectionBase.
// This avoids explicit name prefixes in all places these functions are used.
Expand All @@ -118,7 +120,7 @@ class DiffusionConnection : public Connection< targetidentifierT >
void
check_connection( Node& s, Node& t, rport receptor_type, const CommonPropertiesType& )
{
EventType ge;
DiffusionConnectionEvent ge;

s.sends_secondary_event( ge );
ge.set_sender( s );
Expand Down Expand Up @@ -165,6 +167,9 @@ class DiffusionConnection : public Connection< targetidentifierT >
double diffusion_factor_;
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties DiffusionConnection< targetidentifierT >::properties;

template < typename targetidentifierT >
void
DiffusionConnection< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down Expand Up @@ -198,6 +203,14 @@ DiffusionConnection< targetidentifierT >::set_status( const DictionaryDatum& d,
updateValue< double >( d, names::diffusion_factor, diffusion_factor_ );
}


template < typename targetidentifierT >
SecondaryEvent*
DiffusionConnection< targetidentifierT >::get_secondary_event()
{
return new DiffusionConnectionEvent();
}

} // namespace

#endif /* #ifndef DIFFUSION_CONNECTION_H */
18 changes: 16 additions & 2 deletions models/gap_junction.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class GapJunction : public Connection< targetidentifierT >
// this line determines which common properties to use
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;
typedef GapJunctionEvent EventType;

static constexpr ConnectionModelProperties properties =
ConnectionModelProperties::REQUIRES_SYMMETRIC | ConnectionModelProperties::SUPPORTS_WFR;

/**
* Default Constructor.
Expand All @@ -96,6 +98,8 @@ class GapJunction : public Connection< targetidentifierT >
{
}

SecondaryEvent* get_secondary_event();

// Explicitly declare all methods inherited from the dependent base
// ConnectionBase. This avoids explicit name prefixes in all places these
// functions are used. Since ConnectionBase depends on the template parameter,
Expand All @@ -107,7 +111,7 @@ class GapJunction : public Connection< targetidentifierT >
void
check_connection( Node& s, Node& t, rport receptor_type, const CommonPropertiesType& )
{
EventType ge;
GapJunctionEvent ge;

s.sends_secondary_event( ge );
ge.set_sender( s );
Expand Down Expand Up @@ -149,6 +153,9 @@ class GapJunction : public Connection< targetidentifierT >
double weight_; //!< connection weight
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties GapJunction< targetidentifierT >::properties;

template < typename targetidentifierT >
void
GapJunction< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand All @@ -161,6 +168,13 @@ GapJunction< targetidentifierT >::get_status( DictionaryDatum& d ) const
def< long >( d, names::size_of, sizeof( *this ) );
}

template < typename targetidentifierT >
SecondaryEvent*
GapJunction< targetidentifierT >::get_secondary_event()
{
return new GapJunctionEvent();
}

template < typename targetidentifierT >
void
GapJunction< targetidentifierT >::set_status( const DictionaryDatum& d, ConnectorModel& cm )
Expand Down
6 changes: 6 additions & 0 deletions models/ht_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class ht_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::SUPPORTS_HPC
| ConnectionModelProperties::SUPPORTS_LBL;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -182,6 +186,8 @@ class ht_synapse : public Connection< targetidentifierT >
double t_lastspike_; //!< Time point of last spike emitted
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties ht_synapse< targetidentifierT >::properties;

/**
* Send an event to the receiver of this connection.
Expand Down
8 changes: 7 additions & 1 deletion models/jonke_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,22 @@ class jonke_synapse : public Connection< targetidentifierT >
typedef JonkeCommonProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::SUPPORTS_HPC
| ConnectionModelProperties::SUPPORTS_LBL;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
*/
jonke_synapse();


/**
* Copy constructor.
* Needs to be defined properly in order for GenericConnector to work.
*/
jonke_synapse( const jonke_synapse& ) = default;

jonke_synapse& operator=( const jonke_synapse& ) = default;

// Explicitly declare all methods inherited from the dependent base
Expand Down Expand Up @@ -323,6 +327,8 @@ class jonke_synapse : public Connection< targetidentifierT >
double t_lastspike_;
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties jonke_synapse< targetidentifierT >::properties;

/**
* Send an event to the receiver of this connection.
Expand Down
18 changes: 6 additions & 12 deletions models/modelsmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ ModelsModule::init( SLIInterpreter* )

// register all synapse models
register_connection_model< bernoulli_synapse >( "bernoulli_synapse" );
register_connection_model< clopath_synapse >(
"clopath_synapse", default_connection_model_flags | RegisterConnectionModelFlags::REQUIRES_CLOPATH_ARCHIVING );
register_connection_model< clopath_synapse >( "clopath_synapse" );
register_connection_model< cont_delay_synapse >( "cont_delay_synapse" );
register_connection_model< ht_synapse >( "ht_synapse" );
register_connection_model< jonke_synapse >( "jonke_synapse" );
Expand All @@ -328,19 +327,14 @@ ModelsModule::init( SLIInterpreter* )
register_connection_model< tsodyks_synapse >( "tsodyks_synapse" );
register_connection_model< tsodyks_synapse_hom >( "tsodyks_synapse_hom" );
register_connection_model< tsodyks2_synapse >( "tsodyks2_synapse" );
register_connection_model< urbanczik_synapse >(
"urbanczik_synapse", default_connection_model_flags | RegisterConnectionModelFlags::REQUIRES_URBANCZIK_ARCHIVING );
register_connection_model< urbanczik_synapse >( "urbanczik_synapse" );
register_connection_model< vogels_sprekeler_synapse >( "vogels_sprekeler_synapse" );

// register secondary connection models
register_secondary_connection_model< GapJunction >(
"gap_junction", RegisterConnectionModelFlags::REQUIRES_SYMMETRIC | RegisterConnectionModelFlags::SUPPORTS_WFR );
register_secondary_connection_model< RateConnectionInstantaneous >(
"rate_connection_instantaneous", RegisterConnectionModelFlags::SUPPORTS_WFR );
register_secondary_connection_model< RateConnectionDelayed >(
"rate_connection_delayed", RegisterConnectionModelFlags::HAS_DELAY );
register_secondary_connection_model< DiffusionConnection >(
"diffusion_connection", RegisterConnectionModelFlags::SUPPORTS_WFR );
register_connection_model< GapJunction >( "gap_junction" );
register_connection_model< RateConnectionInstantaneous >( "rate_connection_instantaneous" );
register_connection_model< RateConnectionDelayed >( "rate_connection_delayed" );
register_connection_model< DiffusionConnection >( "diffusion_connection" );
}

} // namespace nest
7 changes: 7 additions & 0 deletions models/quantal_stp_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,16 @@ class quantal_stp_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties = ConnectionModelProperties::HAS_DELAY
| ConnectionModelProperties::IS_PRIMARY | ConnectionModelProperties::SUPPORTS_HPC
| ConnectionModelProperties::SUPPORTS_LBL;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
*/
quantal_stp_synapse();

/**
* Copy constructor to propagate common properties.
*/
Expand Down Expand Up @@ -184,6 +189,8 @@ class quantal_stp_synapse : public Connection< targetidentifierT >
double t_lastspike_; //!< Time point of last spike emitted
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties quantal_stp_synapse< targetidentifierT >::properties;

/**
* Send an event to the receiver of this connection.
Expand Down
Loading