NEST  2.6.0,not_revisioned_source_dir@0
tokenstack.h
Go to the documentation of this file.
1 /*
2  * tokenstack.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 TOKENSTACK_H
24 #define TOKENSTACK_H
25 /*
26  SLI's stack for tokens
27 */
28 
29 #include "token.h"
30 #include "tarrayobj.h"
31 #include "tokenarray.h"
32 
33 /* This stack implementation assumes that functions are only called,
34  if the necessary pre-requisites are fulfilled. The code will break
35  otherwise.
36 */
37 
38 class TokenStack : private TokenArrayObj
39 {
40 public:
42  : TokenArrayObj(0,Token(),n) {}
43  TokenStack(const TokenArray& ta)
44  : TokenArrayObj(ta) {}
45 
48 
49  void clear(void)
50  {
51  erase(begin(),end());
52  }
53 
54 
55  void push(const Token& e)
56  {
57  push_back(e);
58  }
59 
60  void push_move(Token& e)
61  {
62  push_back_move(e);
63  }
64 
70  void push_by_ref(const Token& e)
71  {
73  }
74 
81  {
83  }
84 
85  void pop(void)
86  {
87  pop_back();
88  }
89 
90  void pop_move(Token& e) // new one 5.5.97
91  {
92  e.move(*(end()-1));
93  pop_back();
94  }
95 
96  void pop(size_t n)
97  {
98  erase(end()-n, end());
99  }
100 
101 
102  Token& top(void)
103  {
104  return *(end()-1);
105  }
106  const Token& top(void) const
107  {
108  return *(end()-1);
109  }
110 
111  const Token& pick(size_t i) const
112  {
113  return *(end()-i-1);
114  }
115 
116  Token& pick(size_t i)
117  {
118  return *(end()-i-1);
119  }
120 
121  using TokenArrayObj::empty;
122 // using TokenArray::operator=;
123 
124 
125  void swap(void)
126  {
127  (end()-1)->swap(*(end()-2));
128  }
129 
130  void swap(Token &e)
131  {
132  (end()-1)->swap(e);
133  }
134 
135  void index(Index i)
136  {
137  push(pick(i));
138  }
139 
140  void roll(size_t n, long k)
141  {
142  if ( n < 2 || k == 0 )
143  return; // nothing to do
144 
145  if ( k > 0 )
146  {
147  rotate(end()-n,end()-(k%n),end());
148  }
149  else
150  {
151  rotate(end()-n,end()-(n+k)%n,end());
152  }
153  }
154 
155  Index size(void) const {return TokenArrayObj::capacity();}
156  Index load(void) const {return TokenArrayObj::size();}
157 
158  void dump(std::ostream &) const;
159 
160  TokenArray toArray(void) const
161  {
162  return TokenArray(*this);
163  }
164 
165 };
166 
167 #endif
Token * end() const
Definition: tarrayobj.h:70
Index size(void) const
Definition: tokenstack.h:155
void pop_move(Token &e)
Definition: tokenstack.h:90
void swap(void)
Definition: tokenstack.h:125
size_t capacity(void) const
Definition: tarrayobj.h:80
void swap(Token &e)
Definition: tokenstack.h:130
Token & top(void)
Definition: tokenstack.h:102
void push_back_by_pointer(Datum *rhs)
Push back a datum pointer.
Definition: tarrayobj.h:174
void move(Token &c)
Definition: token.h:142
TokenArray toArray(void) const
Definition: tokenstack.h:160
bool reserve(size_t)
Definition: tarrayobj.cc:197
void push_back_by_ref(const Token &t)
Push back a reference.
Definition: tarrayobj.h:161
void erase(size_t, size_t)
Definition: tarrayobj.cc:261
Definition: tokenstack.h:38
Definition: tarrayobj.h:37
const Token & pick(size_t i) const
Definition: tokenstack.h:111
void pop(void)
Definition: tokenstack.h:85
Definition: tokenarray.h:62
unsigned long Index
Definition: token.h:372
void push_by_pointer(Datum *rhs)
Push a valid datum to the stack.
Definition: tokenstack.h:80
void push_back_move(Token &t)
Definition: tarrayobj.h:147
void dump(std::ostream &) const
Definition: tokenstack.cc:30
void clear(void)
Definition: tokenstack.h:49
size_t size(void) const
Definition: tarrayobj.h:75
void roll(size_t n, long k)
Definition: tokenstack.h:140
void rotate(Token *, Token *, Token *)
Definition: tarrayobj.cc:208
Token * begin() const
Definition: tarrayobj.h:65
TokenStack(const TokenArray &ta)
Definition: tokenstack.h:43
TokenStack(Index n)
Definition: tokenstack.h:41
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
void reserve_token(size_t n)
Definition: tarrayobj.h:134
Index load(void) const
Definition: tokenstack.h:156
Token & pick(size_t i)
Definition: tokenstack.h:116
Definition: datum.h:33
const Token & top(void) const
Definition: tokenstack.h:106
A type-independent container for C++-types.
Definition: token.h:68
void pop(size_t n)
Definition: tokenstack.h:96
void push(const Token &e)
Definition: tokenstack.h:55
void push_move(Token &e)
Definition: tokenstack.h:60
bool empty(void) const
Definition: tarrayobj.h:227
void pop_back(void)
Definition: tarrayobj.h:187
const double e
Definition: numerics.cpp:62
void index(Index i)
Definition: tokenstack.h:135
void push_back(const Token &t)
Definition: tarrayobj.h:140
void push_by_ref(const Token &e)
Push a Token with a valid datum to the stack.
Definition: tokenstack.h:70