NEST  2.6.0,not_revisioned_source_dir@0
multirange.h
Go to the documentation of this file.
1 /*
2  * multirange.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 MULTIRANGE_H
24 #define MULTIRANGE_H
25 
26 #include <vector>
27 #include <utility>
28 #include "nest.h"
29 
30 namespace nest {
31 
35  class Multirange
36  {
37  public:
38  typedef std::pair<index,index> Range;
39  typedef std::vector<Range> RangeVector;
40 
41  class iterator {
42  public:
43  iterator(RangeVector::const_iterator iter, index n);
44  index operator*() const;
45  bool operator!=(const iterator& other) const;
47  iterator operator++(int);
48 
49  private:
50  RangeVector::const_iterator pair_iter_;
52  };
53 
54  Multirange();
55  void push_back(index x);
56  void clear();
57  index operator[](index n) const;
58  index size() const;
59  bool empty() const;
60  iterator begin() const;
61  iterator end() const;
62 
63  private:
66  };
67 
68  inline
70  ranges_(), size_(0)
71  {
72  }
73 
74  inline
76  {
77  if ((not ranges_.empty()) && (ranges_.back().second+1 == x)) {
78  ++ranges_.back().second;
79  } else {
80  ranges_.push_back(Range(x,x));
81  }
82  ++size_;
83  }
84 
85  inline
87  {
88  ranges_.clear();
89  size_ = 0;
90  }
91 
92  inline
94  {
95  return size_;
96  }
97 
98  inline
99  bool Multirange::empty() const
100  {
101  return size_ == 0;
102  }
103 
104  inline
105  Multirange::iterator::iterator(RangeVector::const_iterator iter, index n):
106  pair_iter_(iter), n_(n)
107  {
108  }
109 
110  inline
112  {
113  return (other.pair_iter_ != pair_iter_) || (other.n_ != n_);
114  }
115 
116  inline
118  {
119  return pair_iter_->first + n_;
120  }
121 
122  inline
124  {
125  ++n_;
126  if (n_ > pair_iter_->second-pair_iter_->first) {
127  ++pair_iter_;
128  n_ = 0;
129  }
130  return *this;
131  }
132 
133  inline
135  {
136  iterator tmp=*this;
137  ++(*this);
138  return tmp;
139  }
140 
141  inline
143  {
144  return Multirange::iterator(ranges_.begin(),0);
145  }
146 
147  inline
149  {
150  return Multirange::iterator(ranges_.end(),0);
151  }
152 
153 
154 } // namespace
155 
156 #endif
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
Definition: multirange.h:41
RangeVector ranges_
Definition: multirange.h:64
std::vector< Range > RangeVector
Definition: multirange.h:39
Multirange()
Definition: multirange.h:69
index size_
Definition: multirange.h:65
iterator end() const
Definition: multirange.h:148
index operator[](index n) const
Definition: multirange.cpp:26
void push_back(index x)
Definition: multirange.h:75
iterator(RangeVector::const_iterator iter, index n)
Definition: multirange.h:105
index size() const
Definition: multirange.h:93
iterator & operator++()
Definition: multirange.h:123
RangeVector::const_iterator pair_iter_
Definition: multirange.h:50
const Name other("other")
Node type.
Definition: nest_names.h:216
bool empty() const
Definition: multirange.h:99
index operator*() const
Definition: multirange.h:117
const Name x("x")
current scaling factor of the synaptic weight [0...1] (Tsodyks2_connection)
Definition: nest_names.h:356
std::pair< index, index > Range
Definition: multirange.h:38
index n_
Definition: multirange.h:51
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
Default types used by the NEST kernel.
Class for sequences of ranges acting like a compressed vector.
Definition: multirange.h:35
iterator begin() const
Definition: multirange.h:142
bool operator!=(const iterator &other) const
Definition: multirange.h:111
void clear()
Definition: multirange.h:86