00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034
00035 #ifndef GROOVX_RUTZ_STATICSTACK_H_UTC20050626084019_DEFINED
00036 #define GROOVX_RUTZ_STATICSTACK_H_UTC20050626084019_DEFINED
00037
00038 #include "rutz/abort.h"
00039
00040 namespace rutz
00041 {
00043
00045 template <typename T, unsigned int N>
00046 class static_stack
00047 {
00048 public:
00049 static_stack() throw() : vec(), sz(0) {}
00050
00051 static_stack(const static_stack& other) throw() :
00052 vec(), sz(0)
00053 {
00054 *this = other;
00055 }
00056
00057 static_stack& operator=(const static_stack& other) throw()
00058 {
00059 sz = other.sz;
00060
00061 for (unsigned int i = 0; i < sz; ++i)
00062 {
00063 vec[i] = other.vec[i];
00064 }
00065
00066 return *this;
00067 }
00068
00069 unsigned int size() const throw() { return sz; }
00070
00071 static unsigned int capacity() throw() { return N; }
00072
00073 bool push(T p) throw()
00074 {
00075 if (sz >= N)
00076 return false;
00077
00078 vec[sz++] = p;
00079 return true;
00080 }
00081
00082 void pop() throw()
00083 {
00084 if (sz == 0)
00085 GVX_ABORT("underflow in static_stack::pop");
00086
00087 --sz;
00088 }
00089
00090 T top() const throw()
00091 {
00092 return (sz > 0) ? vec[sz-1] : 0;
00093 }
00094
00095 T at(unsigned int i) const throw()
00096 {
00097 return (i < sz) ? vec[i] : 0;
00098 }
00099
00100 T operator[](unsigned int i) const throw() { return at(i); }
00101
00102 typedef T* iterator;
00103 typedef const T* const_iterator;
00104
00105 iterator begin() throw() { return &vec[0]; }
00106 iterator end() throw() { return &vec[0] + sz; }
00107
00108 const_iterator begin() const throw() { return &vec[0]; }
00109 const_iterator end() const throw() { return &vec[0] + sz; }
00110
00111 private:
00112 T vec[N];
00113 unsigned int sz;
00114 };
00115 }
00116
00117 static const char __attribute__((used)) vcid_groovx_rutz_staticstack_h_utc20050626084019[] = "$Id: staticstack.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00118 #endif // !GROOVX_RUTZ_STATICSTACK_H_UTC20050626084019_DEFINED