/*
* Stack.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
#pragma once
#include <sol\Object.h>
#include <sol\InvalidArgumentException.h>
//#include <sol\OutOfRangeException.h>
namespace SOL {
class Stack :public Object {
private:
Object** array;
unsigned int sp;
unsigned int size;
public:
Stack(unsigned int size1 = 100)
:size(size1), array(NULL), sp(0)
{
if (size>0) {
array = new Object*[size];
} else {
throw InvalidArgumentException("Stack::Stack,1,InvaliArgument");
}
}
public:
Stack::~Stack()
{
if (array) {
delete [] array;
array = NULL;
}
}
public:
void push(Object* object)
{
if(sp < size) {
array[sp++] = object;
}
}
public:
Object* Stack::pop()
{
Object* object = NULL;
if(sp >0) {
object = array[--sp];
}
return object;
}
};
}
|