NEST  2.6.0,not_revisioned_source_dir@0
gid_collection.h
Go to the documentation of this file.
1 /*
2  * gid_collection.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 GID_COLLECTION_H
24 #define GID_COLLECTION_H
25 
26 #include <vector>
27 #include <ostream>
28 #include <utility>
29 #include <stdexcept>
30 
31 #include "nest.h"
32 #include "tokenarray.h"
33 #include "arraydatum.h"
34 
35 namespace nest {
36 
37  class GIDCollection {
38 
39  std::vector<index> gid_array_;
40  std::pair<index, index> gid_range_;
41  bool is_range_;
42 
43  public:
44 
46  friend class GIDCollection;
47  const_iterator(const GIDCollection* gc, size_t offset) : gc_(gc), offset_(offset) {}
49  size_t offset_;
50  public:
51  index operator*() const;
52  const const_iterator& operator++();
53  bool operator!=(const const_iterator& rhs) const;
54  };
55 
57  GIDCollection(index first, index last);
60 
61  void print_me(std::ostream& out) const;
62 
63  index operator[] (const size_t pos) const;
64  bool operator==(const GIDCollection& rhs) const;
65 
66  const_iterator begin() const;
67  const_iterator end() const;
68 
69  size_t size() const;
70  };
71 
72  inline
74  {
75  return (*gc_)[offset_];
76  }
77 
78  inline
80  {
81  ++offset_;
82  return *this;
83  }
84 
85  inline
87  {
88  return offset_ != rhs.offset_;
89  }
90 
91  inline
92  index GIDCollection::operator[] (const size_t pos) const
93  {
94  if ((is_range_ && pos + gid_range_.first > gid_range_.second) || (!is_range_ && pos >= gid_array_.size()))
95  throw std::out_of_range("pos points outside of the GIDCollection");
96 
97  if (is_range_)
98  return gid_range_.first + pos;
99  else
100  return gid_array_[pos];
101  }
102 
103  inline
105  {
106  if (is_range_)
107  return gid_range_ == rhs.gid_range_;
108  else
109  return gid_array_ == rhs.gid_array_;
110  }
111 
112  inline
114  {
115  return const_iterator(this, 0);
116  }
117 
118  inline
120  {
121  return const_iterator(this, size());
122  }
123 
124  inline
125  size_t GIDCollection::size() const
126  {
127  if (is_range_)
128  return gid_range_.second - gid_range_.first + 1;
129  else
130  return gid_array_.size();
131  }
132 
133 } // namespace nest
134 
135 #endif /* #ifndef GID_COLLECTION_H */
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
Definition: gid_collection.h:45
index operator*() const
Definition: gid_collection.h:73
Definition: lockptrdatum.h:40
const Name offset("offset")
Miscellaneous parameters.
Definition: nest_names.h:211
void print_me(std::ostream &out) const
Definition: gid_collection.cpp:51
const_iterator(const GIDCollection *gc, size_t offset)
Definition: gid_collection.h:47
const GIDCollection * gc_
Definition: gid_collection.h:48
Definition: tokenarray.h:62
std::vector< index > gid_array_
Definition: gid_collection.h:39
const const_iterator & operator++()
Definition: gid_collection.h:79
size_t size() const
Definition: gid_collection.h:125
std::pair< index, index > gid_range_
Definition: gid_collection.h:40
index operator[](const size_t pos) const
Definition: gid_collection.h:92
Definition: gid_collection.h:37
bool operator==(const GIDCollection &rhs) const
Definition: gid_collection.h:104
bool is_range_
Definition: gid_collection.h:41
bool operator!=(const const_iterator &rhs) const
Definition: gid_collection.h:86
Default types used by the NEST kernel.
size_t offset_
Definition: gid_collection.h:49
GIDCollection()
Definition: gid_collection.h:56
const_iterator begin() const
Definition: gid_collection.h:113
const_iterator end() const
Definition: gid_collection.h:119