Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

CC_IntStack.cpp

00001 00002 00003 00004 // 00005 // Copyright 2003 P&P Software GmbH - All Rights Reserved 00006 // 00007 // CC_IntStack.h 00008 // 00009 // Version 1.0 00010 // Date 30.08.03 (Version 1.0) 00011 // Author A. Pasetti (P&P Software) 00012 // 00013 00014 #include "../GeneralInclude/CompilerSwitches.h" 00015 #include "../GeneralInclude/DebugSupport.h" 00016 #include "../GeneralInclude/ClassId.h" 00017 #include "../GeneralInclude/Constants.h" 00018 #include "../Base/CC_RootObject.h" 00019 00020 #include "CC_IntStack.h" 00021 00022 CC_IntStack::CC_IntStack() { 00023 size = 0; 00024 stackPointer = 0; 00025 pStack = pNULL; 00026 setClassId(ID_INTSTACK); 00027 } 00028 00029 void CC_IntStack::setStackSize(unsigned int size) { 00030 assert( this->size == 0); // should not be called more than once 00031 assert( size > 0); // stack size must be greater than zero 00032 00033 pStack = new int[size]; 00034 assert( pStack!= pNULL ); 00035 this->size = size; 00036 stackPointer = 0; 00037 } 00038 00039 unsigned int CC_IntStack::getStackSize() const { 00040 return size; 00041 } 00042 00043 unsigned int CC_IntStack::getNumberOfItems() const { 00044 return stackPointer; 00045 } 00046 00047 00048 void CC_IntStack::push(int newItem) { 00049 assert( (pStack != pNULL) ); 00050 00051 if ( isFull() ) 00052 this->CC_RootObject::getEventRepository()->create(this,EVT_STACK_FULL); 00053 else { 00054 pStack[stackPointer]=newItem; 00055 stackPointer++; 00056 } 00057 assert( stackPointer <= size ); 00058 } 00059 00060 int CC_IntStack::pop() { 00061 assert( (pStack != pNULL) ); 00062 00063 if ( isEmpty() ) { 00064 this->CC_RootObject::getEventRepository()->create(this,EVT_STACK_EMPTY); 00065 return pNULL; 00066 } else { 00067 stackPointer--; 00068 return pStack[stackPointer]; 00069 } 00070 } 00071 00072 bool CC_IntStack::isFull() const { 00073 assert( (pStack != pNULL) ); 00074 return (stackPointer==size); 00075 } 00076 00077 bool CC_IntStack::isEmpty() const { 00078 assert( (pStack != pNULL) ); 00079 return (stackPointer==0); 00080 } 00081 00082 void CC_IntStack::reset() { 00083 assert( (pStack != pNULL) ); 00084 stackPointer = 0; 00085 } 00086 00087 bool CC_IntStack::isObjectConfigured() { 00088 00089 // Check configuration of super object 00090 if ( !CC_RootObject::isObjectConfigured() ) 00091 return NOT_CONFIGURED; 00092 00093 if ( (pStack == pNULL) ) 00094 return NOT_CONFIGURED; 00095 return CONFIGURED; 00096 } 00097
Copyright 2003 P&P Software GmbH - All Rights Reserved