home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _stack.h < prev    next >
C/C++ Source or Header  |  2001-01-26  |  3KB  |  106 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Copyright (c) 1996,1997
  7.  * Silicon Graphics Computer Systems, Inc.
  8.  *
  9.  * Copyright (c) 1997
  10.  * Moscow Center for SPARC Technology
  11.  *
  12.  * Copyright (c) 1999 
  13.  * Boris Fomitchev
  14.  *
  15.  * This material is provided "as is", with absolutely no warranty expressed
  16.  * or implied. Any use is at your own risk.
  17.  *
  18.  * Permission to use or copy this software for any purpose is hereby granted 
  19.  * without fee, provided the above notices are retained on all copies.
  20.  * Permission to modify the code and to distribute modified code is granted,
  21.  * provided the above notices are retained, and a notice that the code was
  22.  * modified is included with the above copyright notice.
  23.  *
  24.  */
  25.  
  26. /* NOTE: This is an internal header file, included by other STL headers.
  27.  *   You should not attempt to use it directly.
  28.  */
  29.  
  30. #ifndef _STLP_INTERNAL_STACK_H
  31. #define _STLP_INTERNAL_STACK_H
  32.  
  33. #ifndef _STLP_INTERNAL_DEQUE_H
  34. # include <stl/_deque.h>
  35. #endif
  36.  
  37. _STLP_BEGIN_NAMESPACE
  38.  
  39. # if !defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
  40. template <class _Tp, class _Sequence = deque<_Tp> >
  41. # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
  42. # define _STLP_STACK_ARGS _Tp
  43. template <class _Tp>
  44. # else
  45. template <class _Tp, class _Sequence>
  46. # endif
  47. class stack {
  48.  
  49. # ifdef _STLP_STACK_ARGS 
  50.   typedef deque<_Tp> _Sequence;
  51. # endif
  52.  
  53. public:
  54.   typedef typename _Sequence::value_type      value_type;
  55.   typedef typename _Sequence::size_type       size_type;
  56.   typedef          _Sequence                  container_type;
  57.  
  58.   typedef typename _Sequence::reference       reference;
  59.   typedef typename _Sequence::const_reference const_reference;
  60. protected:
  61.   _Sequence c;
  62. public:
  63.   stack() : c() {}
  64.   explicit stack(const _Sequence& __s) : c(__s) {}
  65.  
  66.   bool empty() const { return c.empty(); }
  67.   size_type size() const { return c.size(); }
  68.   reference top() { return c.back(); }
  69.   const_reference top() const { return c.back(); }
  70.   void push(const value_type& __x) { c.push_back(__x); }
  71.   void pop() { c.pop_back(); }
  72.   const _Sequence& _Get_c() const { return c; }
  73. };
  74.  
  75. # ifndef _STLP_STACK_ARGS
  76. #  define _STLP_STACK_ARGS _Tp, _Sequence
  77. #  define _STLP_STACK_HEADER_ARGS class _Tp, class _Sequence
  78. # else
  79. #  define _STLP_STACK_HEADER_ARGS class _Tp
  80. # endif
  81.  
  82. template < _STLP_STACK_HEADER_ARGS >
  83. inline bool _STLP_CALL  operator==(const stack< _STLP_STACK_ARGS >& __x, const stack< _STLP_STACK_ARGS >& __y)
  84. {
  85.   return __x._Get_c() == __y._Get_c();
  86. }
  87.  
  88. template < _STLP_STACK_HEADER_ARGS >
  89. inline bool _STLP_CALL  operator<(const stack< _STLP_STACK_ARGS >& __x, const stack< _STLP_STACK_ARGS >& __y)
  90. {
  91.   return __x._Get_c() < __y._Get_c();
  92. }
  93.  
  94. _STLP_RELOPS_OPERATORS(template < _STLP_STACK_HEADER_ARGS >, stack< _STLP_STACK_ARGS >)
  95.     
  96. _STLP_END_NAMESPACE
  97.  
  98. #  undef _STLP_STACK_ARGS
  99. #  undef _STLP_STACK_HEADER_ARGS
  100.  
  101. #endif /* _STLP_INTERNAL_STACK_H */
  102.  
  103. // Local Variables:
  104. // mode:C++
  105. // End:
  106.