AlignedArray.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_ALIGNEDARRAY_H_
36 #define _BLAZE_UTIL_ALIGNEDARRAY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/system/Alignment.h>
45 #include <blaze/util/Assert.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // CLASS DEFINITION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
64 template< typename Type // Data type of the elements
65  , size_t N // Number of elements
66  , size_t Alignment > // Array alignment
67 struct AlignedArrayHelper;
69 //*************************************************************************************************
70 
71 
72 //*************************************************************************************************
77 template< typename Type // Data type of the elements
78  , size_t N > // Number of elements
79 struct AlignedArrayHelper<Type,N,1UL>
80 {
81  BLAZE_ALIGN( 1UL ) Type v_[N];
82 };
84 //*************************************************************************************************
85 
86 
87 //*************************************************************************************************
92 template< typename Type // Data type of the elements
93  , size_t N > // Number of elements
94 struct AlignedArrayHelper<Type,N,2UL>
95 {
96  BLAZE_ALIGN( 2UL ) Type v_[N];
97 };
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
107 template< typename Type // Data type of the elements
108  , size_t N > // Number of elements
109 struct AlignedArrayHelper<Type,N,4UL>
110 {
111  BLAZE_ALIGN( 4UL ) Type v_[N];
112 };
114 //*************************************************************************************************
115 
116 
117 //*************************************************************************************************
122 template< typename Type // Data type of the elements
123  , size_t N > // Number of elements
124 struct AlignedArrayHelper<Type,N,8UL>
125 {
126  BLAZE_ALIGN( 8UL ) Type v_[N];
127 };
129 //*************************************************************************************************
130 
131 
132 //*************************************************************************************************
137 template< typename Type // Data type of the elements
138  , size_t N > // Number of elements
139 struct AlignedArrayHelper<Type,N,16UL>
140 {
141  BLAZE_ALIGN( 16UL ) Type v_[N];
142 };
144 //*************************************************************************************************
145 
146 
147 //*************************************************************************************************
152 template< typename Type // Data type of the elements
153  , size_t N > // Number of elements
154 struct AlignedArrayHelper<Type,N,32UL>
155 {
156  BLAZE_ALIGN( 32UL ) Type v_[N];
157 };
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
167 template< typename Type // Data type of the elements
168  , size_t N > // Number of elements
169 struct AlignedArrayHelper<Type,N,64UL>
170 {
171  BLAZE_ALIGN( 64UL ) Type v_[N];
172 };
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
182 template< typename Type // Data type of the elements
183  , size_t N > // Number of elements
184 struct AlignedArrayHelper<Type,N,128UL>
185 {
186  BLAZE_ALIGN( 128UL ) Type v_[N];
187 };
189 //*************************************************************************************************
190 
191 
192 //*************************************************************************************************
197 template< typename Type // Data type of the elements
198  , size_t N > // Number of elements
199 struct AlignedArrayHelper<Type,N,256UL>
200 {
201  BLAZE_ALIGN( 256UL ) Type v_[N];
202 };
204 //*************************************************************************************************
205 
206 
207 
208 
209 
210 
211 
212 
213 //=================================================================================================
214 //
215 // CLASS DEFINITION
216 //
217 //=================================================================================================
218 
219 //*************************************************************************************************
261 template< typename Type // Data type of the elements
262  , size_t N // Number of elements
263  , size_t Alignment = AlignmentOf<Type>::value > // Array alignment
265 {
266  public:
267  //**Type definitions****************************************************************************
268  typedef Type* Pointer;
269  typedef const Type* ConstPointer;
270  typedef Type& Reference;
271  typedef const Type& ConstReference;
272  //**********************************************************************************************
273 
274  //**Constructors********************************************************************************
277  inline AlignedArray();
279  //**********************************************************************************************
280 
281  //**Destructor**********************************************************************************
282  // No explicitly declared destructor.
283  //**********************************************************************************************
284 
285  //**Conversion operators************************************************************************
288  inline operator Pointer ();
289  inline operator ConstPointer() const;
291  //**********************************************************************************************
292 
293  //**Data access functions***********************************************************************
296  inline Reference operator[]( size_t index );
297  inline ConstReference operator[]( size_t index ) const;
298  inline Pointer data();
299  inline ConstPointer data() const;
301  //**********************************************************************************************
302 
303  private:
304  //**Member variables****************************************************************************
308  AlignedArrayHelper<Type,N,Alignment> array_;
309 
310 
311  //**********************************************************************************************
312 
313  //**Compile time checks*************************************************************************
318  //**********************************************************************************************
319 };
320 //*************************************************************************************************
321 
322 
323 
324 
325 //=================================================================================================
326 //
327 // CONSTRUCTORS
328 //
329 //=================================================================================================
330 
331 //*************************************************************************************************
334 template< typename Type // Data type of the elements
335  , size_t N // Number of elements
336  , size_t Alignment > // Array alignment
338 {
339  BLAZE_INTERNAL_ASSERT( checkAlignment( array_.v_ ), "Invalid alignment detected" );
340 }
341 //*************************************************************************************************
342 
343 
344 
345 
346 //=================================================================================================
347 //
348 // CONVERSION OPERATORS
349 //
350 //=================================================================================================
351 
352 //*************************************************************************************************
357 template< typename Type // Data type of the elements
358  , size_t N // Number of elements
359  , size_t Alignment > // Array alignment
361 {
362  return array_.v_;
363 }
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
372 template< typename Type // Data type of the elements
373  , size_t N // Number of elements
374  , size_t Alignment > // Array alignment
376 {
377  return array_.v_;
378 }
379 //*************************************************************************************************
380 
381 
382 
383 
384 //=================================================================================================
385 //
386 // DATA ACCESS FUNCTIONS
387 //
388 //=================================================================================================
389 
390 //*************************************************************************************************
398 template< typename Type // Data type of the elements
399  , size_t N // Number of elements
400  , size_t Alignment > // Array alignment
403 {
404  BLAZE_USER_ASSERT( index < N, "Invalid array access index" );
405  return array_.v_[index];
406 }
407 //*************************************************************************************************
408 
409 
410 //*************************************************************************************************
418 template< typename Type // Data type of the elements
419  , size_t N // Number of elements
420  , size_t Alignment > // Array alignment
423 {
424  BLAZE_USER_ASSERT( index < N, "Invalid array access index" );
425  return array_.v_[index];
426 }
427 //*************************************************************************************************
428 
429 
430 //*************************************************************************************************
437 template< typename Type // Data type of the elements
438  , size_t N // Number of elements
439  , size_t Alignment > // Array alignment
442 {
443  return array_.v_;
444 }
445 //*************************************************************************************************
446 
447 
448 //*************************************************************************************************
455 template< typename Type // Data type of the elements
456  , size_t N // Number of elements
457  , size_t Alignment > // Array alignment
460 {
461  return array_.v_;
462 }
463 //*************************************************************************************************
464 
465 } // namespace blaze
466 
467 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the AlignmentOf type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
AlignedArray()
The default constructor for AlignedArray.
Definition: AlignedArray.h:337
Pointer data()
Low-level data access to the array elements.
Definition: AlignedArray.h:441
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const Type * ConstPointer
Pointer to a constant array element.
Definition: AlignedArray.h:269
Constraint on the data type.
Type * Pointer
Pointer to a non-constant array element.
Definition: AlignedArray.h:268
const Type & ConstReference
Reference to a constant array element.
Definition: AlignedArray.h:271
Header file for run time assertion macros.
Constraint on the data type.
Type & Reference
Reference to a non-constant array element.
Definition: AlignedArray.h:270
Reference operator[](size_t index)
Subscript operator for the direct access to the array elements.
Definition: AlignedArray.h:402
bool checkAlignment(const T *address)
Checks the alignment of the given.
Definition: AlignmentCheck.h:68
Header file for the alignment check function.
System specific memory alignment definitions.
Implementation of a static array with a fixed alignment.The AlignedArray class template represents a ...
Definition: AlignedArray.h:264
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101