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 7 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
52 changes: 26 additions & 26 deletions libnestutil/enum_bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ namespace nest
/**
* These methods support type-safe bitfields using C++'s enum classes.
*
* Define the bitfield flags as follows:
* Define the bitfield properties as follows:
*
* .. code-block:: C++
*
* enum class MyFlags : unsigned
* enum class MyProperties : unsigned
* {
* FIRST_FLAG = 1 << 0,
* SECOND_FLAG = 1 << 1,
* THIRD_FLAG = 1 << 2,
* FOURTH_FLAG = 1 << 3
* FIRST_PROPERTY = 1 << 0,
* SECOND_PROPERTY = 1 << 1,
* THIRD_PROPERTY = 1 << 2,
* FOURTH_PROPERTY = 1 << 3
* };
*
* To prevent template substitution from enabling bitfield operators on *every* enum class, we use the enable_if
Expand All @@ -47,17 +47,17 @@ 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 `MyProperties`--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:
* To enable the bitfield operators for our `MyProperties` class, we thus specialise the template:
*
* .. code-block:: C++
*
* template <>
* struct EnableBitMaskOperators< MyFlags >
* struct EnableBitMaskOperators< MyProperties >
* {
* static const bool enable = true;
* };
Expand All @@ -66,9 +66,9 @@ namespace nest
*
* .. code-block:: C++
*
* MyFlags my_flags = MyFlags::FIRST_FLAG | MyFlags::FOURTH_FLAG;
* my_flags |= MyFlags::THIRD_FLAG;
* if ( enumFlagSet( my_flags, MyFlags::FOURTH_FLAG ) )
* MyProperties my_properties = MyProperties::FIRST_PROPERTY | MyProperties::FOURTH_PROPERTY;
* my_properties |= MyProperties::THIRD_PROPERTY;
* if ( has_property( my_properties, MyProperties::FOURTH_PROPERTY ) )
* {
* 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,10 +133,10 @@ operator^=( Enum& lhs, Enum rhs )

template < typename Enum >
bool
enumFlagSet( const Enum en, const Enum flag )
has_property( const Enum en, const Enum property )
{
using underlying = typename std::underlying_type< Enum >::type;
return static_cast< underlying >( en & flag ) != 0;
return static_cast< underlying >( en & property ) != 0;
}
clinssen marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
6 changes: 6 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,9 @@ class clopath_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties =
default_connection_model_properties | ConnectionModelProperties::REQUIRES_CLOPATH_ARCHIVING;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -211,6 +215,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
6 changes: 5 additions & 1 deletion models/diffusion_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ 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 secondaryProperties = ConnectionModelProperties::SUPPORTS_WFR;

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

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

template < typename targetidentifierT >
void
DiffusionConnection< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down
6 changes: 6 additions & 0 deletions models/gap_junction.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class GapJunction : public Connection< targetidentifierT >
typedef Connection< targetidentifierT > ConnectionBase;
typedef GapJunctionEvent EventType;

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

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -149,6 +152,9 @@ class GapJunction : public Connection< targetidentifierT >
double weight_; //!< connection weight
};

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

template < typename targetidentifierT >
void
GapJunction< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down
18 changes: 6 additions & 12 deletions models/modelsmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,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 @@ -334,19 +333,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_secondary_connection_model< GapJunction >( "gap_junction" );
register_secondary_connection_model< RateConnectionInstantaneous >( "rate_connection_instantaneous" );
register_secondary_connection_model< RateConnectionDelayed >( "rate_connection_delayed" );
register_secondary_connection_model< DiffusionConnection >( "diffusion_connection" );
}

} // namespace nest
4 changes: 4 additions & 0 deletions models/rate_connection_delayed.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class RateConnectionDelayed : public Connection< targetidentifierT >
typedef Connection< targetidentifierT > ConnectionBase;
typedef DelayedRateConnectionEvent EventType;

static constexpr ConnectionModelProperties secondaryProperties = ConnectionModelProperties::HAS_DELAY;

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -141,6 +143,8 @@ class RateConnectionDelayed : public Connection< targetidentifierT >
double weight_; //!< connection weight
};

template < typename targetidentifierT > constexpr ConnectionModelProperties RateConnectionDelayed< targetidentifierT >::secondaryProperties;

template < typename targetidentifierT >
void
RateConnectionDelayed< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down
4 changes: 4 additions & 0 deletions models/rate_connection_instantaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class RateConnectionInstantaneous : public Connection< targetidentifierT >
typedef Connection< targetidentifierT > ConnectionBase;
typedef InstantaneousRateConnectionEvent EventType;

static constexpr ConnectionModelProperties secondaryProperties = ConnectionModelProperties::SUPPORTS_WFR;
clinssen marked this conversation as resolved.
Show resolved Hide resolved

/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
Expand Down Expand Up @@ -149,6 +151,8 @@ class RateConnectionInstantaneous : public Connection< targetidentifierT >
double weight_; //!< connection weight
};

template < typename targetidentifierT > constexpr ConnectionModelProperties RateConnectionInstantaneous< targetidentifierT >::secondaryProperties;

template < typename targetidentifierT >
void
RateConnectionInstantaneous< targetidentifierT >::get_status( DictionaryDatum& d ) const
Expand Down
5 changes: 5 additions & 0 deletions models/urbanczik_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class urbanczik_synapse : public Connection< targetidentifierT >
typedef CommonSynapseProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;

static constexpr ConnectionModelProperties properties =
default_connection_model_properties | ConnectionModelProperties::REQUIRES_URBANCZIK_ARCHIVING;

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

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

/**
* Send an event to the receiver of this connection.
Expand Down
19 changes: 12 additions & 7 deletions nestkernel/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "delay_checker.h"
#include "event.h"
#include "kernel_manager.h"
#include "nest.h"
#include "nest_names.h"
#include "nest_time.h"
#include "nest_timeconverter.h"
Expand Down Expand Up @@ -96,7 +97,6 @@ class ConnTestDummyNodeBase : public Node
}
};


/**
* Base class for representing connections.
* It provides the mandatory properties receiver port and target,
Expand All @@ -120,6 +120,10 @@ class Connection
// connections not used in primary connectors
typedef SecondaryEvent EventType;

// properties used when registering a connection with the ModelManager
static constexpr ConnectionModelProperties properties = default_connection_model_properties;
static constexpr ConnectionModelProperties secondaryProperties = default_secondary_connection_model_properties;

Connection()
: target_()
, syn_id_delay_( 1.0 )
Expand Down Expand Up @@ -297,19 +301,20 @@ class Connection
*/
void check_connection_( Node& dummy_target, Node& source, Node& target, const rport receptor_type );

