InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2Stack.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Mat Marcus
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // This is an STL style stack (adaptor) based on K2Vector
24 //
25 //========================================================================================
26 
27 #ifndef __K2STACK__
28 #define __K2STACK__
29 
30 #include "K2Vector.h"
31 
32 namespace K2 {
33 
34 template <class T, class _C>
35 class stack;
36 
37 template <class T, class _C >
38 bool16 operator==(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
39 
40 template <class T, class _C >
41 bool16 operator!= (const stack<T, _C>& lhs, const stack<T, _C>& rhs);
42 
43 template <class T, class _C >
44 bool16 operator< (const stack<T, _C>& lhs, const stack<T, _C>& rhs);
45 
46 template <class T, class _C >
47 bool16 operator<= (const stack<T, _C>& lhs, const stack<T, _C>& rhs);
48 
49 template <class T, class _C >
50 bool16 operator> (const stack<T, _C>& lhs, const stack<T, _C>& rhs);
51 
52 template <class T, class _C >
53 bool16 operator>= (const stack<T, _C>& lhs, const stack<T, _C>& rhs);
54 
58 template <class T, class _C = K2Vector<T> >
59 class stack
60 {
61 public:
62  typedef typename _C::value_type value_type;
63  typedef typename _C::size_type size_type;
64  typedef _C container_type;
65 
66  explicit stack(const _C& x = _C()) : c(x) {}
67 
72  bool16 empty() const { return c.empty(); }
73 
78  size_type size() const { return c.size(); }
79 
84  value_type& top() { return c.back(); }
85 
90  const value_type& top() const { return c.back(); }
91 
95  void push(const value_type& x) { c.push_back(x); }
96 
100  void pop() { c.pop_back(); }
101 
102  friend bool16 operator== <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
103  friend bool16 operator!= <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
104  friend bool16 operator< <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
105  friend bool16 operator<= <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
106  friend bool16 operator> <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
107  friend bool16 operator>= <>(const stack<T, _C>& lhs, const stack<T, _C>& rhs);
108 
109 protected:
110  _C c;
111 };
112 
113 template <class T, class _C>
114 bool16 operator==(const stack<T, _C>& lhs, const stack<T, _C>& rhs)
115 {
116  return lhs.c == rhs.c;
117 }
118 
119 template <class T, class _C>
120 bool16 operator< (const stack<T, _C>& lhs, const stack<T, _C>& rhs)
121 {
122  return lhs.c < rhs.c;
123 }
124 
125 template <class T, class _C>
126 bool16 operator!=(const stack<T, _C>& lhs, const stack<T, _C>& rhs)
127 {
128  return lhs.c != rhs.c;
129 }
130 
131 template <class T, class _C>
132 bool16 operator> (const stack<T, _C>& lhs, const stack<T, _C>& rhs)
133 {
134  return lhs.c > rhs.c;
135 }
136 
137 template <class T, class _C>
138 bool16 operator>=(const stack<T, _C>& lhs, const stack<T, _C>& rhs)
139 {
140  return lhs.c >= rhs.c;
141 }
142 
143 template <class T, class _C>
144 bool16 operator<=(const stack<T, _C>& lhs, const stack<T, _C>& rhs)
145 {
146  return lhs.c <= rhs.c;
147 }
148 
149 } // K2 namespace
150 
151 
152 #endif
153