home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / libg++-2.5.3-bin.lha / lib / g++-include / gen / VStack.hP < prev    next >
Text File  |  1994-02-21  |  3KB  |  121 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19.  
  20. #ifndef _<T>VStack_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _<T>VStack_h 1
  25.  
  26. #include "<T>.Stack.h"
  27.  
  28. class <T>VStack : public <T>Stack
  29. {
  30. protected:
  31.   int                   size;
  32.   int                   ptr;
  33.   <T>*                  s;
  34.  
  35. public:
  36.  
  37.                         <T>VStack(int sz = DEFAULT_INITIAL_CAPACITY);
  38.                         <T>VStack(<T>VStack&);
  39.                         ~<T>VStack();
  40.  
  41.   void                  operator = (<T>VStack&);
  42.   void                  push(<T&> item);
  43.   <T>                   pop();
  44.   <T>&                  top();
  45.   void                  del_top();
  46.  
  47.   int                   length();
  48.   int                   empty();
  49.   int                   full();
  50.   void                  clear();
  51.  
  52.   void                  resize(int sz);
  53.   int                   capacity();
  54.  
  55.   int                   OK();
  56. };
  57.  
  58.  
  59. inline <T>VStack::<T>VStack(int sz)
  60. {
  61.   s = new <T> [size = sz];
  62.   ptr = 0;
  63. }
  64.  
  65. inline <T>VStack::~<T>VStack()
  66. {
  67.   delete [] s;
  68. }
  69.  
  70. inline void <T>VStack::clear()
  71. {
  72.   ptr = 0;
  73. }
  74.  
  75. inline int <T>VStack::capacity()
  76. {
  77.   return size;
  78. }
  79.  
  80. inline int <T>VStack::empty()
  81. {
  82.   return ptr == 0;
  83. }
  84.  
  85. inline int <T>VStack::full()
  86. {
  87.   return ptr == size;
  88. }
  89.  
  90. inline int <T>VStack::length()
  91. {
  92.   return ptr;
  93. }
  94.  
  95. inline void <T>VStack::push(<T&> item)
  96. {
  97.   if (full()) error("push to full stack.");
  98.   s[ptr++] = item;
  99. }
  100.  
  101. inline <T> <T>VStack::pop()
  102. {
  103.   if (empty()) error("pop from empty stack.");
  104.   return s[--ptr];
  105. }
  106.  
  107.  
  108. inline void <T>VStack::del_top()
  109. {
  110.   if (empty()) error("del_top from empty stack.");
  111.   --ptr;
  112. }
  113.  
  114. inline <T>& <T>VStack::top()
  115. {
  116.   if (empty()) error("top from empty stack.");
  117.   return s[ptr-1];
  118. }
  119.  
  120. #endif
  121.