00001 /* --------------------------------------------------------------------------- 00002 commonc++ - A C++ Common Class Library 00003 Copyright (C) 2005-2012 Mark A Lindner 00004 00005 This file is part of commonc++. 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public 00018 License along with this library; if not, write to the Free 00019 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 --------------------------------------------------------------------------- 00021 */ 00022 00023 #ifndef __ccxx_Array_hxx 00024 #define __ccxx_Array_hxx 00025 00026 #include <commonc++/Common.h++> 00027 #include <commonc++/OutOfBoundsException.h++> 00028 00029 namespace ccxx { 00030 00037 template <typename T, size_t SIZE> class Array 00038 { 00039 public: 00040 00041 typedef T value_type; 00042 typedef T* iterator; 00043 typedef const T* const_iterator; 00044 typedef T& reference; 00045 typedef const T& const_reference; 00046 00047 Array() throw() 00048 : _size(SIZE) 00049 { } 00050 00051 ~Array() throw() 00052 { } 00053 00054 T& operator[](int index) throw(OutOfBoundsException) 00055 { 00056 if((index < 0) || (index >= static_cast<int>(_size))) 00057 throw OutOfBoundsException(); 00058 00059 return(_data[index]); 00060 } 00061 00062 const T& operator[](int index) const throw(OutOfBoundsException) 00063 { 00064 if((index < 0) || (index >= _size)) 00065 throw OutOfBoundsException(); 00066 00067 return(_data[index]); 00068 } 00069 00070 operator T*() throw() 00071 { return(_data); } 00072 00073 iterator begin() throw() 00074 { return(_data); } 00075 00076 const_iterator begin() const throw() 00077 { return(_data); } 00078 00079 iterator end() throw() 00080 { return(_data + _size); } 00081 00082 const_iterator end() const throw() 00083 { return(_data + _size); } 00084 00085 size_t size() const throw() 00086 { return(_size); } 00087 00088 private: 00089 00090 size_t _size; 00091 T _data[SIZE]; 00092 }; 00093 00094 }; // namespace ccxx 00095 00096 #endif // __ccxx_Array_hxx 00097 00098 /* end of header file */
1.6.3