X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..a7689c49fe02c0c065facf736ab28b19f5997b7c:/include/wx/stack.h?ds=inline diff --git a/include/wx/stack.h b/include/wx/stack.h index 3edda4fc49..b4e8ed2f8a 100644 --- a/include/wx/stack.h +++ b/include/wx/stack.h @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/stack.h // Purpose: STL stack clone -// Author: Lindsay Mathieson -// Modified by: +// Author: Lindsay Mathieson, Vadim Zeitlin // Created: 30.07.2001 -// Copyright: (c) 2001 Lindsay Mathieson -// Licence: wxWidgets licence +// Copyright: (c) 2001 Lindsay Mathieson (WX_DECLARE_STACK) +// 2011 Vadim Zeitlin +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifndef _WX_STACK_H_ @@ -13,31 +13,72 @@ #include "wx/vector.h" -#define WX_DECLARE_STACK(obj, cls)\ -class cls : public wxVectorBase\ +#if wxUSE_STD_CONTAINERS + +#include +#define wxStack std::stack + +#else // !wxUSE_STD_CONTAINERS + +// Notice that unlike std::stack, wxStack currently always uses wxVector and +// can't be used with any other underlying container type. +// +// Another difference is that comparison operators between stacks are not +// implemented (but they should be, see 23.2.3.3 of ISO/IEC 14882:1998). + +template +class wxStack +{ +public: + typedef wxVector container_type; + typedef typename container_type::size_type size_type; + typedef typename container_type::value_type value_type; + + wxStack() { } + explicit wxStack(const container_type& cont) : m_cont(cont) { } + + // Default copy ctor, assignment operator and dtor are ok. + + + bool empty() const { return m_cont.empty(); } + size_type size() const { return m_cont.size(); } + + value_type& top() { return m_cont.back(); } + const value_type& top() const { return m_cont.back(); } + + void push(const value_type& val) { m_cont.push_back(val); } + void pop() { m_cont.pop_back(); } + +private: + container_type m_cont; +}; + +#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS + + +// Deprecated macro-based class for compatibility only, don't use any more. +#define WX_DECLARE_STACK(obj, cls) \ +class cls : public wxVector \ {\ - WX_DECLARE_VECTORBASE(obj, cls);\ public:\ - void push(const obj& o)\ - {\ - bool rc = Alloc(size() + 1);\ - wxASSERT(rc);\ - Append(new obj(o));\ - };\ + void push(const obj& o)\ + {\ + push_back(o); \ + };\ \ - void pop()\ - {\ - RemoveAt(size() - 1);\ - };\ + void pop()\ + {\ + pop_back(); \ + };\ \ - obj& top()\ - {\ - return *(obj *) GetItem(size() - 1);\ - };\ - const obj& top() const\ - {\ - return *(obj *) GetItem(size() - 1);\ - };\ + obj& top()\ + {\ + return at(size() - 1);\ + };\ + const obj& top() const\ + {\ + return at(size() - 1); \ + };\ } #endif // _WX_STACK_H_