NEST main@caf0ae8
 
Loading...
Searching...
No Matches
dict_util.h
Go to the documentation of this file.
1/*
2 * dict_util.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef DICT_UTIL_H
24#define DICT_UTIL_H
25
26// Includes from nestkernel:
27#include "kernel_manager.h"
28#include "vp_manager_impl.h"
29
30#include "dictionary.h"
31
32namespace nest
33{
40template < typename T >
41bool
42update_value_param( Dictionary const& d, const std::string& key, T& value, nest::Node* node )
43{
44 assert( node != nullptr );
45 const auto it = d.find( key );
46 if ( it != d.end() and std::holds_alternative< std::shared_ptr< nest::Parameter > >( it->second.item ) )
47 {
48 const auto param = d.get< ParameterPTR >( key );
49 const auto vp = kernel().vp_manager.node_id_to_vp( node->get_node_id() );
50 const auto tid = kernel().vp_manager.vp_to_thread( vp );
51 const auto rng = get_vp_specific_rng( tid );
52 value = param->value( rng, node );
53 return true;
54 }
55 else
56 {
57 return d.update_value( key, value );
58 }
59}
60
61} // namespace nest
62
63#endif // DICT_UTIL_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Base class for all NEST network objects.
Definition node.h:99
size_t get_node_id() const
Return global Network ID.
Definition node.h:1200
size_t node_id_to_vp(const size_t node_id) const
Return a thread number for a given global node id.
Definition vp_manager_impl.h:43
size_t vp_to_thread(const size_t vp) const
Convert a given VP ID to the corresponding thread ID.
Definition vp_manager_impl.h:49
VPManager vp_manager
Definition kernel_manager.h:234
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
RngPtr get_vp_specific_rng(size_t tid)
Definition kernel_manager.h:298
KernelManager & kernel()
Definition kernel_manager.h:311
bool update_value_param(Dictionary const &d, const std::string &key, T &value, nest::Node *node)
Obtain value from parameter dictionary including evaluation of random or spatial parameters.
Definition dict_util.h:42
std::shared_ptr< Parameter > ParameterPTR
Definition parameter.h:40