NEST  2.6.0,not_revisioned_source_dir@0
genericmodel.h
Go to the documentation of this file.
1 /*
2  * genericmodel.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 GENERICMODEL_H
24 #define GENERICMODEL_H
25 
26 #include "model.h"
27 #include "dynmodule.h"
28 #include <new>
29 
30 namespace nest
31 {
41  template <typename ElementT>
42  class GenericModel: public Model
43  {
44  public:
45  GenericModel(const std::string &);
46  GenericModel(const char[]);
47 
51  GenericModel(const GenericModel&, const std::string&);
52 
56  Model* clone(const std::string&) const;
57 
58  bool has_proxies();
60  bool one_node_per_process();
61  bool is_off_grid();
77 
78  Node const & get_prototype() const;
79 
80  void set_model_id(int);
81 
82  private:
83 
86 
87  size_t get_element_size() const;
88 
92  Node* allocate_(void *);
93 
97  void init_memory_(sli::pool &);
98 
102  ElementT proto_;
103  };
104 
105  template< typename ElementT>
106  GenericModel<ElementT>::GenericModel(const std::string &name)
107  : Model(name),
108  proto_()
109  {
110  set_threads();
111  }
112 
113  template< typename ElementT>
115  : Model(std::string(name)),
116  proto_()
117  {
118  set_threads();
119  }
120 
121  template <typename ElementT>
123  const std::string& newname)
124  : Model(newname),
125  proto_(oldmod.proto_)
126  {
127  set_type_id(oldmod.get_type_id());
128  set_threads();
129  }
130 
131  template <typename ElementT>
132  Model* GenericModel<ElementT>::clone(const std::string& newname) const
133  {
134  return new GenericModel(*this, newname);
135  }
136 
137  template< typename ElementT>
139  {
140  Node *n = new(adr) ElementT(proto_);
141  return n;
142  }
143 
144  template< typename ElementT>
146  {
147  mem.init(sizeof(ElementT), 1000, 1);
148  }
149 
150  template <typename ElementT>
151  inline
153  {
154  return proto_.has_proxies();
155  }
156 
157  template <typename ElementT>
158  inline
160  {
161  return proto_.potential_global_receiver();
162  }
163 
164  template <typename ElementT>
165  inline
167  {
168  return proto_.one_node_per_process();
169  }
170 
171  template <typename ElementT>
172  inline
174  {
175  return proto_.is_off_grid();
176  }
177 
178  template <typename ElementT>
179  inline
180  port GenericModel<ElementT>::send_test_event(Node& target, rport receptor, synindex syn_id, bool dummy_target)
181  {
182  return proto_.send_test_event(target, receptor, syn_id, dummy_target);
183  }
184 
185  template <typename ElementT>
187  {
188  proto_.set_status(d);
189  }
190 
191  template <typename ElementT>
193  {
194  DictionaryDatum d = proto_.get_status_base();
195  (*d)["elementsize"]= sizeof(ElementT);
196  return d;
197  }
198 
199  template <typename ElementT>
201  {
202  return sizeof(ElementT);
203  }
204 
205  template <typename ElementT>
207  {
208  return proto_;
209  }
210 
211  template <typename ElementT>
213  {
214  proto_.set_model_id(i);
215  }
216 
217 
229  template <class ModelT>
230  index register_model(Network& net, const std::string &name,
231  bool private_model = false)
232  {
233  Model* prototype = new GenericModel<ModelT>(name);
234  assert(prototype != 0);
235  return net.register_model(*prototype, private_model);
236  }
237 
256  template <class ModelT>
257  index register_preconf_model(Network& net, const std::string &name,
258  Dictionary& conf, bool private_model = false)
259  {
260  Model* prototype = new GenericModel<ModelT>(name);
261  assert(prototype != 0);
262  conf.clear_access_flags();
263  prototype->set_status(conf);
264  std::string missed;
265  assert(conf.all_accessed(missed)); // we only get here from C++ code, no need for exception
266  return net.register_model(*prototype, private_model);
267  }
268 
281  template <class ModelT>
282  index register_private_model(Network& net, const std::string &name)
283  {
284  return register_model<ModelT>(net, name, true);
285  }
286 }
287 #endif
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
size_t get_element_size() const
Return the size of the prototype.
Definition: genericmodel.h:200
index register_preconf_model(Network &net, const std::string &name, Dictionary &conf, bool private_model=false)
Register a pre-configured model prototype with the network.
Definition: genericmodel.h:257
index get_type_id() const
Definition: model.h:174
bool is_off_grid()
Definition: genericmodel.h:173
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
void init(size_t n, size_t initial=100, size_t growth=1)
Definition: allocator.cpp:65
bool all_accessed(std::string &missed) const
Check whether all elements have been accessed.
Definition: dict.h:161
index register_model(Network &net, const std::string &name, bool private_model=false)
Register a model prototype with the network.
Definition: genericmodel.h:230
bool has_proxies()
Definition: genericmodel.h:152
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
assert(pNet!=0)
void init_memory_(sli::pool &)
Initialize the pool allocator with the node specific properties.
Definition: genericmodel.h:145
void set_model_id(int)
Set the model id on the prototype.
Definition: genericmodel.h:212
const Name std("std")
Miscellaneous parameters.
Definition: nest_names.h:265
A class that associates names and tokens.
Definition: dict.h:45
DictionaryDatum get_status_()
Definition: genericmodel.h:192
ElementT proto_
Prototype node from which all instances are constructed.
Definition: genericmodel.h:102
Node * allocate_(void *)
Call placement new on the supplied memory position.
Definition: genericmodel.h:138
void clear_access_flags()
Clear access flags on all dictionary elements.
Definition: dict.cc:142
port send_test_event(Node &, rport, synindex, bool)
Definition: genericmodel.h:180
void set_threads()
Set number of threads based on number set in network.
Definition: model.cpp:39
bool one_node_per_process()
Definition: genericmodel.h:166
const Name target("target")
Connection parameters.
Definition: nest_names.h:282
Base class for all Models.
Definition: model.h:48
void set_status(DictionaryDatum)
Change properties of the prototype node according to the entries in the dictionary.
Definition: model.cpp:88
Main administrative interface to the network.
Definition: network.h:135
Generic Model template.
Definition: genericmodel.h:42
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
void set_type_id(index id)
Set the model id on the prototype.
Definition: model.h:169
unsigned char synindex
Unsigned char type for enumerations of synapse types.
Definition: nest.h:115
Model * clone(const std::string &) const
Return pointer to cloned model with same name.
Definition: genericmodel.h:132
Node const & get_prototype() const
Return const reference to the prototype.
Definition: genericmodel.h:206
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
index register_private_model(Network &net, const std::string &name)
Register a private model prototype with the network.
Definition: genericmodel.h:282
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Base class for all NEST network objects.
Definition: node.h:96
bool potential_global_receiver()
Definition: genericmodel.h:159
void set_status_(DictionaryDatum)
Definition: genericmodel.h:186
index register_model(Model &m, bool private_model=false)
Register a built-in model for use with the network.
Definition: network.cpp:1744
GenericModel(const std::string &)
Definition: genericmodel.h:106