examples/PIPS/opencproducerconsumerex/inc/stack.h

Go to the documentation of this file.
00001 
00015 #ifndef STACK_H
00016 #define STACK_H
00017 
00018 /* INCLUDE FILES */
00019 #include <string.h>
00020 #include "CommanHeader.h"
00021 
00022 
00023 /*
00024 C++ Class that defines Stack
00025 */
00026 class Stack {
00027 enum 
00028         {
00029         EMaxProduction = 1000
00030         };
00031 
00032 public:
00033 
00034         Stack() : iStatckTop(-1) 
00035         {
00036         }
00037 
00042         ~Stack()
00043         {
00044                 ProducedItem* item = NULL; 
00045                 do
00046                         {
00047                         item = Pop();
00048                         delete item;
00049                         } while(item != NULL);
00050         }
00051 
00060         void Push( ProducedItem* aItem ) 
00061         {
00062                 //If there is enough space to put item onto stack
00063                 if(iStatckTop < EMaxProduction-1)
00064                         {
00065                         ProducedItem* item = new ProducedItem;
00066                         memcpy(item, aItem, sizeof(ProducedItem));
00067                         iItems[++iStatckTop] = item;
00068                         }
00069                 //else Ignore it!
00070         }
00071 
00082         ProducedItem* Pop() 
00083         {
00084                 if(iStatckTop != -1) 
00085                 {
00086                         ProducedItem* item = iItems[iStatckTop];
00087                         iItems[iStatckTop--] = NULL;
00088                         return item;
00089                 }
00090                 return NULL;
00091         }
00092 
00093 private:
00094         ProducedItem*   iItems[EMaxProduction];
00095         int                             iStatckTop;
00096 };
00097 
00098 #endif /*STACK_H*/
00099 
00100 /*  End of File */

Generated by  doxygen 1.6.2