1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: fnd_FixedBufferVector.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: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_FND_FND_FIXEDBUFFERVECTOR_H_ 17 #define NN_FND_FND_FIXEDBUFFERVECTOR_H_ 18 19 #include <nn/types.h> 20 21 #ifdef __cplusplus 22 23 namespace nn { 24 namespace fnd { 25 26 template <typename T, int NUM_OF_T> 27 class FixedBufferVector 28 { 29 public: FixedBufferVector()30 FixedBufferVector() 31 : m_Length(0) 32 { 33 } ~FixedBufferVector()34 ~FixedBufferVector() {} 35 36 const T& operator[](int index) const 37 { 38 return m_Buffer[index]; 39 } 40 T& operator[](int index) 41 { 42 return m_Buffer[index]; 43 } 44 Add(T v)45 void Add(T v) 46 { 47 *Add() = v; 48 } Add()49 T* Add() 50 { 51 NN_MAX_TASSERT_(m_Length, NUM_OF_T - 1); 52 53 T* p = &m_Buffer[m_Length]; 54 m_Length++; 55 return p; 56 } 57 Remove(int index)58 void Remove(int index) 59 { 60 NN_MIN_TASSERT_(m_Length, 1); 61 62 const int last = m_Length - 1; 63 if( index != last ) 64 { 65 m_Buffer[index] = m_Buffer[last]; 66 } 67 m_Length--; 68 } Clear()69 void Clear() 70 { 71 m_Length = 0; 72 } 73 GetBegin()74 T* GetBegin() { return &m_Buffer[0]; } GetEnd()75 T* GetEnd() { return &m_Buffer[m_Length]; } GetBegin()76 const T* GetBegin() const { return &m_Buffer[0]; } GetEnd()77 const T* GetEnd() const { return &m_Buffer[m_Length]; } GetLength()78 s32 GetLength() const { return m_Length; } 79 80 81 private: 82 u16 m_Length; 83 NN_PADDING2; 84 NN_PADDING4; 85 T m_Buffer[NUM_OF_T]; 86 }; 87 88 }} 89 90 #endif 91 92 #endif // ifndef NN_FND_FND_FIXEDBUFFERVECTOR_H_ 93