stl_stack.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_STACK_H
00032 #define __SGI_STL_INTERNAL_STACK_H
00033 
00034 #include <sequence_concepts.h>
00035 
00036 __STL_BEGIN_NAMESPACE
00037 
00038 // Forward declarations of operators == and <, needed for friend declaration.
00039 
00040 template <class _Tp, 
00041           class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(deque<_Tp>) >
00042 class stack;
00043 
00044 template <class _Tp, class _Seq>
00045 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00046 
00047 template <class _Tp, class _Seq>
00048 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
00049 
00050 
00051 template <class _Tp, class _Sequence>
00052 class stack {
00053 
00054   // requirements:
00055 
00056   __STL_CLASS_REQUIRES(_Tp, _Assignable);
00057   __STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
00058   typedef typename _Sequence::value_type _Sequence_value_type;
00059   __STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
00060 
00061 
00062 #ifdef __STL_MEMBER_TEMPLATES
00063   template <class _Tp1, class _Seq1>
00064   friend bool operator== (const stack<_Tp1, _Seq1>&,
00065                           const stack<_Tp1, _Seq1>&);
00066   template <class _Tp1, class _Seq1>
00067   friend bool operator< (const stack<_Tp1, _Seq1>&,
00068                          const stack<_Tp1, _Seq1>&);
00069 #else /* __STL_MEMBER_TEMPLATES */
00070   friend bool __STD_QUALIFIER
00071   operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
00072   friend bool __STD_QUALIFIER
00073   operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
00074 #endif /* __STL_MEMBER_TEMPLATES */
00075 
00076 public:
00077   typedef typename _Sequence::value_type      value_type;
00078   typedef typename _Sequence::size_type       size_type;
00079   typedef          _Sequence                  container_type;
00080 
00081   typedef typename _Sequence::reference       reference;
00082   typedef typename _Sequence::const_reference const_reference;
00083 protected:
00084   _Sequence c;
00085 public:
00086   stack() : c() {}
00087   explicit stack(const _Sequence& __s) : c(__s) {}
00088 
00089   bool empty() const { return c.empty(); }
00090   size_type size() const { return c.size(); }
00091   reference top() { return c.back(); }
00092   const_reference top() const { return c.back(); }
00093   void push(const value_type& __x) { c.push_back(__x); }
00094   void pop() { c.pop_back(); }
00095 };
00096 
00097 template <class _Tp, class _Seq>
00098 bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00099 {
00100   return __x.c == __y.c;
00101 }
00102 
00103 template <class _Tp, class _Seq>
00104 bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00105 {
00106   return __x.c < __y.c;
00107 }
00108 
00109 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
00110 
00111 template <class _Tp, class _Seq>
00112 bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00113 {
00114   return !(__x == __y);
00115 }
00116 
00117 template <class _Tp, class _Seq>
00118 bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00119 {
00120   return __y < __x;
00121 }
00122 
00123 template <class _Tp, class _Seq>
00124 bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00125 {
00126   return !(__y < __x);
00127 }
00128 
00129 template <class _Tp, class _Seq>
00130 bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
00131 {
00132   return !(__x < __y);
00133 }
00134 
00135 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
00136 
00137 __STL_END_NAMESPACE
00138 
00139 #endif /* __SGI_STL_INTERNAL_STACK_H */
00140 
00141 // Local Variables:
00142 // mode:C++
00143 // End:

Generated on Mon Jun 5 10:20:44 2006 for Intelligence.kdevelop by  doxygen 1.4.6