home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / STACK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  5.9 KB  |  171 lines

  1. #ifndef __STACK_H
  2. #define __STACK_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_STACK__
  6. #define __STD_STACK__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * stack - Declaration for the Standard Library stack class
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * Copyright (c) 1994
  15.  * Hewlett-Packard Company
  16.  *
  17.  * Permission to use, copy, modify, distribute and sell this software
  18.  * and its documentation for any purpose is hereby granted without fee,
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both that copyright notice and this permission notice appear
  21.  * in supporting documentation.  Hewlett-Packard Company makes no
  22.  * representations about the suitability of this software for any
  23.  * purpose.  It is provided "as is" without express or implied warranty.
  24.  *
  25.  *
  26.  ***************************************************************************
  27.  *
  28.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  29.  * ALL RIGHTS RESERVED
  30.  *
  31.  * The software and information contained herein are proprietary to, and
  32.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  33.  * intends to preserve as trade secrets such software and information.
  34.  * This software is furnished pursuant to a written license agreement and
  35.  * may be used, copied, transmitted, and stored only in accordance with
  36.  * the terms of such license and with the inclusion of the above copyright
  37.  * notice.  This software and information or any other copies thereof may
  38.  * not be provided or otherwise made available to any other person.
  39.  *
  40.  * Notwithstanding any other lease or license that may pertain to, or
  41.  * accompany the delivery of, this computer software and information, the
  42.  * rights of the Government regarding its use, reproduction and disclosure
  43.  * are as set forth in Section 52.227-19 of the FARS Computer
  44.  * Software-Restricted Rights clause.
  45.  * 
  46.  * Use, duplication, or disclosure by the Government is subject to
  47.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  48.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  49.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  50.  * P.O. Box 2328, Corvallis, Oregon 97339.
  51.  *
  52.  * This computer software and information is distributed with "restricted
  53.  * rights."  Use, duplication or disclosure is subject to restrictions as
  54.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  55.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  56.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  57.  * then the "Alternate III" clause applies.
  58.  *
  59.  **************************************************************************/
  60.  
  61. #include <stdcomp.h>
  62.  
  63. #include <algorithm>
  64. #include <deque>
  65.  
  66. #ifndef _RWSTD_NO_NAMESPACE
  67. namespace std {
  68. #endif
  69.  
  70.   template <class T, class Container _RWSTD_COMPLEX_DEFAULT(deque<T>) > 
  71.   class stack;
  72.  
  73. #ifdef _RWSTD_NO_UNDEFINED_FRIEND
  74.   template <class T, class Container>
  75.   inline bool operator==(const stack<T,Container>& x, 
  76.                          const stack<T,Container>& y);
  77.   template <class T, class Container>
  78.   inline bool operator<(const stack<T,Container>& x, 
  79.                         const stack<T,Container>& y);
  80. #endif  
  81.  
  82.   template <class T, class Container>
  83.   class stack
  84.   {
  85.     friend bool (std::operator==) (const stack<T,Container>& x,
  86.                  const stack<T,Container>& y);
  87.     friend bool (std::operator<) (const stack<T,Container>& x,
  88.                 const stack<T,Container>& y);
  89.   public:
  90.     
  91.     typedef _TYPENAME Container::value_type         value_type;
  92.     typedef _TYPENAME Container::size_type          size_type;
  93.     typedef _TYPENAME Container::reference          reference;
  94.     typedef _TYPENAME Container::const_reference    const_reference;
  95.     typedef Container                               container_type;
  96.  
  97.   protected:
  98.     
  99.     Container c;
  100.  
  101.   public:
  102.     _EXPLICIT stack(const Container& co _RWSTD_DEFAULT_ARG(Container())) 
  103.       : c(co)
  104.     { ; }
  105.  
  106. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS    
  107.     stack(void) : c(Container())
  108.     { ; }
  109. #endif
  110.  
  111.     bool              empty ()                    const { return c.empty(); }
  112.     size_type         size  ()                    const { return c.size();  }
  113.     reference         top   ()                          { return c.back();  }
  114.     const_reference   top   ()                    const { return c.back();  }
  115.     void              push  (const value_type& x)       { c.push_back(x);   }
  116.     void              pop   ()                          { c.pop_back();     }
  117.   };
  118.  
  119.   template <class T, class Container>
  120.   inline bool operator== (const stack<T,Container>& x, 
  121.                           const stack<T,Container>& y)
  122.   {
  123.     return x.c == y.c;
  124.   }
  125.  
  126.   template <class T, class Container>
  127.   inline bool operator< (const stack<T,Container>& x, 
  128.                          const stack<T,Container>& y)
  129.   {
  130.     return x.c < y.c;
  131.   }
  132.  
  133.   template <class T, class Container>
  134.   inline bool operator!= (const stack<T,Container>& x, 
  135.                           const stack<T,Container>& y)
  136.   {
  137.     return !(x == y);
  138.   }
  139.  
  140.   template <class T, class Container>
  141.   inline bool operator> (const stack<T,Container>& x, 
  142.                          const stack<T,Container>& y)
  143.   {
  144.     return y < x;
  145.   }
  146.  
  147.   template <class T, class Container>
  148.   inline bool operator>= (const stack<T,Container>& x, 
  149.                           const stack<T,Container>& y)
  150.   {
  151.     return !(x < y);
  152.   }
  153.  
  154.   template <class T, class Container>
  155.   inline bool operator<= (const stack<T,Container>& x, 
  156.                           const stack<T,Container>& y)
  157.   {
  158.     return !(y <  x);
  159.   }
  160.  
  161. #ifndef _RWSTD_NO_NAMESPACE
  162. }
  163. #endif
  164.  
  165. #endif /*__STD_STACK__*/
  166. #ifndef __USING_STD_NAMES__
  167.   using namespace std;
  168. #endif
  169. #pragma option pop
  170. #endif /* __STACK_H */
  171.