changeset 69:d1be174e5585

Adding fixed stack for game screens
author koryspansel <koryspansel@bendbroadband.com>
date Mon, 10 Oct 2011 09:49:54 -0700
parents c4ece16cf995
children ffaeccdc105e
files LightClone/LightClone.vcproj LightClone/Source/FixedStack.h
diffstat 2 files changed, 155 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Source\FixedStack.h"
+					>
+				</File>
+				<File
 					RelativePath=".\Source\FixedString.h"
 					>
 				</File>
--- /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<typename Type, uint32 Capacity>
+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__