/* the order of the members below is critical
as it influcences the size of the object. Please leave unchanged
as
/* the order of the members below is critical as it influcences the size of the object. Please leave unchanged as:

targetidentifierT target_;
SynIdDelay syn_id_delay_; //!< syn_id (char) and delay (24 bit) in
timesteps of this
connection
SynIdDelay syn_id_delay_; //!< syn_id (char) and delay (24 bit) in timesteps of this connection
*/
targetidentifierT target_;
//! syn_id (char) and delay (24 bit) in timesteps of this connection
SynIdDelay syn_id_delay_;
};

template < typename targetidentifierT >
constexpr ConnectionModelProperties Connection< targetidentifierT >::properties;
template < typename targetidentifierT >
constexpr ConnectionModelProperties Connection< targetidentifierT >::secondaryProperties;

template < typename targetidentifierT >
inline void
Expand Down
22 changes: 3 additions & 19 deletions nestkernel/connector_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,17 @@
namespace nest
{

ConnectorModel::ConnectorModel( const std::string name,
const bool is_primary,
const bool has_delay,
const bool requires_symmetric,
const bool supports_wfr,
const bool requires_clopath_archiving,
const bool requires_urbanczik_archiving )
ConnectorModel::ConnectorModel( const std::string name, const ConnectionModelProperties& properties )
: name_( name )
, default_delay_needs_check_( true )
, is_primary_( is_primary )
, has_delay_( has_delay )
, requires_symmetric_( requires_symmetric )
, supports_wfr_( supports_wfr )
, requires_clopath_archiving_( requires_clopath_archiving )
, requires_urbanczik_archiving_( requires_urbanczik_archiving )
, properties_( properties )
{
}

ConnectorModel::ConnectorModel( const ConnectorModel& cm, const std::string name )
: name_( name )
, default_delay_needs_check_( true )
, is_primary_( cm.is_primary_ )
, has_delay_( cm.has_delay_ )
, requires_symmetric_( cm.requires_symmetric_ )
, supports_wfr_( cm.supports_wfr_ )
, requires_clopath_archiving_( cm.requires_clopath_archiving_ )
, requires_urbanczik_archiving_( cm.requires_urbanczik_archiving_ )
, properties_( cm.get_properties() )
clinssen marked this conversation as resolved.
Show resolved Hide resolved
{
}

Expand Down
Loading