From 74825641aec43331823f988f2b924e9e763e39a1 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Tue, 22 Feb 2022 15:43:17 +0100 Subject: [PATCH 1/5] Move and rename update_value_int --- models/quantal_stp_synapse_impl.h | 36 ++----------------------------- sli/dictutils.h | 32 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/models/quantal_stp_synapse_impl.h b/models/quantal_stp_synapse_impl.h index 9fa2664b44..6e273fd7e3 100644 --- a/models/quantal_stp_synapse_impl.h +++ b/models/quantal_stp_synapse_impl.h @@ -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() @@ -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_ ); + updateValueInt( d, names::a, a_ ); } } // of namespace nest diff --git a/sli/dictutils.h b/sli/dictutils.h index 356748a24e..5fd0986e5f 100644 --- a/sli/dictutils.h +++ b/sli/dictutils.h @@ -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. + */ +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 ) + { + 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; +} + /** Create a property of type ArrayDatum in the dictionary, if it does not * already exist. From e146ef9b3e9914cbdfd7f204644f819b311fe586 Mon Sep 17 00:00:00 2001 From: Stine Brekke Vennemo Date: Tue, 8 Mar 2022 12:05:37 +0100 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: clinssen --- sli/dictutils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sli/dictutils.h b/sli/dictutils.h index 5fd0986e5f..7ad1be7112 100644 --- a/sli/dictutils.h +++ b/sli/dictutils.h @@ -272,6 +272,7 @@ updateValue2( DictionaryDatum const& d, Name const n, C& obj, void ( C::*setfunc * Skip call if it doesn't exist. * @ingroup DictUtils * @throws TypeMismatch The entry is neither int nor double. + * @returns true if the property was found (and updated) in the dictionary, false otherwise */ inline bool updateValueInt( const DictionaryDatum& d, Name propname, int& prop ) @@ -280,13 +281,13 @@ updateValueInt( const DictionaryDatum& d, Name propname, int& prop ) { Datum* dat = ( *d )[ propname ].datum(); IntegerDatum* intdat = dynamic_cast< IntegerDatum* >( dat ); - if ( intdat != 0 ) + if ( intdat != nullptr ) { prop = static_cast< int >( intdat->get() ); return true; } DoubleDatum* doubledat = dynamic_cast< DoubleDatum* >( dat ); - if ( doubledat != 0 ) + if ( doubledat != nullptr ) { prop = static_cast< int >( doubledat->get() ); return true; From 736f404c29ae9d05ffd323006bcea00664ff4bbb Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Tue, 8 Mar 2022 12:12:20 +0100 Subject: [PATCH 3/5] Add note about integer values --- sli/dictutils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sli/dictutils.h b/sli/dictutils.h index 7ad1be7112..518d9b37e5 100644 --- a/sli/dictutils.h +++ b/sli/dictutils.h @@ -225,6 +225,8 @@ def( DictionaryDatum& d, Name const n, FT const& value ) /** Update a variable from a dictionary entry if it exists, skip call if it * doesn't. + * @note It is not possible to update integer values. If the dictionary entry + * is an integer, use updateValueInt. * @ingroup DictUtils * @throws see getValue(DictionaryDatum, Name) */ From 65277cdb28f937b0f0053d4f9f4f5782e5120ee5 Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Tue, 22 Mar 2022 09:00:21 +0100 Subject: [PATCH 4/5] Remove updateValueInt, use updateValue< long > instead --- models/quantal_stp_synapse_impl.h | 4 ++-- sli/dictutils.h | 34 ------------------------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/models/quantal_stp_synapse_impl.h b/models/quantal_stp_synapse_impl.h index 6e273fd7e3..e6d22fe25b 100644 --- a/models/quantal_stp_synapse_impl.h +++ b/models/quantal_stp_synapse_impl.h @@ -76,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_ ); - updateValueInt( d, names::n, n_ ); - updateValueInt( d, names::a, a_ ); + updateValue< long >( d, names::n, n_ ); + updateValue< long >( d, names::a, a_ ); } } // of namespace nest diff --git a/sli/dictutils.h b/sli/dictutils.h index 518d9b37e5..52d3626c04 100644 --- a/sli/dictutils.h +++ b/sli/dictutils.h @@ -270,40 +270,6 @@ 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. - * @returns true if the property was found (and updated) in the dictionary, false otherwise - */ -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 != nullptr ) - { - prop = static_cast< int >( intdat->get() ); - return true; - } - DoubleDatum* doubledat = dynamic_cast< DoubleDatum* >( dat ); - if ( doubledat != nullptr ) - { - 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. * @ingroup DictUtils From 04347251a89ec46d25a2fd3b317341529c40100d Mon Sep 17 00:00:00 2001 From: Stine Vennemo Date: Tue, 22 Mar 2022 09:03:06 +0100 Subject: [PATCH 5/5] Update comment --- sli/dictutils.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sli/dictutils.h b/sli/dictutils.h index 52d3626c04..a4a5198c68 100644 --- a/sli/dictutils.h +++ b/sli/dictutils.h @@ -225,8 +225,7 @@ def( DictionaryDatum& d, Name const n, FT const& value ) /** Update a variable from a dictionary entry if it exists, skip call if it * doesn't. - * @note It is not possible to update integer values. If the dictionary entry - * is an integer, use updateValueInt. + * @note If the dictionary entry is an integer, use updateValue< long >. * @ingroup DictUtils * @throws see getValue(DictionaryDatum, Name) */