Array.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2009  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   T& operator[](uint_t index) throw(OutOfBoundsException)
00063   {
00064     if(index >= _size)
00065       throw OutOfBoundsException();
00066 
00067     return(_data[index]);
00068   }
00069 
00070   const T& operator[](int index) const throw(OutOfBoundsException)
00071   {
00072     if((index < 0) || (index >= _size))
00073       throw OutOfBoundsException();
00074 
00075     return(_data[index]);
00076   }
00077 
00078   const T& operator[](uint_t index) const throw(OutOfBoundsException)
00079   {
00080     if(index >= _size)
00081       throw OutOfBoundsException();
00082 
00083     return(_data[index]);
00084   }
00085 
00086   operator T*() throw()
00087   { return(_data); }
00088 
00089   iterator begin() throw()
00090   { return(_data); }
00091 
00092   const_iterator begin() const throw()
00093   { return(_data); }
00094 
00095   iterator end() throw()
00096   { return(_data + _size); }
00097 
00098   const_iterator end() const throw()
00099   { return(_data + _size); }
00100 
00101   size_t size() const throw()
00102   { return(_size); }
00103 
00104   private:
00105 
00106   size_t _size;
00107   T _data[SIZE];
00108 };
00109 
00110 }; // namespace ccxx
00111 
00112 #endif // __ccxx_Array_hxx
00113 
00114 /* end of header file */

Generated on Sat Apr 17 23:03:05 2010 for libcommonc++ by  doxygen 1.5.9