home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / valustck.h < prev    next >
C/C++ Source or Header  |  1992-10-19  |  1KB  |  64 lines

  1. /*
  2.  * ValueStack.h  - class definitions for fast value stack.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #ifndef ValueStack_H
  19. # define ValueStack_H
  20.  
  21. #include "Value.h"
  22. #include "Error.h"
  23.  
  24. //___________________________________________________________ ValueStack
  25.  
  26. static const int STACK_SIZE = 10; 
  27.  
  28. class ValueStack
  29. {
  30. public:
  31.   ValueStack();
  32.   ~ValueStack();
  33.  
  34.   void clear();
  35.   Value& pop();
  36.   void push(const Value& v);
  37.   
  38. private:
  39.   Value items[STACK_SIZE];
  40.   int sp;
  41. };
  42.  
  43. inline void ValueStack::clear()
  44. {
  45.   sp = -1;
  46. }
  47.  
  48. inline void ValueStack::push(const Value& v)
  49. {
  50.   if (sp >= STACK_SIZE)
  51.     Error(ERR_ABORT, "ValueStack::push stack is full");
  52.   items[++sp] = v; 
  53. }
  54.  
  55. inline Value& ValueStack::pop()
  56. {
  57.   if (sp < 0)
  58.     Error(ERR_ABORT, "ValueStack::pop stack is empty");
  59.   return items[sp--];
  60. }
  61.  
  62.  
  63. #endif // ValueStack_H
  64.