NEST  2.6.0,not_revisioned_source_dir@0
model.h
Go to the documentation of this file.
1 /*
2  * model.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 MODEL_H
24 #define MODEL_H
25 #include <string>
26 
27 #include <new>
28 #include <vector>
29 #include "node.h"
30 #include "allocator.h"
31 #include "dictutils.h"
32 
33 namespace nest
34 {
35 
48  class Model
49  {
50  public:
51 
52  Model(const std::string& name);
53  Model(const Model& m):
54  name_(m.name_),
55  type_id_(m.type_id_),
56  memory_(m.memory_)
57  {}
58 
59  virtual ~Model(){}
60 
64  virtual Model* clone(const std::string&) const =0;
65 
72  void set_threads();
73 
80  Node* allocate(thread t);
81 
82  void free(thread t, Node *);
83 
88  void clear();
89 
99  void reserve_additional(thread t, size_t n);
100 
109  std::string get_name() const;
110 
116  size_t mem_available();
117 
123  size_t mem_capacity();
124 
125  virtual bool has_proxies()=0;
126  virtual bool potential_global_receiver()=0;
127  virtual bool one_node_per_process()=0;
128  virtual bool is_off_grid()=0;
129 
137 
145 
146  virtual port send_test_event(Node&, rport, synindex, bool)=0;
147 
151  virtual
152  size_t get_element_size() const=0;
153 
157  virtual
158  Node const& get_prototype(void) const =0;
159 
163  virtual
164  void set_model_id(int) =0;
165 
170  {
171  type_id_=id;
172  }
173 
175  {
176  return type_id_;
177  }
178 
179  private:
180 
181  virtual
183 
184  virtual
186 
187 
192  void set_threads_(thread t);
193 
197  virtual
198  void init_memory_(sli::pool &)=0;
199 
203  virtual
204  Node * allocate_(void *)=0;
205 
211  std::string name_;
212 
220 
224  std::vector<sli::pool> memory_;
225 
226  };
227 
228 
229  inline
231  {
232  assert((size_t)t < memory_.size());
233  return allocate_(memory_[t].alloc());
234  }
235 
236  inline
238  {
239  assert((size_t)t < memory_.size());
240  memory_[t].free(n);
241  }
242 
243  inline
244  std::string Model::get_name() const
245  {
246  return name_;
247  }
248 
249 }
250 #endif
251 
252 
253 
254 
255 
256 
257 
258 
259 
260 
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
index get_type_id() const
Definition: model.h:174
virtual ~Model()
Definition: model.h:59
Definition: lockptrdatum.h:40
Declarations for base class Node.
void set_threads_(thread t)
Set the number of threads.
Definition: model.cpp:44
std::string name_
Name of the Model.
Definition: model.h:211
virtual void set_status_(DictionaryDatum)=0
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
DictionaryDatum get_status(void)
Export properties of the prototype node by setting entries in the status dictionary.
Definition: model.cpp:100
assert(pNet!=0)
virtual bool has_proxies()=0
virtual bool potential_global_receiver()=0
virtual Model * clone(const std::string &) const =0
Create clone with new name.
Model(const std::string &name)
Definition: model.cpp:33
Model(const Model &m)
Definition: model.h:53
virtual DictionaryDatum get_status_()=0
std::string get_name() const
Return name of the Model.
Definition: model.h:244
size_t mem_capacity()
Return the memory capacity.
Definition: model.cpp:79
void set_threads()
Set number of threads based on number set in network.
Definition: model.cpp:39
virtual bool one_node_per_process()=0
Node * allocate(thread t)
Allocate new Node and return its pointer.
Definition: model.h:230
Base class for all Models.
Definition: model.h:48
virtual void set_model_id(int)=0
Set the model id on the prototype.
void set_status(DictionaryDatum)
Change properties of the prototype node according to the entries in the dictionary.
Definition: model.cpp:88
void clear()
Deletes all nodes which belong to this model.
Definition: model.cpp:63
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
void free(thread t, Node *)
Definition: model.h:237
virtual port send_test_event(Node &, rport, synindex, bool)=0
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
std::vector< sli::pool > memory_
Memory for all nodes sorted by threads.
Definition: model.h:224
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
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
virtual void init_memory_(sli::pool &)=0
Initialize the pool allocator with the Node specific values.
virtual Node * allocate_(void *)=0
Allocate a new object at the specified memory position.
index type_id_
Identifier of the model C++ type.
Definition: model.h:219
virtual Node const & get_prototype(void) const =0
Return const reference to the prototype.
size_t mem_available()
Return the available memory.
Definition: model.cpp:70
void reserve_additional(thread t, size_t n)
Reserve memory for at least n additional Nodes.
Definition: model.cpp:57
int_t thread
Thread index type.
Definition: nest.h:133
virtual bool is_off_grid()=0
virtual size_t get_element_size() const =0
Return the size of the prototype.