NEST main@caf0ae8
 
Loading...
Searching...
No Matches
recordables_map.h
Go to the documentation of this file.
1/*
2 * recordables_map.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 RECORDABLES_MAP_H
24#define RECORDABLES_MAP_H
25
26// C++ includes:
27#include <cassert>
28#include <map>
29#include <string>
30#include <utility>
31
32// Includes from nestkernel:
33#include "nest_types.h"
34
35namespace nest
36{
59template < typename HostNode >
60class RecordablesMap : public std::map< std::string, double ( HostNode::* )() const >
61{
62 typedef std::map< std::string, double ( HostNode::* )() const > Base_;
63
64public:
66 {
67 }
68
70 typedef double ( HostNode::*DataAccessFct )() const;
71
79 void create();
80
89 std::vector< std::string >
90 get_list() const
91 {
92 std::vector< std::string > recordables;
93 for ( typename Base_::const_iterator it = this->begin(); it != this->end(); ++it )
94 {
95 recordables.push_back( it->first );
96 }
97 return recordables;
98
99 // the entire function should just be
100 // return recordables_;
101 }
102
103private:
105 void
106 insert_( const std::string& n, const DataAccessFct f )
107 {
108 Base_::insert( std::make_pair( n, f ) );
109
110 // Line below leads to seg-fault if nest is quit right after start,
111 // see comment on get_list()
112 // recordables_.push_back(n);
113 }
114
122 // std::vector< std::string > recordables_;
123};
124
125template < typename HostNode >
126void
128{
129 assert( false );
130}
131
132
134template < typename HostNode >
136{
137 // Pointer instead of reference required to avoid problems with
138 // copying element in std::map when using libc++ under C++11.
139 HostNode* parent_;
140 size_t elem_;
141
142public:
143 DataAccessFunctor( HostNode& n, size_t elem )
144 : parent_( &n )
145 , elem_( elem ) {};
146
147 double
149 {
150 return parent_->get_state_element( elem_ );
151 };
152};
153
154
168template < typename HostNode >
169class DynamicRecordablesMap : public std::map< std::string, const DataAccessFunctor< HostNode > >
170{
171 typedef std::map< std::string, const DataAccessFunctor< HostNode > > Base_;
172
173public:
175 {
176 }
177
180
188 void create( HostNode& n );
189
198 std::vector< std::string >
199 get_list() const
200 {
201 std::vector< std::string > recordables;
202 for ( typename Base_::const_iterator it = this->begin(); it != this->end(); ++it )
203 {
204 recordables.push_back( it->first );
205 }
206 return recordables;
207 }
208
210 void
211 insert( const std::string& n, const DataAccessFct& f )
212 {
213 Base_::insert( std::make_pair( n, f ) );
214 }
215
218 void
219 erase( const std::string& n )
220 {
221 typename DynamicRecordablesMap< HostNode >::iterator it = this->find( n );
222 // If the string is not in the map, throw an error
223 if ( it == this->end() )
224 {
225 throw KeyError( n, "DynamicRecordablesMap", "erase" );
226 }
227
228 Base_::erase( it );
229 }
230};
231
232template < typename HostNode >
233void
235{
236 assert( false );
237}
238}
239
240#endif
Class that reads out state vector elements, used by UniversalDataLogger.
Definition recordables_map.h:136
HostNode * parent_
Definition recordables_map.h:139
double operator()() const
Definition recordables_map.h:148
DataAccessFunctor(HostNode &n, size_t elem)
Definition recordables_map.h:143
size_t elem_
Definition recordables_map.h:140
Map names of recordables to DataAccessFunctors.
Definition recordables_map.h:170
void insert(const std::string &n, const DataAccessFct &f)
Insertion functions to be used in create(), adds entry to map and list.
Definition recordables_map.h:211
std::vector< std::string > get_list() const
Obtain list of all recordables, for use by get_status().
Definition recordables_map.h:199
virtual ~DynamicRecordablesMap()
Definition recordables_map.h:174
std::map< std::string, const DataAccessFunctor< HostNode > > Base_
Definition recordables_map.h:171
void create(HostNode &n)
Create the map.
Definition recordables_map.h:234
void erase(const std::string &n)
Erase functions to be used when setting state, removes entry from map and list.
Definition recordables_map.h:219
DataAccessFunctor< HostNode > DataAccessFct
Datatype for access callable.
Definition recordables_map.h:179
Exception to be thrown if when trying to delete an entry from DynamicRecordablesMap that does not exi...
Definition exceptions.h:1187
Map names of recordables to data access functions.
Definition recordables_map.h:61
virtual ~RecordablesMap()
Definition recordables_map.h:65
void create()
Create the map.
Definition recordables_map.h:127
double(HostNode::* DataAccessFct)() const
Datatype for access functions.
Definition recordables_map.h:70
std::map< std::string, double(HostNode::*)() const > Base_
Definition recordables_map.h:62
std::vector< std::string > get_list() const
Obtain list of all recordables, for use by get_status().
Definition recordables_map.h:90
void insert_(const std::string &n, const DataAccessFct f)
Insertion functions to be used in create(), adds entry to map and list.
Definition recordables_map.h:106
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
long find(const NodeCollectionPTR nc, size_t node_id)
Definition nest.cpp:404