1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> 3 <title>oscl_queue.h Source File</title> 4 <link href="doxygen.css" rel="stylesheet" type="text/css"> 5 </head><body> 6 <!-- Generated by Doxygen 1.2.18 --> 7 <center> 8 <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </center> 9 <hr><h1>oscl_queue.h</h1><a href="oscl__queue_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">// -*- c++ -*-</span> 10 00002 11 00003 12 00004 13 00005 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> 14 00006 15 00007 <span class="comment">// O S C L _ Q U E U E</span> 16 00008 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> 17 00009 18 00024 <span class="preprocessor">#ifndef OSCL_QUEUE_H_INCLUDED</span> 19 00025 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_QUEUE_H_INCLUDED</span> 20 00026 <span class="preprocessor"></span> 21 00027 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span> 22 00028 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span> 23 00029 <span class="preprocessor">#endif</span> 24 00030 <span class="preprocessor"></span> 25 00031 <span class="preprocessor">#ifndef OSCL_MEM_BASIC_FUNCTIONS_H_INCLUDED</span> 26 00032 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__mem__basic__functions_8h.html">oscl_mem_basic_functions.h</a>"</span> 27 00033 <span class="preprocessor">#endif</span> 28 00034 <span class="preprocessor"></span> 29 00035 <span class="preprocessor">#ifndef OSCL_ASSERT_H_INCLUDED</span> 30 00036 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__assert_8h.html">oscl_assert.h</a>"</span> 31 00037 <span class="preprocessor">#endif</span> 32 00038 <span class="preprocessor"></span> 33 00039 <span class="preprocessor">#ifndef OSCL_OPAQUE_TYPE_H_INCLUDED</span> 34 00040 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__opaque__type_8h.html">oscl_opaque_type.h</a>"</span> 35 00041 <span class="preprocessor">#endif</span> 36 00042 <span class="preprocessor"></span> 37 <a name="l00050"></a><a class="code" href="classOscl__Queue__Base.html">00050</a> <span class="keyword">class </span><a class="code" href="classOscl__Queue__Base.html">Oscl_Queue_Base</a> 38 00051 { 39 00052 <span class="keyword">public</span>: 40 00053 41 <a name="l00057"></a><a class="code" href="classOscl__Queue__Base.html#a0">00057</a> uint32 <a class="code" href="classOscl__Queue__Base.html#a0">size</a>()<span class="keyword"> const</span> 42 00058 <span class="keyword"> </span>{ 43 00059 <span class="keywordflow">return</span> <a class="code" href="classOscl__Queue__Base.html#n0">numelems</a>; 44 00060 } 45 00061 46 <a name="l00065"></a><a class="code" href="classOscl__Queue__Base.html#a1">00065</a> uint32 <a class="code" href="classOscl__Queue__Base.html#a1">capacity</a>()<span class="keyword"> const</span> 47 00066 <span class="keyword"> </span>{ 48 00067 <span class="keywordflow">return</span> <a class="code" href="classOscl__Queue__Base.html#n1">bufsize</a>; 49 00068 } 50 00069 51 <a name="l00073"></a><a class="code" href="classOscl__Queue__Base.html#a2">00073</a> <span class="keywordtype">bool</span> <a class="code" href="classOscl__Queue__Base.html#a2">empty</a>()<span class="keyword"> const</span> 52 00074 <span class="keyword"> </span>{ 53 00075 <span class="keywordflow">return</span> <a class="code" href="classOscl__Queue__Base.html#n0">numelems</a> == 0; 54 00076 } 55 00077 56 00086 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#a3">reserve</a>(uint32 n) ; 57 00087 58 00088 <span class="keyword">protected</span>: 59 00089 60 00090 <span class="comment">//for use in default constructor. vtable is needed so this is a subroutine.</span> 61 00091 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b0">construct</a>(<a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a>* aType); 62 00092 63 00093 <span class="comment">//for use in constructor with pre-allocation for "n" elements.</span> 64 00094 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b0">construct</a>(<a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a>* aType, uint32 n) ; 65 00095 66 <a name="l00099"></a><a class="code" href="classOscl__Queue__Base.html#b2">00099</a> <span class="keyword">virtual</span> <a class="code" href="classOscl__Queue__Base.html#b2">~Oscl_Queue_Base</a>() 67 00100 {} 68 00101 69 00105 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b3">destroy</a>(); 70 00106 71 00112 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b4">push</a>(<span class="keyword">const</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* x) ; 72 00113 73 00117 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b5">pop</a>() ; 74 00118 75 00122 OSCL_IMPORT_REF <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b6">clear</a>() ; 76 00123 77 <a name="l00124"></a><a class="code" href="classOscl__Queue__Base.html#n0">00124</a> uint32 <a class="code" href="classOscl__Queue__Base.html#n0">numelems</a>; <span class="comment">// number of valid entries in queue</span> 78 <a name="l00125"></a><a class="code" href="classOscl__Queue__Base.html#n1">00125</a> uint32 <a class="code" href="classOscl__Queue__Base.html#n1">bufsize</a>; <span class="comment">// size of elems</span> 79 <a name="l00126"></a><a class="code" href="classOscl__Queue__Base.html#n2">00126</a> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__Queue__Base.html#n2">elems</a>; <span class="comment">// array holding the elements</span> 80 <a name="l00127"></a><a class="code" href="classOscl__Queue__Base.html#n3">00127</a> uint32 <a class="code" href="classOscl__Queue__Base.html#n3">sizeof_T</a>; 81 00128 82 <a name="l00129"></a><a class="code" href="classOscl__Queue__Base.html#n4">00129</a> uint32 <a class="code" href="classOscl__Queue__Base.html#n4">ifront</a>; <span class="comment">// front of queue: removal point</span> 83 <a name="l00130"></a><a class="code" href="classOscl__Queue__Base.html#n5">00130</a> uint32 <a class="code" href="classOscl__Queue__Base.html#n5">irear</a>; <span class="comment">// just before back of queue: increment=>insertion point</span> 84 00131 85 00132 <span class="keyword">private</span>: 86 00133 87 00137 <a class="code" href="group__osclbase.html#a25">OsclAny</a>* increment_T(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p_T, int32 n)<span class="keyword"> const</span> 88 00138 <span class="keyword"> </span>{ 89 00139 <span class="keywordflow">return</span> (<a class="code" href="group__osclbase.html#a25">OsclAny</a>*)((int32)p_T + n*<a class="code" href="classOscl__Queue__Base.html#n3">sizeof_T</a>); 90 00140 } 91 00141 92 00145 <a class="code" href="group__osclbase.html#a25">OsclAny</a>* front() 93 00146 { 94 00147 <span class="keywordflow">return</span> increment_T(<a class="code" href="classOscl__Queue__Base.html#n2">elems</a>, <a class="code" href="classOscl__Queue__Base.html#n4">ifront</a>); 95 00148 } 96 00149 97 00150 <a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a>* pOpaqueType; 98 00151 }; 99 00152 100 00165 <span class="keyword">template</span><<span class="keyword">class</span> T, <span class="keyword">class</span> Alloc> 101 <a name="l00166"></a><a class="code" href="classOscl__Queue.html">00166</a> <span class="keyword">class </span><a class="code" href="classOscl__Queue.html">Oscl_Queue</a> 102 00167 : <span class="keyword">public</span> <a class="code" href="classOscl__Queue__Base.html">Oscl_Queue_Base</a> 103 00168 , <span class="keyword">public</span> <a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a> 104 00169 { 105 00170 106 00171 <span class="keyword">public</span>: 107 <a name="l00172"></a><a class="code" href="classOscl__Queue.html#s0">00172</a> <span class="keyword">typedef</span> T <a class="code" href="classOscl__Queue.html#s0">value_type</a>; 108 <a name="l00173"></a><a class="code" href="classOscl__Queue.html#s1">00173</a> <span class="keyword">typedef</span> T* <a class="code" href="classOscl__Queue.html#s1">pointer</a>; 109 <a name="l00174"></a><a class="code" href="classOscl__Queue.html#s2">00174</a> <span class="keyword">typedef</span> T& <a class="code" href="classOscl__Queue.html#s2">reference</a>; 110 <a name="l00175"></a><a class="code" href="classOscl__Queue.html#s3">00175</a> <span class="keyword">typedef</span> <span class="keyword">const</span> T& <a class="code" href="classOscl__Queue.html#s3">const_reference</a>; 111 <a name="l00176"></a><a class="code" href="classOscl__Queue.html#s4">00176</a> <span class="keyword">typedef</span> uint32 <a class="code" href="classOscl__Queue.html#s4">size_type</a>; 112 00177 113 <a name="l00181"></a><a class="code" href="classOscl__Queue.html#a0">00181</a> <a class="code" href="classOscl__Queue.html#a0">Oscl_Queue</a>() : <a class="code" href="classOscl__Queue__Base.html">Oscl_Queue_Base</a>(), <a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a>() 114 00182 { 115 00183 <a class="code" href="classOscl__Queue__Base.html#n3">sizeof_T</a> = <span class="keyword">sizeof</span>(T); 116 00184 <a class="code" href="classOscl__Queue__Base.html#b0">Oscl_Queue_Base::construct</a>(<span class="keyword">this</span>); 117 00185 } 118 00186 119 <a name="l00194"></a><a class="code" href="classOscl__Queue.html#a1">00194</a> <a class="code" href="classOscl__Queue.html#a0">Oscl_Queue</a>(uint32 n) : <a class="code" href="classOscl__Queue__Base.html">Oscl_Queue_Base</a>(), <a class="code" href="classOscl__Opaque__Type__Alloc.html">Oscl_Opaque_Type_Alloc</a>() 120 00195 { 121 00196 <a class="code" href="classOscl__Queue__Base.html#n3">sizeof_T</a> = <span class="keyword">sizeof</span>(T); 122 00197 <a class="code" href="classOscl__Queue__Base.html#b0">Oscl_Queue_Base::construct</a>(<span class="keyword">this</span>, n); 123 00198 } 124 00199 125 <a name="l00203"></a><a class="code" href="classOscl__Queue.html#a2">00203</a> <span class="keyword">virtual</span> <a class="code" href="classOscl__Queue.html#a2">~Oscl_Queue</a>() 126 00204 { 127 00205 <a class="code" href="classOscl__Queue__Base.html#b3">Oscl_Queue_Base::destroy</a>(); 128 00206 } 129 00207 130 <a name="l00213"></a><a class="code" href="classOscl__Queue.html#a3">00213</a> <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue.html#a3">push</a>(<span class="keyword">const</span> T& x) 131 00214 { 132 00215 <a class="code" href="classOscl__Queue__Base.html#b4">Oscl_Queue_Base::push</a>(&x); 133 00216 } 134 00217 135 <a name="l00221"></a><a class="code" href="classOscl__Queue.html#a4">00221</a> <a class="code" href="classOscl__Queue.html#s2">reference</a> <a class="code" href="classOscl__Queue.html#a4">front</a>() 136 00222 { 137 00223 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(! <a class="code" href="classOscl__Queue__Base.html#a2">empty</a>()); 138 00224 <span class="keywordflow">return</span> (reference)((pointer)<a class="code" href="classOscl__Queue__Base.html#n2">elems</a>)[<a class="code" href="classOscl__Queue__Base.html#n4">ifront</a>]; 139 00225 } 140 00226 141 <a name="l00230"></a><a class="code" href="classOscl__Queue.html#a5">00230</a> <a class="code" href="classOscl__Queue.html#s3">const_reference</a> <a class="code" href="classOscl__Queue.html#a4">front</a>()<span class="keyword"> const</span> 142 00231 <span class="keyword"> </span>{ 143 00232 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(! <a class="code" href="classOscl__Queue__Base.html#a2">empty</a>()); 144 00233 <span class="keywordflow">return</span> (const_reference)((pointer)<a class="code" href="classOscl__Queue__Base.html#n2">elems</a>)[<a class="code" href="classOscl__Queue__Base.html#n4">ifront</a>]; 145 00234 } 146 00235 147 00236 148 <a name="l00240"></a><a class="code" href="classOscl__Queue.html#a6">00240</a> <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue.html#a6">pop</a>() 149 00241 { 150 00242 <a class="code" href="classOscl__Queue__Base.html#b5">Oscl_Queue_Base::pop</a>(); 151 00243 } 152 00244 153 <a name="l00250"></a><a class="code" href="classOscl__Queue.html#a7">00250</a> <a class="code" href="classOscl__Queue.html#s2">reference</a> <a class="code" href="classOscl__Queue.html#a7">back</a>() 154 00251 { 155 00252 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(! <a class="code" href="classOscl__Queue__Base.html#a2">empty</a>()); 156 00253 <span class="keywordflow">return</span> (reference)((pointer)<a class="code" href="classOscl__Queue__Base.html#n2">elems</a>)[<a class="code" href="classOscl__Queue__Base.html#n5">irear</a>]; 157 00254 } 158 00255 159 <a name="l00259"></a><a class="code" href="classOscl__Queue.html#a8">00259</a> <a class="code" href="classOscl__Queue.html#s3">const_reference</a> <a class="code" href="classOscl__Queue.html#a7">back</a>()<span class="keyword"> const</span> 160 00260 <span class="keyword"> </span>{ 161 00261 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(! <a class="code" href="classOscl__Queue__Base.html#a2">empty</a>()); 162 00262 <span class="keywordflow">return</span> (const_reference)((pointer)<a class="code" href="classOscl__Queue__Base.html#n2">elems</a>)[<a class="code" href="classOscl__Queue__Base.html#n5">irear</a>]; 163 00263 } 164 00264 165 <a name="l00268"></a><a class="code" href="classOscl__Queue.html#a9">00268</a> <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue.html#a9">clear</a>() 166 00269 { 167 00270 <a class="code" href="classOscl__Queue__Base.html#b6">Oscl_Queue_Base::clear</a>(); 168 00271 } 169 00272 170 00283 <span class="keyword">private</span>: 171 00284 Alloc defAlloc; 172 00285 173 00286 <span class="comment">//from Oscl_Opaque_Type_Alloc</span> 174 00287 <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOscl__Opaque__Type__Alloc.html#a2">allocate</a>(<span class="keyword">const</span> uint32 <a class="code" href="classOscl__Queue__Base.html#a0">size</a>) 175 00288 { 176 00289 <span class="keywordflow">return</span> defAlloc.allocate(<a class="code" href="classOscl__Queue__Base.html#a0">size</a>); 177 00290 } 178 00291 179 00292 <span class="comment">//from Oscl_Opaque_Type_Alloc</span> 180 00293 <span class="keywordtype">void</span> <a class="code" href="classOscl__Opaque__Type__Alloc.html#a3">deallocate</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p) 181 00294 { 182 00295 defAlloc.deallocate(p); 183 00296 } 184 00297 185 00298 <span class="comment">//from Oscl_Opaque_Type_Alloc</span> 186 00299 <span class="keywordtype">void</span> <a class="code" href="classOscl__Opaque__Type__Alloc.html#a0">construct</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* p, <span class="keyword">const</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* x) 187 00300 { 188 00301 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(x); 189 00302 <span class="keyword">new</span>(p) <a class="code" href="classOscl__Queue.html#s0">value_type</a>(*((T*)x)); 190 00303 } 191 00304 192 00305 <span class="comment">//from Oscl_Opaque_Type_Alloc</span> 193 00306 <span class="keywordtype">void</span> <a class="code" href="classOscl__Queue__Base.html#b3">destroy</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* first) 194 00307 { 195 00308 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(first); 196 00309 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(first); 197 00310 <span class="comment">//must use "pointer" instead of "T*" here to avoid ADS 1.2 compile error.</span> 198 00311 ((pointer)first)->~T(); 199 00312 } 200 00313 201 00314 202 00315 <span class="comment">/***************************</span> 203 00316 <span class="comment"> * things we don't believe are needed</span> 204 00317 <span class="comment"> * -- private definitions to block implicit ones --</span> 205 00318 <span class="comment"> */</span> 206 00319 207 00325 <a class="code" href="classOscl__Queue.html">Oscl_Queue<T, Alloc></a>& operator=(<span class="keyword">const</span> <a class="code" href="classOscl__Queue.html">Oscl_Queue<T, Alloc></a>& x) 208 00326 { 209 00327 <span class="comment">// Do we need to copy a queue? Why...?</span> 210 00328 <span class="comment">// .. unless there's a need, let's not bother with the</span> 211 00329 <span class="comment">// complexity here..</span> 212 00330 <span class="comment">// (need something here, we don't want implicit assignment either</span> 213 00331 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(x); 214 00332 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(<span class="keyword">false</span>); 215 00333 <span class="keywordflow">return</span> *<span class="keyword">this</span>; 216 00334 } 217 00335 218 00341 <a class="code" href="classOscl__Queue.html#a0">Oscl_Queue</a>(<span class="keyword">const</span> <a class="code" href="classOscl__Queue.html">Oscl_Queue<T, Alloc></a>& x) 219 00342 : <a class="code" href="classOscl__Queue__Base.html">Oscl_Queue_Base</a>(sizeof(T), this, this) 220 00343 { 221 00344 <a class="code" href="group__osclbase.html#a89">OSCL_UNUSED_ARG</a>(x); 222 00345 <a class="code" href="group__osclbase.html#a78">OSCL_ASSERT</a>(<span class="keyword">false</span>); 223 00346 } 224 00347 }; <span class="comment">// end class oscl_queue</span> 225 00348 226 00352 <span class="preprocessor">#endif</span> 227 00353 <span class="preprocessor"></span> 228 00354 229 </pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small> 230 <address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small> 231 </small></address> 232 </body> 233 </html> 234