home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  5.7 KB  |  169 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.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  29.  *
  30.  * This computer software is owned by Rogue Wave Software, Inc. and is
  31.  * protected by U.S. copyright laws and other laws and by international
  32.  * treaties.  This computer software is furnished by Rogue Wave Software,
  33.  * Inc. pursuant to a written license agreement and may be used, copied,
  34.  * transmitted, and stored only in accordance with the terms of such
  35.  * license and with the inclusion of the above copyright notice.  This
  36.  * computer software or any other copies thereof may not be provided or
  37.  * otherwise made available to any other person.
  38.  *
  39.  * U.S. Government Restricted Rights.  This computer software is provided
  40.  * with Restricted Rights.  Use, duplication, or disclosure by the
  41.  * Government is subject to restrictions as set forth in subparagraph (c)
  42.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  43.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  44.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  45.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  46.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  47.  *
  48.  **************************************************************************/
  49.  
  50. #include <stdcomp.h>
  51.  
  52. #include <algorithm>
  53. #include <deque>
  54.  
  55. #ifndef _RWSTD_NO_NAMESPACE
  56. namespace std {
  57. #endif
  58.  
  59.   template <class T, class Container _RWSTD_COMPLEX_DEFAULT(deque<T>) > 
  60.   class stack;
  61.  
  62. #ifdef _RWSTD_NO_UNDEFINED_FRIEND
  63.   template <class T, class Container>
  64.   inline bool operator==(const stack<T,Container>& x, 
  65.                          const stack<T,Container>& y);
  66.   template <class T, class Container>
  67.   inline bool operator<(const stack<T,Container>& x, 
  68.                         const stack<T,Container>& y);
  69. #endif  
  70.  
  71.   template <class T, class Container>
  72.   class stack
  73.   {
  74. #ifdef __TURBOC__
  75.     friend bool (std::operator==) (const stack<T,Container>& x,
  76.                             const stack<T,Container>& y);
  77.     friend bool (std::operator<) (const stack<T,Container>& x,
  78.                            const stack<T,Container>& y);
  79. #else
  80.     friend bool operator== (const stack<T,Container>& x,
  81.                             const stack<T,Container>& y);
  82.     friend bool operator< (const stack<T,Container>& x,
  83.                            const stack<T,Container>& y);
  84. #endif
  85.   public:
  86.     
  87.     typedef _TYPENAME Container::value_type         value_type;
  88.     typedef _TYPENAME Container::size_type          size_type;
  89.     typedef _TYPENAME Container::reference          reference;
  90.     typedef _TYPENAME Container::const_reference    const_reference;
  91.     typedef Container                               container_type;
  92.  
  93.   protected:
  94.     
  95.     Container c;
  96.  
  97.   public:
  98.     _EXPLICIT stack(const Container& co _RWSTD_DEFAULT_ARG(Container())) 
  99.       : c(co)
  100.     { ; }
  101.  
  102. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS    
  103.     stack(void) : c(Container())
  104.     { ; }
  105. #endif
  106.  
  107.     bool              empty ()                    const { return c.empty(); }
  108.     size_type         size  ()                    const { return c.size();  }
  109.     reference         top   ()                          { return c.back();  }
  110.     const_reference   top   ()                    const { return c.back();  }
  111.     void              push  (const value_type& x)       { c.push_back(x);   }
  112.     void              pop   ()                          { c.pop_back();     }
  113.   };
  114.  
  115.   template <class T, class Container>
  116.   inline bool operator== (const stack<T,Container>& x, 
  117.                           const stack<T,Container>& y)
  118.   {
  119.     return x.c == y.c;
  120.   }
  121.  
  122.   template <class T, class Container>
  123.   inline bool operator< (const stack<T,Container>& x, 
  124.                          const stack<T,Container>& y)
  125.   {
  126.     return x.c < y.c;
  127.   }
  128.  
  129.   template <class T, class Container>
  130.   inline bool operator!= (const stack<T,Container>& x, 
  131.                           const stack<T,Container>& y)
  132.   {
  133.     return !(x == y);
  134.   }
  135.  
  136.   template <class T, class Container>
  137.   inline bool operator> (const stack<T,Container>& x, 
  138.                          const stack<T,Container>& y)
  139.   {
  140.     return y < x;
  141.   }
  142.  
  143.   template <class T, class Container>
  144.   inline bool operator>= (const stack<T,Container>& x, 
  145.                           const stack<T,Container>& y)
  146.   {
  147.     return !(x < y);
  148.   }
  149.  
  150.   template <class T, class Container>
  151.   inline bool operator<= (const stack<T,Container>& x, 
  152.                           const stack<T,Container>& y)
  153.   {
  154.     return !(y <  x);
  155.   }
  156.  
  157. #ifndef _RWSTD_NO_NAMESPACE
  158. }
  159. #endif
  160.  
  161. #endif /*__STD_STACK__*/
  162.  
  163. #ifndef __USING_STD_NAMES__
  164.   using namespace std;
  165. #endif
  166.  
  167. #pragma option pop
  168. #endif /* __STACK_H */
  169.