21 #ifndef GNASH_SAFESTACK_H 22 #define GNASH_SAFESTACK_H 44 typedef std::vector<T*> StackType;
58 const StackSize offset = _end -
i;
59 return _data[offset >> _chunkShift][offset & _chunkMod];
70 const StackSize offset = _end -
i;
71 return _data[offset >> _chunkShift][offset & _chunkMod];
77 const T&
at(StackSize
i)
const 81 const StackSize offset = _end -
i;
82 return _data[offset >> _chunkShift][offset & _chunkMod];
94 const StackSize offset = _end -
i;
95 return _data[offset >> _chunkShift][offset & _chunkMod];
104 StackSize offset = _downstop + i + 2;
105 return _data[offset >> _chunkShift][offset & _chunkMod];
112 StackSize offset = _downstop + i + 2;
113 return _data[offset >> _chunkShift][offset & _chunkMod];
121 StackSize offset = _downstop + i + 2;
122 _data[offset >> _chunkShift][offset & _chunkMod] = val;
157 StackSize available = (1 << _chunkShift) * _data.size() - _end + 1;
158 StackSize
n = size()+
i;
159 while (available < n)
162 _data.push_back(
new T[1 << _chunkShift]);
163 available += 1 << _chunkShift;
175 StackSize
size()
const {
return _end - _downstop - 1; }
178 bool empty()
const {
return size() == 0; }
185 StackSize ret = _downstop;
186 _downstop = _end - 1;
209 _downstop = downstop;
218 for (
auto& elem : _data)
delete [] elem;
227 static const StackSize _chunkShift = 6;
228 static const StackSize _chunkMod = (1 << _chunkShift) - 1;
T & at(StackSize i)
From the top of the stack, get the i'th value down.
Definition: SafeStack.h:90
void setAllSizes(StackSize total, StackSize downstop)
Definition: SafeStack.h:206
void assign(StackSize i, T val)
Assign a value to given index counting from bottom.
Definition: SafeStack.h:117
void clear()
Drop all stack elements reguardless of the "downstop".
Definition: SafeStack.h:134
void setDownstop(StackSize i)
Definition: SafeStack.h:192
T & top(StackSize i)
From the top of the stack, get the i'th value down.
Definition: SafeStack.h:66
StackType::size_type StackSize
Definition: SafeStack.h:49
SafeStack()
Default constructor.
Definition: SafeStack.h:213
~SafeStack()
Delete the allocated data.
Definition: SafeStack.h:216
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: SafeStack.h:41
Definition: GnashKey.h:160
const T & value(StackSize i) const
Definition: SafeStack.h:108
void grow(StackSize i)
Definition: SafeStack.h:155
Definition: GnashKey.h:166
Definition: SafeStack.h:29
const T & top(StackSize i) const
From the top of the stack, get the i'th value down.
Definition: SafeStack.h:54
StackSize getDownstop() const
Gives the size of the stack which is currently accessible.
Definition: SafeStack.h:169
T & value(StackSize i)
Definition: SafeStack.h:100
T & pop()
Pop the top of the stack.
Definition: SafeStack.h:147
void drop(StackSize i)
Definition: SafeStack.h:128
Definition: GnashKey.h:132
Definition: GnashKey.h:155
void push(const T &t)
Definition: SafeStack.h:141
const T & at(StackSize i) const
From the top of the stack, get the i'th value down.
Definition: SafeStack.h:77
StackSize fixDownstop()
Definition: SafeStack.h:183
bool empty() const
Is the stack empty to us? (Check totalSize() != for actually empty)
Definition: SafeStack.h:178
StackSize totalSize() const
Return the complete stack size, including non-accessible elements.
Definition: SafeStack.h:202
StackSize size() const
Alias for getDownstop()
Definition: SafeStack.h:175