00001 /* 00002 * stack_array.h 00003 * 00004 * Copyright (C) 2006 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 * Array on the stack. 00032 */ 00033 00034 #ifndef WAVEPACKET_UTIL_STACK_ARRAY_H__ 00035 #define WAVEPACKET_UTIL_STACK_ARRAY_H__ 00036 00037 // includes -------------------------------------------------------------------- 00038 #include "common/common.h" 00039 00040 00041 /// \ingroup util 00042 00043 //////////////////////////////////////////////////////////////////////////////// 00044 // 00045 // stack_array<T, N> 00046 // 00047 // 1D array held on the stack 00048 // 00049 //////////////////////////////////////////////////////////////////////////////// 00050 template <class T, class N> 00051 class stack_array { 00052 public: 00053 typedef stack_array<T,N> stack_t; 00054 00055 stack_array(void) throw() { this->clear(); } 00056 00057 const T& operator[](IN int i) const throw() { 00058 ASSERT(i >= 0, "i = %d", i); 00059 ASSERT(i < N::eMaxArraySize, "i = %d", i); 00060 return m_array[i]; 00061 } 00062 00063 T& operator[](IN int i) throw() { 00064 ASSERT(i >= 0, "i = %d", i); 00065 ASSERT(i < N::eMaxArraySize, "i = %d", i); 00066 return m_array[i]; 00067 } 00068 00069 int size(void) const throw() { 00070 return m_size; 00071 } 00072 00073 void clear(void) throw() { 00074 m_size = 0; 00075 } 00076 00077 const T * getDataPointer(void) const throw() { 00078 return m_array; 00079 } 00080 00081 T * getDataPointer(void) throw() { 00082 return m_array; 00083 } 00084 00085 void push_back(IN T t) throw() { 00086 ASSERT(m_size < N::eMaxArraySize, 00087 "Stack array has just blown out"); 00088 m_array[m_size] = t; 00089 ++m_size; 00090 } 00091 00092 private: 00093 T m_array[N::eMaxArraySize]; 00094 int m_size; 00095 }; 00096 00097 00098 00099 #endif // WAVEPACKET_UTIL_STACK_ARRAY_H__ 00100