Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/stack_8h_source.html
changeset 6 43e37759235e
equal deleted inserted replaced
5:f345bda72bc4 6:43e37759235e
       
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     2 <html xmlns="http://www.w3.org/1999/xhtml">
       
     3 <head>
       
     4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
       
     5 <title>TB9.2 Example Applications: examples/PIPS/opencproducerconsumerex/inc/stack.h Source File</title>
       
     6 <link href="tabs.css" rel="stylesheet" type="text/css"/>
       
     7 <link href="doxygen.css" rel="stylesheet" type="text/css"/>
       
     8 </head>
       
     9 <body>
       
    10 <!-- Generated by Doxygen 1.6.2 -->
       
    11 <h1>examples/PIPS/opencproducerconsumerex/inc/stack.h</h1><a href="stack_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
       
    12 <a name="l00015"></a>00015 <span class="preprocessor">#ifndef STACK_H</span>
       
    13 <a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#define STACK_H</span>
       
    14 <a name="l00017"></a>00017 <span class="preprocessor"></span>
       
    15 <a name="l00018"></a>00018 <span class="comment">/* INCLUDE FILES */</span>
       
    16 <a name="l00019"></a>00019 <span class="preprocessor">#include &lt;string.h&gt;</span>
       
    17 <a name="l00020"></a>00020 <span class="preprocessor">#include &quot;CommanHeader.h&quot;</span>
       
    18 <a name="l00021"></a>00021 
       
    19 <a name="l00022"></a>00022 
       
    20 <a name="l00023"></a>00023 <span class="comment">/*</span>
       
    21 <a name="l00024"></a>00024 <span class="comment">C++ Class that defines Stack</span>
       
    22 <a name="l00025"></a>00025 <span class="comment">*/</span>
       
    23 <a name="l00026"></a><a class="code" href="class_stack.html">00026</a> <span class="keyword">class </span><a class="code" href="class_stack.html">Stack</a> {
       
    24 <a name="l00027"></a>00027 <span class="keyword">enum</span> 
       
    25 <a name="l00028"></a>00028         {
       
    26 <a name="l00029"></a>00029         EMaxProduction = 1000
       
    27 <a name="l00030"></a>00030         };
       
    28 <a name="l00031"></a>00031 
       
    29 <a name="l00032"></a>00032 <span class="keyword">public</span>:
       
    30 <a name="l00033"></a>00033 
       
    31 <a name="l00034"></a>00034         <a class="code" href="class_stack.html">Stack</a>() : iStatckTop(-1) 
       
    32 <a name="l00035"></a>00035         {
       
    33 <a name="l00036"></a>00036         }
       
    34 <a name="l00037"></a><a class="code" href="class_stack.html#a40bd5dff912f0e5290777c4b46d17809">00037</a> 
       
    35 <a name="l00042"></a>00042         <a class="code" href="class_stack.html#a40bd5dff912f0e5290777c4b46d17809">~Stack</a>()
       
    36 <a name="l00043"></a>00043         {
       
    37 <a name="l00044"></a>00044                 <a class="code" href="struct_produced_item.html">ProducedItem</a>* item = NULL; 
       
    38 <a name="l00045"></a>00045                 <span class="keywordflow">do</span>
       
    39 <a name="l00046"></a>00046                         {
       
    40 <a name="l00047"></a>00047                         item = <a class="code" href="class_stack.html#afcc483f12294ea49bcacb6cc528ece5a">Pop</a>();
       
    41 <a name="l00048"></a>00048                         <span class="keyword">delete</span> item;
       
    42 <a name="l00049"></a>00049                         } <span class="keywordflow">while</span>(item != NULL);
       
    43 <a name="l00050"></a>00050         }
       
    44 <a name="l00051"></a>00051 
       
    45 <a name="l00060"></a>00060         <span class="keywordtype">void</span> <a class="code" href="class_stack.html#a15effcd021a0a8ef515e543140a70a6e">Push</a>( <a class="code" href="struct_produced_item.html">ProducedItem</a>* aItem ) 
       
    46 <a name="l00061"></a>00061         {
       
    47 <a name="l00062"></a>00062                 <span class="comment">//If there is enough space to put item onto stack</span>
       
    48 <a name="l00063"></a>00063                 <span class="keywordflow">if</span>(iStatckTop &lt; EMaxProduction-1)
       
    49 <a name="l00064"></a>00064                         {
       
    50 <a name="l00065"></a>00065                         <a class="code" href="struct_produced_item.html">ProducedItem</a>* item = <span class="keyword">new</span> <a class="code" href="struct_produced_item.html">ProducedItem</a>;
       
    51 <a name="l00066"></a>00066                         memcpy(item, aItem, <span class="keyword">sizeof</span>(<a class="code" href="struct_produced_item.html">ProducedItem</a>));
       
    52 <a name="l00067"></a>00067                         iItems[++iStatckTop] = item;
       
    53 <a name="l00068"></a>00068                         }
       
    54 <a name="l00069"></a>00069                 <span class="comment">//else Ignore it!</span>
       
    55 <a name="l00070"></a>00070         }
       
    56 <a name="l00071"></a>00071 
       
    57 <a name="l00082"></a>00082         <a class="code" href="struct_produced_item.html">ProducedItem</a>* <a class="code" href="class_stack.html#afcc483f12294ea49bcacb6cc528ece5a">Pop</a>() 
       
    58 <a name="l00083"></a>00083         {
       
    59 <a name="l00084"></a>00084                 <span class="keywordflow">if</span>(iStatckTop != -1) 
       
    60 <a name="l00085"></a>00085                 {
       
    61 <a name="l00086"></a>00086                         <a class="code" href="struct_produced_item.html">ProducedItem</a>* item = iItems[iStatckTop];
       
    62 <a name="l00087"></a>00087                         iItems[iStatckTop--] = NULL;
       
    63 <a name="l00088"></a>00088                         <span class="keywordflow">return</span> item;
       
    64 <a name="l00089"></a>00089                 }
       
    65 <a name="l00090"></a>00090                 <span class="keywordflow">return</span> NULL;
       
    66 <a name="l00091"></a>00091         }
       
    67 <a name="l00092"></a>00092 
       
    68 <a name="l00093"></a>00093 <span class="keyword">private</span>:
       
    69 <a name="l00094"></a>00094         <a class="code" href="struct_produced_item.html">ProducedItem</a>*   iItems[EMaxProduction];
       
    70 <a name="l00095"></a>00095         <span class="keywordtype">int</span>                             iStatckTop;
       
    71 <a name="l00096"></a>00096 };
       
    72 <a name="l00097"></a>00097 
       
    73 <a name="l00098"></a>00098 <span class="preprocessor">#endif </span><span class="comment">/*STACK_H*/</span>
       
    74 <a name="l00099"></a>00099 
       
    75 <a name="l00100"></a>00100 <span class="comment">/*  End of File */</span>
       
    76 </pre></div></div>
       
    77 <hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
       
    78 <a href="http://www.doxygen.org/index.html">
       
    79 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
       
    80 </body>
       
    81 </html>