Return to Stack.h CVS log | Up to [Pegasus] / pegasus / src / Pegasus / Common |
1 mike 1.3 //%///////////////////////////////////////////////////////////////////////////// | ||
2 mike 1.1 // 3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a 6 // copy of this software and associated documentation files (the "Software"), 7 // to deal in the Software without restriction, including without limitation 8 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 // and/or sell copies of the Software, and to permit persons to whom the 10 // Software is furnished to do so, subject to the following conditions: 11 // 12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 // DEALINGS IN THE SOFTWARE. 19 // | ||
20 mike 1.3 //============================================================================== | ||
21 mike 1.1 // | ||
22 mike 1.3 // Author: Mike Brasher (mbrasher@bmc.com) | ||
23 mike 1.1 // | ||
24 mike 1.3 // Modified By: | ||
25 karl 1.2 // | ||
26 mike 1.3 //%///////////////////////////////////////////////////////////////////////////// | ||
27 mike 1.1 28 //////////////////////////////////////////////////////////////////////////////// 29 // 30 // Stack.h 31 // 32 // Simple stack implementation based on the Array<> class. 33 // 34 //////////////////////////////////////////////////////////////////////////////// 35 36 #ifndef Pegasus_Stack_h 37 #define Pegasus_Stack_h 38 39 #include <Pegasus/Common/Config.h> 40 #include <Pegasus/Common/Array.h> 41 42 PEGASUS_NAMESPACE_BEGIN 43 44 template<class T> 45 class Stack 46 { 47 public: | ||
48 karl 1.2 /// | ||
49 mike 1.1 Stack() { } | ||
50 karl 1.2 /// | ||
51 mike 1.1 Stack(const Stack& x) : _rep(x._rep) { } | ||
52 karl 1.2 /// | ||
53 mike 1.1 ~Stack() { } | ||
54 karl 1.2 /// | ||
55 mike 1.1 Stack& operator=(const Stack& x) { _rep = x._rep; return *this; } | ||
56 karl 1.2 /// | ||
57 mike 1.1 Boolean isEmpty() const { return _rep.getSize() == 0; } | ||
58 karl 1.2 /// | ||
59 mike 1.1 void push(const T& x) { _rep.append(x); } | ||
60 karl 1.2 /// | ||
61 mike 1.1 T& top(); | ||
62 karl 1.2 /// | ||
63 mike 1.1 const T& top() const { return ((Stack<T>*)this)->top(); } | ||
64 karl 1.2 /// | ||
65 mike 1.1 void pop(); | ||
66 karl 1.2 /// | ||
67 mike 1.1 Uint32 getSize() const { return _rep.getSize(); } | ||
68 karl 1.2 /// | ||
69 mike 1.1 T& operator[](Uint32 i) { return _rep[i]; } | ||
70 karl 1.2 /// | ||
71 mike 1.1 const T& operator[](Uint32 i) const { return _rep[i]; } 72 73 private: 74 75 Array<T> _rep; 76 }; 77 78 template<class T> 79 T& Stack<T>::top() 80 { 81 if (!isEmpty()) 82 return _rep[_rep.getSize() - 1]; 83 else 84 { 85 static T dummy = T(); 86 return dummy; 87 } 88 } 89 90 template<class T> 91 void Stack<T>::pop() 92 mike 1.1 { 93 if (_rep.getSize() == 0) 94 throw StackUnderflow(); 95 96 _rep.remove(_rep.getSize() - 1); 97 } 98 99 PEGASUS_NAMESPACE_END 100 101 #endif /* Pegasus_Stack_h */ |
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |