]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/stack.h | |
3 | // Purpose: STL stack clone | |
4 | // Author: Lindsay Mathieson, Vadim Zeitlin | |
5 | // Created: 30.07.2001 | |
6 | // Copyright: (c) 2001 Lindsay Mathieson <lindsay@mathieson.org> (WX_DECLARE_STACK) | |
7 | // 2011 Vadim Zeitlin <vadim@wxwidgets.org> | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_STACK_H_ | |
12 | #define _WX_STACK_H_ | |
13 | ||
14 | #include "wx/vector.h" | |
15 | ||
16 | #if wxUSE_STD_CONTAINERS | |
17 | ||
18 | #include <stack> | |
19 | #define wxStack std::stack | |
20 | ||
21 | #else // !wxUSE_STD_CONTAINERS | |
22 | ||
23 | // Notice that unlike std::stack, wxStack currently always uses wxVector and | |
24 | // can't be used with any other underlying container type. | |
25 | // | |
26 | // Another difference is that comparison operators between stacks are not | |
27 | // implemented (but they should be, see 23.2.3.3 of ISO/IEC 14882:1998). | |
28 | ||
29 | template <typename T> | |
30 | class wxStack | |
31 | { | |
32 | public: | |
33 | typedef wxVector<T> container_type; | |
34 | typedef typename container_type::size_type size_type; | |
35 | typedef typename container_type::value_type value_type; | |
36 | ||
37 | wxStack() { } | |
38 | explicit wxStack(const container_type& cont) : m_cont(cont) { } | |
39 | ||
40 | // Default copy ctor, assignment operator and dtor are ok. | |
41 | ||
42 | ||
43 | bool empty() const { return m_cont.empty(); } | |
44 | size_type size() const { return m_cont.size(); } | |
45 | ||
46 | value_type& top() { return m_cont.back(); } | |
47 | const value_type& top() const { return m_cont.back(); } | |
48 | ||
49 | void push(const value_type& val) { m_cont.push_back(val); } | |
50 | void pop() { m_cont.pop_back(); } | |
51 | ||
52 | private: | |
53 | container_type m_cont; | |
54 | }; | |
55 | ||
56 | #endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS | |
57 | ||
58 | ||
59 | // Deprecated macro-based class for compatibility only, don't use any more. | |
60 | #define WX_DECLARE_STACK(obj, cls) \ | |
61 | class cls : public wxVector<obj> \ | |
62 | {\ | |
63 | public:\ | |
64 | void push(const obj& o)\ | |
65 | {\ | |
66 | push_back(o); \ | |
67 | };\ | |
68 | \ | |
69 | void pop()\ | |
70 | {\ | |
71 | pop_back(); \ | |
72 | };\ | |
73 | \ | |
74 | obj& top()\ | |
75 | {\ | |
76 | return at(size() - 1);\ | |
77 | };\ | |
78 | const obj& top() const\ | |
79 | {\ | |
80 | return at(size() - 1); \ | |
81 | };\ | |
82 | } | |
83 | ||
84 | #endif // _WX_STACK_H_ | |
85 |