libcommonc++  0.7
Array.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Array_hxx
24 #define __ccxx_Array_hxx
25 
26 #include <commonc++/Common.h++>
28 
29 namespace ccxx {
30 
37 template <typename T, uint_t SIZE> class Array
38 {
39  public:
40 
41  typedef T value_type;
42  typedef T* iterator;
43  typedef const T* const_iterator;
44  typedef T& reference;
45  typedef const T& const_reference;
46 
48  : _size(SIZE)
49  { }
50 
52  { }
53 
59  T& operator[](int index)
60  {
61  if((index < 0) || (index >= static_cast<int>(_size)))
62  throw OutOfBoundsException();
63 
64  return(_data[index]);
65  }
66 
72  const T& operator[](int index) const
73  {
74  if((index < 0) || (index >= _size))
75  throw OutOfBoundsException();
76 
77  return(_data[index]);
78  }
79 
80  operator T*()
81  { return(_data); }
82 
83  iterator begin()
84  { return(_data); }
85 
86  const_iterator begin() const
87  { return(_data); }
88 
89  iterator end()
90  { return(_data + _size); }
91 
92  const_iterator end() const
93  { return(_data + _size); }
94 
95  uint_t size() const
96  { return(_size); }
97 
98  private:
99 
100  uint_t _size;
101  T _data[SIZE];
102 };
103 
104 } // namespace ccxx
105 
106 #endif // __ccxx_Array_hxx
Array()
Definition: Array.h++:47
T value_type
Definition: Array.h++:41
iterator begin()
Definition: Array.h++:83
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
const_iterator begin() const
Definition: Array.h++:86
T & operator[](int index)
Index operator.
Definition: Array.h++:59
const T & const_reference
Definition: Array.h++:45
An exception indicating that an attempted operation would result in an out-of-range array index acces...
Definition: OutOfBoundsException.h++:38
const T * const_iterator
Definition: Array.h++:43
~Array()
Definition: Array.h++:51
T & reference
Definition: Array.h++:44
iterator end()
Definition: Array.h++:89
A simple object wrapper for arrays.
Definition: Array.h++:37
const T & operator[](int index) const
Index operator.
Definition: Array.h++:72
T * iterator
Definition: Array.h++:42
uint_t size() const
Definition: Array.h++:95
Definition: AllocationMap.c++:25
const_iterator end() const
Definition: Array.h++:92