Files correlati : cg0.exe cg0700a.msk cg0700b.msk cg3.exe cg4.exe Bug : Commento: Merge 1.0 libraries
43 lines
647 B
C++
43 lines
647 B
C++
#include <stack.h>
|
|
|
|
TStack::TStack(int size) : _data(size), _sp(0)
|
|
{ }
|
|
|
|
TStack::TStack(const TStack& stack) : _data(stack._data), _sp(stack._sp)
|
|
{ }
|
|
|
|
void TStack::push(const TObject& o)
|
|
{
|
|
_data.add(o, _sp++);
|
|
}
|
|
|
|
void TStack::push(TObject* o)
|
|
{
|
|
_data.add(o, _sp++);
|
|
}
|
|
|
|
TObject& TStack::pop()
|
|
{
|
|
CHECK(_sp > 0, "Stack underflow!");
|
|
return _data[--_sp];
|
|
}
|
|
|
|
TObject& TStack::peek(int depth) const
|
|
{
|
|
CHECKD(depth >= 0 && depth < _sp, "Stack depth error: ", depth);
|
|
return _data[_sp-depth-1];
|
|
}
|
|
|
|
void TStack::destroy()
|
|
{
|
|
_data.destroy();
|
|
_sp = 0;
|
|
}
|
|
|
|
bool TStack::destroy_base()
|
|
{
|
|
if (_sp > 0) _sp--;
|
|
return _data.destroy(0, TRUE);
|
|
}
|
|
|