summaryrefslogtreecommitdiffstats
path: root/ue5/array.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ue5/array.hpp')
-rw-r--r--ue5/array.hpp181
1 files changed, 178 insertions, 3 deletions
diff --git a/ue5/array.hpp b/ue5/array.hpp
index 0acd37d..a78ff56 100644
--- a/ue5/array.hpp
+++ b/ue5/array.hpp
@@ -1,3 +1,10 @@
1/**
2 * @module array
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Class template array
5 * @date 13.06.2009
6 */
7
1#ifndef ARRAY_H 8#ifndef ARRAY_H
2#define ARRAY_H 9#define ARRAY_H
3 10
@@ -10,72 +17,208 @@
10 17
11namespace Ti 18namespace Ti
12{ 19{
20 /**
21 * @class array
22 *
23 * Array defines a class template for storing fixed-size sequences of objects.
24 */
13 template<typename T, std::size_t N> 25 template<typename T, std::size_t N>
14 struct array 26 struct array
15 { 27 {
28 /** lvalue of T */
16 typedef T& reference; 29 typedef T& reference;
30 /** constant lvalue of T */
17 typedef const T& const_reference; 31 typedef const T& const_reference;
32 /** iterator type whose value type is T */
18 typedef T* iterator; 33 typedef T* iterator;
34 /** constant iterator type whose value type is T */
19 typedef const T* const_iterator; 35 typedef const T* const_iterator;
36 /** unsigned integral type */
20 typedef std::size_t size_type; 37 typedef std::size_t size_type;
21 38
39 /* we don't suppport zero-sized arrays */
22 static_assert(N != 0, "array<T, 0> not allowed"); 40 static_assert(N != 0, "array<T, 0> not allowed");
23 41
42 /**
43 * @method fill
44 * @brief Fills container with elements of u
45 * @param u object to fill array with
46 * @return return N
47 * @globalvars none
48 * @exception none
49 * @pre requires CopyAssignable<T> void fill(const T& u)
50 * @post none
51 */
24 void fill(const T& u) 52 void fill(const T& u)
25 { 53 {
26 std::fill_n(begin(), N, u); 54 std::fill_n(begin(), N, u);
27 } 55 }
28 56
29 void swap(array<T,N> & other) 57 /**
58 * @method swap
59 * @brief Exchanges the contents of *this and other.
60 * @param other object to swap with
61 * @return -
62 * @globalvars none
63 * @exception none
64 * @pre none
65 * @post none
66 */
67 void swap(array<T,N>& other)
30 { 68 {
31 std::swap_ranges(begin(), end(), other.begin()); 69 std::swap_ranges(begin(), end(), other.begin());
32 } 70 }
33 71
72 /**
73 * @method begin
74 * @brief Get an iterator referring to the first element in the container
75 * @param -
76 * @return iterator referring to the first element in the container.
77 * @globalvars none
78 * @exception none
79 * @pre none
80 * @post none
81 */
34 iterator begin() 82 iterator begin()
35 { 83 {
36 return m_data; 84 return m_data;
37 } 85 }
38 86
87 /**
88 * @method begin
89 * @brief Get a constant iterator referring to the first element in the
90 * container
91 * @param -
92 * @return constant iterator referring to the first element in the container.
93 * @globalvars none
94 * @exception none
95 * @pre none
96 * @post none
97 */
39 const_iterator begin() const 98 const_iterator begin() const
40 { 99 {
41 return m_data; 100 return m_data;
42 } 101 }
43 102
103 /**
104 * @method end
105 * @brief Get an iterator which is the past-the-end value for the container.
106 * @param -
107 * @return iterator which is the past-the-end value for the container
108 * @globalvars none
109 * @exception none
110 * @pre none
111 * @post none
112 */
44 iterator end() 113 iterator end()
45 { 114 {
46 return m_data + N; 115 return m_data + N;
47 } 116 }
48 117
118 /**
119 * @method end
120 * @brief Get a constant iterator which is the past-the-end value for the
121 * container.
122 * @param -
123 * @return constant iterator which is the past-the-end value for the container
124 * @globalvars none
125 * @exception none
126 * @pre none
127 * @post none
128 */
49 const_iterator end() const 129 const_iterator end() const
50 { 130 {
51 return m_data + N; 131 return m_data + N;
52 } 132 }
53 133
134 /**
135 * @method size
136 * @brief Get number of elements in the container
137 * @param -
138 * @return return N
139 * @globalvars none
140 * @exception none
141 * @pre none
142 * @post none
143 */
54 size_type size() const 144 size_type size() const
55 { 145 {
56 return N; 146 return N;
57 } 147 }
58 148
149 /**
150 * @method max_size
151 * @brief Get maximal number of elements which fit into the container
152 * @param -
153 * @return return N
154 * @globalvars none
155 * @exception none
156 * @pre none
157 * @post none
158 */
59 size_type max_size() const 159 size_type max_size() const
60 { 160 {
61 return N; 161 return N;
62 } 162 }
63 163
164 /**
165 * @method empty
166 * @brief Check if container is empty
167 * @param -
168 * @return always false
169 * @globalvars none
170 * @exception none
171 * @pre none
172 * @post none
173 */
64 bool empty() const 174 bool empty() const
65 { 175 {
66 return false; /* size() == 0 */ 176 return false; /* size() == 0 */
67 } 177 }
68 178
179 /**
180 * @method operator[]
181 * @brief operator []
182 * @param n position of an element in the array
183 * @return reference to the element at position n in the container
184 * @globalvars none
185 * @exception none
186 * @pre none
187 * @post none
188 */
69 reference operator[](size_type n) 189 reference operator[](size_type n)
70 { 190 {
71 return m_data[n]; 191 return m_data[n];
72 } 192 }
73 193
194 /**
195 * @method operator[]
196 * @brief operator []
197 * @param n position of an element in the array
198 * @return constant reference to the element at position n in the container
199 * @globalvars none
200 * @exception none
201 * @pre none
202 * @post none
203 */
74 const_reference operator[](size_type n) const 204 const_reference operator[](size_type n) const
75 { 205 {
76 return m_data[n]; 206 return m_data[n];
77 } 207 }
78 208
209 /**
210 * @method at
211 * @brief Get reference to the element at position n
212 * @param n position of an element in the array
213 * @return reference to the element at position n in the container.
214 * The difference between this member function and member operator
215 * function operator[] is that at signals if the requested
216 * position is out of range by throwing an out_of_range exception.
217 * @globalvars none
218 * @exception out_of_range
219 * @pre none
220 * @post none
221 */
79 reference at(size_type n) 222 reference at(size_type n)
80 { 223 {
81 if (n >= N) 224 if (n >= N)
@@ -83,6 +226,19 @@ namespace Ti
83 return m_data[n]; 226 return m_data[n];
84 } 227 }
85 228
229 /**
230 * @method at
231 * @brief Get constant reference to the element at position n
232 * @param n position of an element in the array
233 * @return constant reference to the element at position n in the container.
234 * The difference between this member function and member operator
235 * function operator[] is that at signals if the requested
236 * position is out of range by throwing an out_of_range exception.
237 * @globalvars none
238 * @exception out_of_range
239 * @pre none
240 * @post none
241 */
86 const_reference at(size_type n) const 242 const_reference at(size_type n) const
87 { 243 {
88 if (n >= N) 244 if (n >= N)
@@ -90,22 +246,41 @@ namespace Ti
90 return m_data[n]; 246 return m_data[n];
91 } 247 }
92 248
249 /**
250 * @method data
251 * @brief Check if container is empty
252 * @param -
253 * @return returns enclosed array
254 * @globalvars none
255 * @exception none
256 * @pre none
257 * @post none
258 */
93 T* data() 259 T* data()
94 { 260 {
95 return m_data; 261 return m_data;
96 } 262 }
97 263
98 private: 264 private:
265 /** enclosed array */
99 T m_data[N]; 266 T m_data[N];
100 }; 267 };
101 268
102 /* std::move returns lvalue as rvalue */ 269 /**
270 * @method make_array
271 * @brief Get an rvalue of an empty array
272 * @param none
273 * @return rvalue of an empty array
274 * @globalvars none
275 * @exception none
276 * @pre none
277 * @post none
278 */
103 template<typename T, std::size_t N> 279 template<typename T, std::size_t N>
104 array<T, N>&& make_array() 280 array<T, N>&& make_array()
105 { 281 {
106 return std::move(array<T, N>()); 282 return std::move(array<T, N>());
107 } 283 }
108
109} // namespace 284} // namespace
110 285
111#endif 286#endif