NEST  2.6.0,not_revisioned_source_dir@0
nodelist.h
Go to the documentation of this file.
1 /*
2  * nodelist.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 NODELIST_H
24 #define NODELIST_H
25 
26 #include "node.h"
27 #include "subnet.h"
28 
29 namespace nest{
30 
51 template <typename ListIterator>
53 {
54 public:
55  typedef ListIterator iterator;
56 
57  explicit LocalNodeListBase(Subnet &subnet) : subnet_(subnet) {}
58 
63  iterator begin() const;
64 
71  iterator end() const { return iterator(subnet_.local_end(),
72  subnet_.local_end()); }
73 
75  bool empty() const { return subnet_.local_empty(); }
76 
78  Subnet& get_subnet() const { return subnet_; }
79 
80 private:
82 };
83 
84 
85 // ----------------------------------------------------------------------------
86 
91 {
93  friend class LocalLeafListIterator;
94 
95  private:
97  LocalNodeListIterator(std::vector<Node*>::iterator const &node,
98  std::vector<Node*>::iterator const &list_end) :
99  current_node_(node), list_end_(list_end) {}
100  bool is_end_() const { return current_node_ == list_end_; }
101 
102  public:
104 
105  Node* operator*() { return *current_node_; }
106  Node const* operator*() const { return *current_node_; }
107 
108  bool operator==(const LocalNodeListIterator& i) const { return current_node_ == i.current_node_; }
109  bool operator!=(const LocalNodeListIterator& i) const { return not ( *this == i ); }
110 
111  private:
113  vector<Node *>::iterator current_node_;
114  vector<Node *>::iterator list_end_;
115 
116 };
117 
118 
119 // ----------------------------------------------------------------------------
120 
121 template <>
124 
129 
130 // ----------------------------------------------------------------------------
131 
136 {
138 
139  private:
141  LocalChildListIterator(std::vector<Node*>::iterator const &node,
142  std::vector<Node*>::iterator const &list_end) :
143  current_node_(node), list_end_(list_end) {}
144 
145  public:
147 
148  Node* operator*() { return *current_node_; }
149  Node const* operator*() const { return *current_node_; }
150 
151  bool operator==(const LocalChildListIterator& i) const { return current_node_ == i.current_node_; }
152  bool operator!=(const LocalChildListIterator& i) const { return not ( *this == i ); }
153 
154  private:
156  vector<Node *>::iterator current_node_;
157  vector<Node *>::iterator list_end_;
158 };
159 
160 template <>
163 
168 
169 // ----------------------------------------------------------------------------
170 
177 {
179 
180  private:
182  LocalLeafListIterator(std::vector<Node*>::iterator const &node,
183  std::vector<Node*>::iterator const &list_end) :
184  base_it_(node, list_end)
185  {
186  while ( not base_it_.is_end_() && not is_leaf_(*base_it_) )
187  ++base_it_;
188  }
189 
190  public:
192 
193  Node* operator*() { return *base_it_; }
194  Node const* operator*() const { return *base_it_; }
195 
196  bool operator==(const LocalLeafListIterator& i) const { return base_it_ == i.base_it_; }
197  bool operator!=(const LocalLeafListIterator& i) const { return not ( *this == i ); }
198 
199  private:
200  LocalNodeListIterator base_it_; //<! we use this one for the basic iteration
201 
202  static bool is_leaf_(Node *n) { return not dynamic_cast<Subnet*>(n); }
203 
204 };
205 
206 template <>
207  LocalNodeListBase<LocalLeafListIterator>::iterator
209 
216 
217 }
218 #endif
vector< Node * >::iterator local_end()
Return iterator to the end of the local child-list.
Definition: subnet.h:246
static bool is_leaf_(Node *n)
Definition: nodelist.h:202
bool operator!=(const LocalNodeListIterator &i) const
Definition: nodelist.h:109
Base class for all subnet nodes.
Definition: subnet.h:67
iterator end() const
Return iterator pointing to node past last node.
Definition: nodelist.h:71
Declarations for base class Node.
LocalChildListIterator operator++()
Definition: nodelist.cpp:137
LocalNodeListIterator operator++()
NodeList::iterator::operator++() Operator++ advances the iterator to the right neighbor in a post-ord...
Definition: nodelist.cpp:81
LocalChildListIterator(std::vector< Node * >::iterator const &node, std::vector< Node * >::iterator const &list_end)
Create iterator from pointer to Node in subnet.
Definition: nodelist.h:141
LocalNodeListBase(Subnet &subnet)
Definition: nodelist.h:57
Node const * operator*() const
Definition: nodelist.h:194
vector< Node * >::iterator current_node_
iterator to the current node in subnet
Definition: nodelist.h:156
bool operator==(const LocalLeafListIterator &i) const
Definition: nodelist.h:196
Node const * operator*() const
Definition: nodelist.h:149
LocalNodeListIterator(std::vector< Node * >::iterator const &node, std::vector< Node * >::iterator const &list_end)
Create iterator from pointer to Node in subnet.
Definition: nodelist.h:97
Iterator for post-order traversal of all local nodes in a subnet.
Definition: nodelist.h:90
bool local_empty() const
returns true if subnet has no local nodes
Definition: subnet.h:264
bool operator==(const LocalNodeListIterator &i) const
Definition: nodelist.h:108
Iterator for traversal of only local leaf nodes in a subnet.
Definition: nodelist.h:176
vector< Node * >::iterator current_node_
iterator to the current node in subnet
Definition: nodelist.h:113
vector< Node * >::iterator list_end_
Definition: nodelist.h:157
Node * operator*()
Definition: nodelist.h:193
bool empty() const
Returns true if no local nodes.
Definition: nodelist.h:75
LocalNodeListBase< LocalLeafListIterator > LocalLeafList
List interface to subnet providing iteration over local leaf nodes.
Definition: nodelist.h:215
bool operator!=(const LocalLeafListIterator &i) const
Definition: nodelist.h:197
LocalNodeListBase< LocalChildListIterator > LocalChildList
List interface to subnet providing iteration over immediate local child nodes.
Definition: nodelist.h:167
Iterator for traversal of all local immediate child nodes in a subnet.
Definition: nodelist.h:135
LocalNodeListBase< LocalNodeListIterator > LocalNodeList
List interface to subnet providing iteration over all local nodes.
Definition: nodelist.h:128
bool operator!=(const LocalChildListIterator &i) const
Definition: nodelist.h:152
ListIterator iterator
Definition: nodelist.h:55
LocalLeafListIterator(std::vector< Node * >::iterator const &node, std::vector< Node * >::iterator const &list_end)
Create iterator from pointer to Node in subnet.
Definition: nodelist.h:182
Node * operator*()
Definition: nodelist.h:105
Node const * operator*() const
Definition: nodelist.h:106
LocalLeafListIterator operator++()
Definition: nodelist.cpp:168
vector< Node * >::iterator list_end_
Definition: nodelist.h:114
Subnet & get_subnet() const
Returns subnet wrapped by NodeList.
Definition: nodelist.h:78
Subnet & subnet_
root of the network
Definition: nodelist.h:81
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
Base class for all NEST network objects.
Definition: node.h:96
Template for list interface to network tree.
Definition: nodelist.h:52
Node * operator*()
Definition: nodelist.h:148
bool operator==(const LocalChildListIterator &i) const
Definition: nodelist.h:151
iterator begin() const
Return iterator pointing to first node in subnet.
bool is_end_() const
Definition: nodelist.h:100
LocalNodeListIterator base_it_
Definition: nodelist.h:200