28template <
class contents>
112template <
class contents>
114: _store(elements >= 0? elements : 0),
115 _kind(_store.length()? BOUNDED : UNBOUNDED),
119template <
class contents>
121: _store(0), _valid_fields(0)
126template <
class contents>
129template <
class contents>
132 while (pop() == basis::common::OKAY) {}
135template <
class contents>
138template <
class contents>
141 if (_kind == BOUNDED) {
142 if (_valid_fields >= elements())
return basis::common::IS_FULL;
144 if (result != basis::common::OKAY)
return basis::common::IS_FULL;
145 }
else _store.concatenate(element);
147 return basis::common::OKAY;
150template <
class contents>
153 if (_valid_fields < 1)
return basis::common::IS_EMPTY;
154 if (_kind == UNBOUNDED)
155 _store.zap(_store.length() - 1, _store.length() - 1);
157 return basis::common::OKAY;
160template <
class contents>
162{
return _store[_valid_fields - 1]; }
164template <
class contents>
167 if (
this == &to_copy)
return *
this;
169 _kind = to_copy._kind;
170 _store.reset(to_copy._store.length());
171 for (
int i = 0; i < to_copy._store.length(); i++)
172 _store.put(i, to_copy._store[i]);
173 _valid_fields = to_copy._valid_fields;
177template <
class contents>
180 for (
int i = 0; i < _store.length() / 2; i++) {
181 contents hold = _store.get(i);
182 int exchange_index = _store.length() - i - 1;
183 _store.put(i, _store.get(exchange_index));
184 _store.put(exchange_index, hold);
188template <
class contents>
191 if (index >= _valid_fields) index = -1;
192 return _store[index];
195template <
class contents>
198 if (!_valid_fields)
return basis::common::IS_EMPTY;
199 to_stuff = _store[_valid_fields - 1];
200 if (_kind == UNBOUNDED) _store.zap(elements()-1, elements()-1);
202 return basis::common::OKAY;
Represents a sequential, ordered, contiguous collection of objects.
Outcomes describe the state of completion for an operation.
An abstraction that represents a stack data structure.
basis::outcome push(const contents &element)
Enters a new element onto the top of the stack.
void reset()
throws out all contents on the stack.
stack & operator=(const stack &to_copy)
makes this stack a copy of "to_copy".
int elements() const
Returns the number of elements used by the stack.
stack(const stack &to_copy)
constructs a stack as a copy of "to_copy".
stack(int elements=0)
Creates a stack with room for the specified number of "elements".
contents & operator[](int index)
Accesses the item at position "index" in the stack.
basis::outcome acquire_pop(contents &to_stuff)
Used to grab the top off of the stack.
void invert()
Inverts this stack, meaning that the old bottom is the new top.
int size() const
returns the size of the stack.
~stack()
destroys anything left on the stack.
contents & top()
Returns the top element from the stack but doesn't change the stack.
stack_kinds kind() const
returns the type of stack that was constructed.
basis::outcome pop()
Removes the top element on the stack.
A dynamic container class that holds any kind of object via pointers.