NEST  2.6.0,not_revisioned_source_dir@0
iteratordatum.h
Go to the documentation of this file.
1 /*
2  * iteratordatum.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 ITERATORDATUM_H
24 #define ITERATORDATUM_H
25 /*
26  Datum template for numeric data types
27 */
28 
29 
30 // this file is based on numericdatum.h and integerdatum.h
31 
32 #include "genericdatum.h"
33 #include "allocator.h"
34 #include "interpret.h"
35 #include <iostream>
36 
37 
38 // prefixed all references to members of GenericDatum with this->,
39 // since HP's aCC otherwise complains about them not being declared
40 // according to ISO Standard Sec. 14.6.2(3) [temp.dep]
41 // HEP, 2001-08-08
42 
44 {
45  public:
46  long start;
47  long stop;
48  long di;
49  long pos;
50 
51  bool operator==(const IteratorState &i) const
52  {
53  return stop == i.stop
54  && start == i.start
55  && di == i.di
56  && pos == i.pos;
57  }
58 
59 };
60 
61 
62 std::ostream& operator<<(std::ostream&, const IteratorState &);
63 
64 
65 
66 
67 class IteratorDatum: public GenericDatum<IteratorState,&SLIInterpreter::Iteratortype>
68 {
69  protected:
70  static sli::pool memory;
71 
72 private:
73  Datum *clone(void) const
74  {
75  return new IteratorDatum(*this);
76  }
77 
78 public:
79 
80 
81  // IteratorDatum(start,stop,di));
82 
83  IteratorDatum() { this->d.start = 0; this->d.stop = 0; this->d.di = 0; this->d.pos = 0;}
84  IteratorDatum(long start_s, long stop_s, long di_s)
85  { this->d.start = start_s; this->d.stop = stop_s; this->d.di = di_s; this->d.pos = start_s;}
86  IteratorDatum(const IteratorDatum& d_s):GenericDatum<IteratorState,&SLIInterpreter::Iteratortype>(d_s) {this->d=d_s.d;}
87  virtual ~IteratorDatum() {}
88 
89 
90 
91  void incr(void)
92  {
93  this->d.pos+=this->d.di;
94  }
95 
96  void decr(void)
97  {
98  this->d.pos-=this->d.di;
99  }
100 
101  long begin(void)
102  {
103  return this->d.start;
104  }
105 
106  long end(void)
107  {
108  return this->d.stop + 1;
109  }
110 
111  long pos(void)
112  {
113  return this->d.pos;
114  }
115 
116  long size(void)
117  {
118  return (this->d.stop - this->d.start)/this->d.di + 1;
119  }
120 
121  bool operator==(const IteratorDatum &i) const
122  {
123  return this->d == i.d;
124 
125  }
126 
127  static void * operator new(size_t size)
128  {
129  if(size != memory.size_of())
130  return ::operator new(size);
131  return memory.alloc();
132  }
133 
134  static void operator delete(void *p, size_t size)
135  {
136  if(p == NULL)
137  return;
138  if(size != memory.size_of())
139  {
140  ::operator delete(p);
141  return;
142  }
143  memory.free(p);
144  }
145 
146  void print(std::ostream &out) const { out << '<'<< this->gettypename()<<'>';}
147 
148  void pprint(std::ostream &out) const { out << this->d; }
149 };
150 
151 
152 
153 
154 #endif
size_t size_of(void) const
Definition: allocator.h:128
void incr(void)
Definition: iteratordatum.h:91
Datum * clone(void) const
Virtual copy constructor.
Definition: iteratordatum.h:73
Definition: genericdatum.h:35
IteratorDatum(long start_s, long stop_s, long di_s)
Definition: iteratordatum.h:84
long pos
Definition: iteratordatum.h:49
long pos(void)
Definition: iteratordatum.h:111
void pprint(std::ostream &out) const
Definition: iteratordatum.h:148
Definition: iteratordatum.h:43
long stop
Definition: iteratordatum.h:47
std::ostream & operator<<(std::ostream &, const IteratorState &)
Definition: iteratordatum.cc:35
IteratorState d
Definition: genericdatum.h:44
long start
Definition: iteratordatum.h:46
virtual ~IteratorDatum()
Definition: iteratordatum.h:87
long di
Definition: iteratordatum.h:48
long begin(void)
Definition: iteratordatum.h:101
long end(void)
Definition: iteratordatum.h:106
void print(std::ostream &out) const
Definition: iteratordatum.h:146
Definition: iteratordatum.h:67
Definition: interpret.h:69
const Name & gettypename(void) const
Definition: datum.h:148
void * alloc(void)
allocate one element
Definition: allocator.h:137
bool operator==(const IteratorDatum &i) const
Definition: iteratordatum.h:121
IteratorDatum()
Definition: iteratordatum.h:83
void free(void *p)
put element back into the pool
Definition: allocator.h:155
long size(void)
Definition: iteratordatum.h:116
bool operator==(const IteratorState &i) const
Definition: iteratordatum.h:51
IteratorDatum(const IteratorDatum &d_s)
Definition: iteratordatum.h:86
void decr(void)
Definition: iteratordatum.h:96
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Definition: datum.h:33
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
static sli::pool memory
Definition: iteratordatum.h:70