# HG changeset patch # User koryspansel # Date 1318265394 25200 # Node ID d1be174e5585badf96db2701e8187135c679b4a9 # Parent c4ece16cf995c842b9b49b98f3d8965b6dc160e6 Adding fixed stack for game screens diff -r c4ece16cf995 -r d1be174e5585 LightClone/LightClone.vcproj --- a/LightClone/LightClone.vcproj Fri Oct 07 13:31:52 2011 -0700 +++ b/LightClone/LightClone.vcproj Mon Oct 10 09:49:54 2011 -0700 @@ -464,6 +464,10 @@ > + + diff -r c4ece16cf995 -r d1be174e5585 LightClone/Source/FixedStack.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/FixedStack.h Mon Oct 10 09:49:54 2011 -0700 @@ -0,0 +1,151 @@ +/* + * FixedStack + */ + +#ifndef __FIXEDSTACK_H__ +#define __FIXEDSTACK_H__ + +#include "Types.h" +#include "Debug.h" + +/* + * FixedStack + */ +template +class FixedStack +{ + /* + * Bottom + */ + static const int32 Bottom = (int32)Capacity - 1; + + /* + * kStack + */ + Type kStack[Capacity]; + + /* + * nTop + */ + int32 nTop; + +public: + + /* + * FixedStack + */ + FixedStack() : nTop(-1) + { + } + + /* + * Push + */ + ErrorCode Push(Type kValue) + { + ErrorCode eCode = Error_Success; + + if(nTop < Bottom) + { + kStack[++nTop] = kValue; + } + + return eCode; + } + + /* + * Pop + */ + Type Pop() + { + ErrorCode eCode = Error_Fail; + return eCode; + } + + /* + * Peek + */ + const Type& Peek() + { + } + + /* + * Clear + */ + void Clear() + { + nTop = -1; + } + + /* + * Size + */ + uint32 Size() const + { + return nSize; + } + + /* + * Find + */ + int32 Find(Type& kValue) const + { + for(uint32 i = 0; i < nSize; ++i) + { + if(pList[i] == kValue) + { + return (int32)i; + } + } + + return -1; + } + + /* + * operator [] + */ + Type& operator[](uint32 nIndex) + { + ASSERT(nIndex < nSize); + return pList[nIndex]; + } + + /* + * operator [] + */ + const Type& operator[](uint32 nIndex) const + { + ASSERT(nIndex < nSize); + return pList[nIndex]; + } + +private: + + /* + * Resize + */ + ErrorCode Resize(uint32 nAmount) + { + if(nAmount > nCapacity) + { + Type* pArray = new Type[2 * nAmount]; + + if(pList) + { + for(uint32 i = 0; i < nSize; ++i) + { + pArray[i] = pList[i]; + } + + delete[] pList; + } + + pList = pArray; + nCapacity = 2 * nAmount; + } + + return Error_Success; + } +}; + +#endif //__FIXEDSTACK_H__