2001-07-07 19:16:38 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/stack.h
|
|
|
|
// Purpose: STL stack clone
|
2011-02-27 07:46:34 -05:00
|
|
|
// Author: Lindsay Mathieson, Vadim Zeitlin
|
2001-07-07 19:16:38 -04:00
|
|
|
// Created: 30.07.2001
|
2011-02-27 07:46:34 -05:00
|
|
|
// Copyright: (c) 2001 Lindsay Mathieson <lindsay@mathieson.org> (WX_DECLARE_STACK)
|
|
|
|
// 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-07-07 19:16:38 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_STACK_H_
|
|
|
|
#define _WX_STACK_H_
|
|
|
|
|
|
|
|
#include "wx/vector.h"
|
|
|
|
|
2011-03-30 10:16:04 -04:00
|
|
|
#if wxUSE_STD_CONTAINERS
|
2011-02-27 07:46:34 -05:00
|
|
|
|
|
|
|
#include <stack>
|
|
|
|
#define wxStack std::stack
|
|
|
|
|
2011-03-30 10:16:04 -04:00
|
|
|
#else // !wxUSE_STD_CONTAINERS
|
2011-02-27 07:46:34 -05:00
|
|
|
|
|
|
|
// 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 <typename T>
|
|
|
|
class wxStack
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef wxVector<T> 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;
|
|
|
|
};
|
|
|
|
|
2011-03-30 10:16:04 -04:00
|
|
|
#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS
|
2011-02-27 07:46:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
// Deprecated macro-based class for compatibility only, don't use any more.
|
2007-09-02 23:05:50 -04:00
|
|
|
#define WX_DECLARE_STACK(obj, cls) \
|
|
|
|
class cls : public wxVector<obj> \
|
2001-07-07 19:16:38 -04:00
|
|
|
{\
|
|
|
|
public:\
|
2004-09-22 10:38:52 -04:00
|
|
|
void push(const obj& o)\
|
|
|
|
{\
|
2007-09-02 23:05:50 -04:00
|
|
|
push_back(o); \
|
2004-09-22 10:38:52 -04:00
|
|
|
};\
|
2001-07-07 19:16:38 -04:00
|
|
|
\
|
2004-09-22 10:38:52 -04:00
|
|
|
void pop()\
|
|
|
|
{\
|
2007-09-02 23:05:50 -04:00
|
|
|
pop_back(); \
|
2004-09-22 10:38:52 -04:00
|
|
|
};\
|
2001-07-07 19:16:38 -04:00
|
|
|
\
|
2004-09-22 10:38:52 -04:00
|
|
|
obj& top()\
|
|
|
|
{\
|
2007-09-02 23:05:50 -04:00
|
|
|
return at(size() - 1);\
|
2004-09-22 10:38:52 -04:00
|
|
|
};\
|
|
|
|
const obj& top() const\
|
|
|
|
{\
|
2007-09-02 23:05:50 -04:00
|
|
|
return at(size() - 1); \
|
2004-09-22 10:38:52 -04:00
|
|
|
};\
|
2001-07-07 19:16:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _WX_STACK_H_
|
|
|
|
|