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

Use updateValue< long > instead of update_value_int in quantal_stp_synapse #2307

Merged
merged 5 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 2 additions & 34 deletions models/quantal_stp_synapse_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,6 @@
namespace nest
{


/* Polymorphic version of update_value.
* This code will take either an int or a double and convert it to an
* int.
*/
bool
update_value_int( const DictionaryDatum& d, Name propname, int& prop )
{
if ( d->known( propname ) )
{
Datum* dat = ( *d )[ propname ].datum();
IntegerDatum* intdat = dynamic_cast< IntegerDatum* >( dat );
if ( intdat != 0 )
{
prop = static_cast< int >( intdat->get() );
return true;
}
DoubleDatum* doubledat = dynamic_cast< DoubleDatum* >( dat );
if ( doubledat != 0 )
{
prop = static_cast< int >( doubledat->get() );
return true;
}
else
{
throw TypeMismatch();
}
}

return false;
}

template < typename targetidentifierT >
quantal_stp_synapse< targetidentifierT >::quantal_stp_synapse()
: ConnectionBase()
Expand Down Expand Up @@ -108,8 +76,8 @@ quantal_stp_synapse< targetidentifierT >::set_status( const DictionaryDatum& d,
updateValue< double >( d, names::u, u_ );
updateValue< double >( d, names::tau_rec, tau_rec_ );
updateValue< double >( d, names::tau_fac, tau_fac_ );
update_value_int( d, names::n, n_ );
update_value_int( d, names::a, a_ );
updateValueInt( d, names::n, n_ );
stinebuu marked this conversation as resolved.
Show resolved Hide resolved
updateValueInt( d, names::a, a_ );
}

} // of namespace nest
Expand Down
32 changes: 32 additions & 0 deletions sli/dictutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,38 @@ updateValue2( DictionaryDatum const& d, Name const n, C& obj, void ( C::*setfunc
}
}

/** Update an int or a double from a dictionary entry if it exists, and convert it to an int.
* Skip call if it doesn't exist.
* @ingroup DictUtils
* @throws TypeMismatch The entry is neither int nor double.
*/
stinebuu marked this conversation as resolved.
Show resolved Hide resolved
inline bool
updateValueInt( const DictionaryDatum& d, Name propname, int& prop )
{
if ( d->known( propname ) )
{
Datum* dat = ( *d )[ propname ].datum();
IntegerDatum* intdat = dynamic_cast< IntegerDatum* >( dat );
if ( intdat != 0 )
stinebuu marked this conversation as resolved.
Show resolved Hide resolved
{
prop = static_cast< int >( intdat->get() );
return true;
}
DoubleDatum* doubledat = dynamic_cast< DoubleDatum* >( dat );
if ( doubledat != 0 )
stinebuu marked this conversation as resolved.
Show resolved Hide resolved
{
prop = static_cast< int >( doubledat->get() );
return true;
}
else
{
throw TypeMismatch();
}
}

return false;
}


/** Create a property of type ArrayDatum in the dictionary, if it does not
* already exist.
Expand Down