_stack.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_STACK_H
  29. #define _STLP_INTERNAL_STACK_H
  30. #ifndef _STLP_INTERNAL_DEQUE_H
  31. # include <stl/_deque.h>
  32. #endif
  33. _STLP_BEGIN_NAMESPACE
  34. #if !defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
  35. template <class _Tp, class _Sequence = deque<_Tp> >
  36. #elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
  37. # define _STLP_STACK_ARGS _Tp
  38. template <class _Tp>
  39. #else
  40. template <class _Tp, class _Sequence>
  41. #endif
  42. class stack
  43. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
  44. # if defined (_STLP_STACK_ARGS)
  45. : public __stlport_class<stack<_Tp> >
  46. # else
  47. : public __stlport_class<stack<_Tp, _Sequence> >
  48. # endif
  49. #endif
  50. {
  51. #ifdef _STLP_STACK_ARGS
  52. typedef deque<_Tp> _Sequence;
  53. typedef stack<_Tp> _Self;
  54. #else
  55. typedef stack<_Tp, _Sequence> _Self;
  56. #endif
  57. public:
  58. typedef typename _Sequence::value_type value_type;
  59. typedef typename _Sequence::size_type size_type;
  60. typedef _Sequence container_type;
  61. typedef typename _Sequence::reference reference;
  62. typedef typename _Sequence::const_reference const_reference;
  63. protected:
  64. //c is a Standard name (23.2.3.3), do no make it STLport naming convention compliant.
  65. _Sequence c;
  66. public:
  67. stack() : c() {}
  68. explicit stack(const _Sequence& __s) : c(__s) {}
  69. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  70. stack(__move_source<_Self> src)
  71. : c(_STLP_PRIV _AsMoveSource(src.get().c)) {}
  72. #endif
  73. bool empty() const { return c.empty(); }
  74. size_type size() const { return c.size(); }
  75. reference top() { return c.back(); }
  76. const_reference top() const { return c.back(); }
  77. void push(const value_type& __x) { c.push_back(__x); }
  78. void pop() { c.pop_back(); }
  79. const _Sequence& _Get_s() const { return c; }
  80. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  81. void _M_swap_workaround(_Self& __x) {
  82. _Sequence __tmp = c;
  83. c = __x.c;
  84. __x.c = __tmp;
  85. }
  86. #endif
  87. };
  88. #ifndef _STLP_STACK_ARGS
  89. # define _STLP_STACK_ARGS _Tp, _Sequence
  90. # define _STLP_STACK_HEADER_ARGS class _Tp, class _Sequence
  91. #else
  92. # define _STLP_STACK_HEADER_ARGS class _Tp
  93. #endif
  94. template < _STLP_STACK_HEADER_ARGS >
  95. inline bool _STLP_CALL operator==(const stack< _STLP_STACK_ARGS >& __x,
  96. const stack< _STLP_STACK_ARGS >& __y)
  97. { return __x._Get_s() == __y._Get_s(); }
  98. template < _STLP_STACK_HEADER_ARGS >
  99. inline bool _STLP_CALL operator<(const stack< _STLP_STACK_ARGS >& __x,
  100. const stack< _STLP_STACK_ARGS >& __y)
  101. { return __x._Get_s() < __y._Get_s(); }
  102. _STLP_RELOPS_OPERATORS(template < _STLP_STACK_HEADER_ARGS >, stack< _STLP_STACK_ARGS >)
  103. #undef _STLP_STACK_ARGS
  104. #undef _STLP_STACK_HEADER_ARGS
  105. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
  106. template <class _Tp, class _Sequence>
  107. struct __move_traits<stack<_Tp, _Sequence> > :
  108. _STLP_PRIV __move_traits_aux<_Sequence>
  109. {};
  110. #endif
  111. _STLP_END_NAMESPACE
  112. #endif /* _STLP_INTERNAL_STACK_H */
  113. // Local Variables:
  114. // mode:C++
  115. // End: