1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: Stack.h 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 46365 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_COMMON_SCENE_STACK_H_ 17 #define NN_COMMON_SCENE_STACK_H_ 18 19 #include <nn.h> 20 21 namespace scene 22 { 23 24 template <class T, int SIZE> class Stack 25 { 26 private: 27 T m_stack[SIZE]; 28 int m_index; 29 public: Stack()30 Stack() : m_index(0) {} ~Stack()31 ~Stack() {} push(const T & item)32 void push(const T &item) 33 { 34 NN_ASSERT(m_index<SIZE); 35 m_stack[m_index]=item; 36 ++m_index; 37 } pop()38 void pop() 39 { 40 NN_ASSERT(m_index>0); 41 --m_index; 42 } top()43 const T &top() const 44 { 45 NN_ASSERT(m_index>0); 46 return m_stack[m_index-1]; 47 } size()48 int size() const { return m_index; } empty()49 bool empty() const { return m_index==0; } 50 }; 51 52 } // namespace scene 53 54 #endif // NN_COMMON_SCENE_STACK_H_ 55