stack.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/stack.h
  3. // Purpose: interface of wxStack<T>
  4. // Author: Vadim Zeitlin
  5. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. wxStack<T> is similar to @c std::stack and can be used exactly like it.
  10. If wxWidgets is compiled in STL mode, wxStack will just be a typedef to
  11. @c std::stack but the advantage of this class is that it is also available
  12. on the (rare) platforms where STL is not, so using it makes the code
  13. marginally more portable. If you only target the standard desktop
  14. platforms, please always use @c std::stack directly instead.
  15. The main difference of this class compared to the standard version is that
  16. it always uses wxVector<T> as the underlying container and doesn't allow
  17. specifying an alternative container type. Another missing part is that the
  18. comparison operators between wxStacks are not currently implemented. Other
  19. than that, this class is exactly the same as @c std::stack, so please refer
  20. to the STL documentation for further information.
  21. @nolibrary
  22. @category{containers}
  23. @see @ref overview_container, wxVector<T>
  24. @since 2.9.2
  25. */
  26. template <typename T>
  27. class wxStack<T>
  28. {
  29. public:
  30. /// Type of the underlying container used.
  31. typedef wxVector<T> container_type;
  32. /// Type returned by size() method.
  33. typedef typename container_type::size_type size_type;
  34. /// Type of the elements stored in the stack.
  35. typedef typename container_type::value_type value_type;
  36. /**
  37. Stack can be created either empty or initialized with the contents of
  38. an existing compatible container.
  39. */
  40. //@{
  41. wxStack();
  42. explicit wxStack(const container_type& cont);
  43. //@}
  44. /// Return whether the stack is currently empty.
  45. bool empty() const;
  46. /// Return the number of elements in the stack.
  47. size_type size() const;
  48. /**
  49. Return the element on top of the stack.
  50. */
  51. //@{
  52. value_type& top();
  53. const value_type& top();
  54. //@}
  55. /// Adds an element to the stack.
  56. void push(const value_type& val);
  57. /// Removes the element currently on top of the stack.
  58. void pop();
  59. };