cartobase  4.5.0
block.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef CARTOBASE_BLOCK_BLOCK_H
35 #define CARTOBASE_BLOCK_BLOCK_H
36 
37 
39 #include <iterator>
40 #include <assert.h>
41 
42 
43 namespace carto
44 {
45 
61 template < class T, size_t N >
62 struct block
63 {
64 
65  typedef T value_type;
66  typedef value_type* pointer;
67  typedef const value_type* const_pointer;
69  typedef const value_type& const_reference;
70 
71  typedef ptrdiff_t difference_type;
72  typedef size_t size_type;
73 
74  typedef pointer iterator;
76 
77 #if defined(CARTO_NO_PARTIAL_TEMPLATE_SPECIALIZATION)
78 
79  typedef std::reverse_iterator< iterator, value_type > reverse_iterator;
80  typedef std::reverse_iterator< const_iterator,
82 #else
83 
84  typedef std::reverse_iterator< iterator > reverse_iterator;
85  typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
86 
87 #endif
88 
89  reference operator[]( size_t d );
90  const_reference operator[]( size_t d ) const;
91 
92  iterator begin();
93  iterator end();
94  const_iterator begin() const;
95  const_iterator end() const;
100 
101  size_type size() const;
102  size_type max_size() const;
103  bool empty() const;
104 
105  T data[ N ];
106 
107 };
108 
109 
110 } // namespace carto
111 
112 
113 template < class T, size_t N>
114 inline
117 {
118 
119  assert( d < N );
120  return data[ d ];
121 
122 }
123 
124 
125 template < class T, size_t N >
126 inline
129 {
130 
131  assert( d < N );
132  return data[ d ];
133 
134 }
135 
136 
137 template < class T, size_t N >
138 inline
140 {
141 
142  return data;
143 
144 }
145 
146 
147 template < class T, size_t N >
148 inline
150 {
151 
152  return data + N;
153 
154 }
155 
156 
157 template < class T, size_t N >
158 inline
161 {
162 
163  return data;
164 
165 }
166 
167 
168 template < class T, size_t N >
169 inline
171 {
172 
173  return data + N;
174 
175 }
176 
177 
178 template < class T, size_t N >
179 inline
181 {
182 
183  return reverse_iterator( end() );
184 
185 }
186 
187 
188 template < class T, size_t N >
189 inline
191 {
192 
193  return reverse_iterator( begin() );
194 
195 }
196 
197 
198 template < class T, size_t N >
199 inline
202 {
203 
204  return const_reverse_iterator( end() );
205 
206 }
207 
208 
209 template < class T, size_t N >
210 inline
213 {
214 
215  return const_reverse_iterator( begin() );
216 
217 }
218 
219 
220 template < class T, size_t N >
221 inline
223 {
224 
225  return N;
226 
227 }
228 
229 
230 template < class T, size_t N >
231 inline
233 {
234 
235  return N;
236 
237 }
238 
239 
240 template < class T, size_t N >
241 inline
243 {
244 
245  return N == 0;
246 
247 }
248 
249 
250 template < class T, size_t N >
251 inline
253  const carto::block< T, N >& b2)
254 {
255 
256  for ( size_t n = 0; n < N; ++n )
257  if ( b1.data[ n ] != b2.data[ n ] )
258  return false;
259  return true;
260 
261 }
262 
263 
264 #endif
iterator begin()
Definition: block.h:139
std::reverse_iterator< iterator > reverse_iterator
Definition: block.h:84
pointer iterator
Definition: block.h:74
size_t size_type
Definition: block.h:72
reverse_iterator rbegin()
Definition: block.h:180
const_pointer const_iterator
Definition: block.h:75
size_type max_size() const
Definition: block.h:232
bool operator==(const carto::block< T, N > &b1, const carto::block< T, N > &b2)
Definition: block.h:252
This array class extends the STL.
Definition: block.h:62
const value_type & const_reference
Definition: block.h:69
T data[N]
Definition: block.h:105
value_type * pointer
Definition: block.h:66
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: block.h:85
value_type & reference
Definition: block.h:68
T value_type
Definition: block.h:65
iterator end()
Definition: block.h:149
ptrdiff_t difference_type
Definition: block.h:71
bool empty() const
Definition: block.h:242
size_type size() const
Definition: block.h:222
const value_type * const_pointer
Definition: block.h:67
reference operator[](size_t d)
Definition: block.h:116
reverse_iterator rend()
Definition: block.h:190