00001
00002
00003
00004
00005
00006
00007
00008
00009
00024 #ifndef OSCL_QUEUE_H_INCLUDED
00025 #define OSCL_QUEUE_H_INCLUDED
00026
00027 #ifndef OSCL_BASE_H_INCLUDED
00028 #include "oscl_base.h"
00029 #endif
00030
00031 #ifndef OSCL_MEM_BASIC_FUNCTIONS_H_INCLUDED
00032 #include "oscl_mem_basic_functions.h"
00033 #endif
00034
00035 #ifndef OSCL_ASSERT_H_INCLUDED
00036 #include "oscl_assert.h"
00037 #endif
00038
00039 #ifndef OSCL_OPAQUE_TYPE_H_INCLUDED
00040 #include "oscl_opaque_type.h"
00041 #endif
00042
00050 class Oscl_Queue_Base
00051 {
00052 public:
00053
00057 uint32 size() const
00058 {
00059 return numelems;
00060 }
00061
00065 uint32 capacity() const
00066 {
00067 return bufsize;
00068 }
00069
00073 bool empty() const
00074 {
00075 return numelems == 0;
00076 }
00077
00086 OSCL_IMPORT_REF void reserve(uint32 n) ;
00087
00088 protected:
00089
00090
00091 OSCL_IMPORT_REF void construct(Oscl_Opaque_Type_Alloc* aType);
00092
00093
00094 OSCL_IMPORT_REF void construct(Oscl_Opaque_Type_Alloc* aType, uint32 n) ;
00095
00099 virtual ~Oscl_Queue_Base()
00100 {}
00101
00105 OSCL_IMPORT_REF void destroy();
00106
00112 OSCL_IMPORT_REF void push(const OsclAny* x) ;
00113
00117 OSCL_IMPORT_REF void pop() ;
00118
00122 OSCL_IMPORT_REF void clear() ;
00123
00124 uint32 numelems;
00125 uint32 bufsize;
00126 OsclAny* elems;
00127 uint32 sizeof_T;
00128
00129 uint32 ifront;
00130 uint32 irear;
00131
00132 private:
00133
00137 OsclAny* increment_T(OsclAny* p_T, int32 n) const
00138 {
00139 return (OsclAny*)((int32)p_T + n*sizeof_T);
00140 }
00141
00145 OsclAny* front()
00146 {
00147 return increment_T(elems, ifront);
00148 }
00149
00150 Oscl_Opaque_Type_Alloc* pOpaqueType;
00151 };
00152
00165 template<class T, class Alloc>
00166 class Oscl_Queue
00167 : public Oscl_Queue_Base
00168 , public Oscl_Opaque_Type_Alloc
00169 {
00170
00171 public:
00172 typedef T value_type;
00173 typedef T* pointer;
00174 typedef T& reference;
00175 typedef const T& const_reference;
00176 typedef uint32 size_type;
00177
00181 Oscl_Queue() : Oscl_Queue_Base(), Oscl_Opaque_Type_Alloc()
00182 {
00183 sizeof_T = sizeof(T);
00184 Oscl_Queue_Base::construct(this);
00185 }
00186
00194 Oscl_Queue(uint32 n) : Oscl_Queue_Base(), Oscl_Opaque_Type_Alloc()
00195 {
00196 sizeof_T = sizeof(T);
00197 Oscl_Queue_Base::construct(this, n);
00198 }
00199
00203 virtual ~Oscl_Queue()
00204 {
00205 Oscl_Queue_Base::destroy();
00206 }
00207
00213 void push(const T& x)
00214 {
00215 Oscl_Queue_Base::push(&x);
00216 }
00217
00221 reference front()
00222 {
00223 OSCL_ASSERT(! empty());
00224 return (reference)((pointer)elems)[ifront];
00225 }
00226
00230 const_reference front() const
00231 {
00232 OSCL_ASSERT(! empty());
00233 return (const_reference)((pointer)elems)[ifront];
00234 }
00235
00236
00240 void pop()
00241 {
00242 Oscl_Queue_Base::pop();
00243 }
00244
00250 reference back()
00251 {
00252 OSCL_ASSERT(! empty());
00253 return (reference)((pointer)elems)[irear];
00254 }
00255
00259 const_reference back() const
00260 {
00261 OSCL_ASSERT(! empty());
00262 return (const_reference)((pointer)elems)[irear];
00263 }
00264
00268 void clear()
00269 {
00270 Oscl_Queue_Base::clear();
00271 }
00272
00283 private:
00284 Alloc defAlloc;
00285
00286
00287 OsclAny* allocate(const uint32 size)
00288 {
00289 return defAlloc.allocate(size);
00290 }
00291
00292
00293 void deallocate(OsclAny* p)
00294 {
00295 defAlloc.deallocate(p);
00296 }
00297
00298
00299 void construct(OsclAny* p, const OsclAny* x)
00300 {
00301 OSCL_ASSERT(x);
00302 new(p) value_type(*((T*)x));
00303 }
00304
00305
00306 void destroy(OsclAny* first)
00307 {
00308 OSCL_ASSERT(first);
00309 OSCL_UNUSED_ARG(first);
00310
00311 ((pointer)first)->~T();
00312 }
00313
00314
00315
00316
00317
00318
00319
00325 Oscl_Queue<T, Alloc>& operator=(const Oscl_Queue<T, Alloc>& x)
00326 {
00327
00328
00329
00330
00331 OSCL_UNUSED_ARG(x);
00332 OSCL_ASSERT(false);
00333 return *this;
00334 }
00335
00341 Oscl_Queue(const Oscl_Queue<T, Alloc>& x)
00342 : Oscl_Queue_Base(sizeof(T), this, this)
00343 {
00344 OSCL_UNUSED_ARG(x);
00345 OSCL_ASSERT(false);
00346 }
00347 };
00348
00352 #endif
00353
00354