// rpimpl_stack.h
// Copyright (c) Menno Rubingh 2016. Web: [http://rubinghsoftware.de]
//
// MR Mar 2016.
//
// StackDbl:
// Stack of 'double' values, used for the evaluation of a RP expression.
// Used internally by the RPInterpreter implementation.
//
#ifndef _RPIMPL_STACK_H_
#define _RPIMPL_STACK_H_
#include "rpimpl_ex.h" //SContext, Ex.
class StackDbl
{
static int const ARRSIZE = 20; //Max stack size.
int m_n; //Nr of elems currently on the stack.
double m_arr[ARRSIZE];
public:
void clear( void )
{
m_n = 0;
}
StackDbl( void )
{
clear();
}
int getN( void ) const
{
return m_n;
}
void push( SContext const * iCxt, double iVal )
{
if ( m_n == ARRSIZE ) { throw Ex( iCxt, "stack overflow"); }
m_arr[m_n] = iVal;
m_n++;
}
double pop ( SContext const * iCxt )
{
if ( m_n == 0 ) { throw Ex( iCxt, "stack underflow"); }
m_n--;
return m_arr[m_n];
}
};
#endif //_RPIMPL_STACK_H_