tc3d_stack.h

来自「自己写的一些基本的3d引擎的基础的代码」· C头文件 代码 · 共 84 行

H
84
字号
/**
 * Comet 3D Engine file (c) 2007 - 2008 Tianjie Wei, THSystems Research Group
 *
 * Released under BSD license, please refer to license.txt for more information
 */

#ifndef _TC3D_STACK_H_
#define _TC3D_STACK_H_

#include "TC3D_Array.h"

namespace C3D
{
	namespace Util
	{
		/**
		 * Stack class template
		 *
		 * @Author Tianjie (James) Wei
		 * @Version 3.0
		 */
		template < class T, class TAlloc = TC3D_Allocator<T> >
		class TC3D_Stack
		{
			protected:

				TC3D_Array<T, TAlloc> tStack;
				TC3D_S32 tSP;

			public:

				/**
				 * Class constructor
				 *
				 * @param	none
				 */
				TC3D_Stack()
				{
					tSP = 0;
				}

				/**
				 * Puts an item into the stack
				 *
				 * @param	data	pointer to the data
				 * @return	none
				 */
				virtual TC3D_Void Push(const T &item)
				{
					tStack.Push_Back(item);
					tSP++;
				}

				/**
				 * Gets an item from top of the stack
				 *
				 * @param	none
				 * @return	item from the stackk
				 */
				virtual T Pop() const
				{
					MC3D_DEBUG_ASSERT(tSP > 0 || tSP < tStack.Size());
					T item = tStack[--tSP];
					tStack.Pop_Back();
					return item;
				}

				/**
				 * Looks at the top of the stack
				 *
				 * @param	none
				 * @return	reference to the item on top of the stack
				 */
				virtual const T &Peek() const
				{
					MC3D_DEBUG_ASSERT(tSP >= 0 || tSP < tStack.Size());
					return tStack[tSP];
				}
		};
	};
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?