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

Fix #954: Avoid the use of unrelated typenames to distinguish template classes #956

Merged
merged 2 commits into from May 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 31 additions & 31 deletions nestkernel/event.h
Expand Up @@ -934,15 +934,16 @@ read_from_comm_buffer( T& d, std::vector< unsigned int >::iterator& pos )
}

/**
* Template class for the storage and communication of a std::vector of type D.
* The class provides the functionality to communicate homogeneous data
* of type D. The second template type E is used to distinguish
* derived classes of the same type D. This is required because of the
* included static variables (as otherwise all derived classes of the same
* data type would share the same static variables).
* Template class for the storage and communication of a std::vector of type
* Data. The class provides the functionality to communicate homogeneous data
* of type Data. The second template type Subclass (which should be chosen
* as the derived class itself) is used to distinguish derived classes with
* the same Data type. This is required because of the included static
* variables in the base class (as otherwise all derived classes of the same
* Data type would share the same static variables).
*
* Technically the DataSecondaryEvent only contains iterators pointing to
* the memory location of the std::vector< D >.
* the memory location of the std::vector< Data >.
*
* Conceptually, there is a one-to-one mapping between a SecondaryEvent
* and a SecondaryConnectorModel. The synindex of this particular
Expand All @@ -955,16 +956,16 @@ read_from_comm_buffer( T& d, std::vector< unsigned int >::iterator& pos )
* supports_syn_id()-function allows testing if a particular synid is mapped
* with the SecondaryEvent in question.
*/
template < typename D, typename E >
template < typename Data, typename Subclass >
class DataSecondaryEvent : public SecondaryEvent
{
private:
// we chose std::vector over std::set because we expect this to be short
static std::vector< synindex > supported_syn_ids_;
static size_t coeff_length_; // length of coeffarray

typename std::vector< D >::iterator coeffarray_as_d_begin_;
typename std::vector< D >::iterator coeffarray_as_d_end_;
typename std::vector< Data >::iterator coeffarray_as_d_begin_;
typename std::vector< Data >::iterator coeffarray_as_d_end_;
std::vector< unsigned int >::iterator coeffarray_as_uints_begin_;
std::vector< unsigned int >::iterator coeffarray_as_uints_end_;

Expand Down Expand Up @@ -1012,7 +1013,7 @@ class DataSecondaryEvent : public SecondaryEvent
}

void
set_coeffarray( std::vector< D >& ca )
set_coeffarray( std::vector< Data >& ca )
{
coeffarray_as_d_begin_ = ca.begin();
coeffarray_as_d_end_ = ca.end();
Expand All @@ -1034,7 +1035,7 @@ class DataSecondaryEvent : public SecondaryEvent
// therefore we save an iterator to the beginning+end of the coeffarray
coeffarray_as_uints_begin_ = pos;

pos += coeff_length_ * number_of_uints_covered< D >();
pos += coeff_length_ * number_of_uints_covered< Data >();

coeffarray_as_uints_end_ = pos;

Expand All @@ -1052,7 +1053,7 @@ class DataSecondaryEvent : public SecondaryEvent
{
write_to_comm_buffer( *( supported_syn_ids_.begin() ), pos );
write_to_comm_buffer( sender_gid_, pos );
for ( typename std::vector< D >::iterator i = coeffarray_as_d_begin_;
for ( typename std::vector< Data >::iterator i = coeffarray_as_d_begin_;
i != coeffarray_as_d_end_;
i++ )
{
Expand All @@ -1066,7 +1067,7 @@ class DataSecondaryEvent : public SecondaryEvent
{
size_t s = number_of_uints_covered< synindex >();
s += number_of_uints_covered< index >();
s += number_of_uints_covered< D >() * coeff_length_;
s += number_of_uints_covered< Data >() * coeff_length_;

return s;
}
Expand All @@ -1083,15 +1084,14 @@ class DataSecondaryEvent : public SecondaryEvent
return coeffarray_as_uints_end_;
}

D get_coeffvalue( std::vector< unsigned int >::iterator& pos );
Data get_coeffvalue( std::vector< unsigned int >::iterator& pos );
};

/**
* Event for gap-junction information. The event transmits the interpolation
* of the membrane potential to the connected neurons.
*/
class GapJunctionEvent
: public DataSecondaryEvent< double, int /*only used to distinguish events*/ >
class GapJunctionEvent : public DataSecondaryEvent< double, GapJunctionEvent >
{

public:
Expand All @@ -1108,8 +1108,7 @@ class GapJunctionEvent
* the rate to the connected neurons.
*/
class InstantaneousRateConnectionEvent
: public DataSecondaryEvent< double,
char /*only used to distinguish events*/ >
: public DataSecondaryEvent< double, InstantaneousRateConnectionEvent >
{

public:
Expand All @@ -1125,8 +1124,8 @@ class InstantaneousRateConnectionEvent
* Event for rate model connections with delay. The event transmits
* the rate to the connected neurons.
*/
class DelayedRateConnectionEvent : public DataSecondaryEvent< double,
bool /*only used to distinguish events*/ >
class DelayedRateConnectionEvent
: public DataSecondaryEvent< double, DelayedRateConnectionEvent >
{

public:
Expand All @@ -1142,8 +1141,8 @@ class DelayedRateConnectionEvent : public DataSecondaryEvent< double,
* Event for diffusion connections (rate model connections for the
* siegert_neuron). The event transmits the rate to the connected neurons.
*/
class DiffusionConnectionEvent : public DataSecondaryEvent< double,
float /*only used to distinguish events*/ >
class DiffusionConnectionEvent
: public DataSecondaryEvent< double, DiffusionConnectionEvent >
{
private:
// drift factor of the corresponding connection
Expand Down Expand Up @@ -1175,21 +1174,22 @@ class DiffusionConnectionEvent : public DataSecondaryEvent< double,
weight get_diffusion_factor() const;
};

template < typename D, typename E >
inline D
DataSecondaryEvent< D, E >::get_coeffvalue(
template < typename Data, typename Subclass >
inline Data
DataSecondaryEvent< Data, Subclass >::get_coeffvalue(
std::vector< unsigned int >::iterator& pos )
{
D elem;
Data elem;
read_from_comm_buffer( elem, pos );
return elem;
}

template < typename D, typename E >
std::vector< synindex > DataSecondaryEvent< D, E >::supported_syn_ids_;
template < typename Data, typename Subclass >
std::vector< synindex >
DataSecondaryEvent< Data, Subclass >::supported_syn_ids_;

template < typename D, typename E >
size_t DataSecondaryEvent< D, E >::coeff_length_ = 0;
template < typename Data, typename Subclass >
size_t DataSecondaryEvent< Data, Subclass >::coeff_length_ = 0;

inline GapJunctionEvent*
GapJunctionEvent::clone() const
Expand Down