Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
alignment.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 
8 Copyright(c) 2014 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
27 ******************************************************************************/
28 
29 #ifndef __ETL_ALIGNEMENT__
30 #define __ETL_ALIGNEMENT__
31 
32 #include "type_traits.h"
33 
37 
38 #if !defined(COMPILER_IAR)
39 
40 #if defined(COMPILER_MICROSOFT)
41 #define ETL_ALIGNMENT_PRE(n) __declspec(align(n))
42 #define ETL_ALIGNMENT_POST(n)
43 #endif
44 
45 #if defined(COMPILER_GCC)
46 #define ETL_ALIGNMENT_PRE(n)
47 #define ETL_ALIGNMENT_POST(n) __attribute__((aligned(n)))
48 #endif
49 
50 #if defined (COMPILER_KEIL)
51 #define ETL_ALIGNMENT_PRE(n)
52 #define ETL_ALIGNMENT_POST(n) __attribute__((aligned(n)))
53 #endif
54 
55 namespace etl
56 {
58  template <typename T, const size_t ALIGNMENT>
59  struct align_at;
60 
62  template <typename T>
63  struct align_at<T, 1>
64  {
65  ETL_ALIGNMENT_PRE(1) T value ETL_ALIGNMENT_POST(1);
66  };
67 
69  template <typename T>
70  struct align_at<T, 2>
71  {
72  ETL_ALIGNMENT_PRE(2) T value ETL_ALIGNMENT_POST(2);
73  };
74 
76  template <typename T>
77  struct align_at<T, 4>
78  {
79  ETL_ALIGNMENT_PRE(4) T value ETL_ALIGNMENT_POST(4);
80  };
81 
83  template <typename T>
84  struct align_at<T, 8>
85  {
86  ETL_ALIGNMENT_PRE(8) T value ETL_ALIGNMENT_POST(8);
87  };
88 
90  template <typename T>
91  struct align_at<T, 16>
92  {
93  ETL_ALIGNMENT_PRE(16) T value ETL_ALIGNMENT_POST(16);
94  };
95 
97  template <typename TValue, typename TAlign>
98  struct align_as : public align_at<TValue, etl::alignment_of<TAlign>::value>
99  {
100  };
101 }
102 #endif
103 
104 #undef ETL_ALIGNMENT_PRE
105 #undef ETL_ALIGNMENT_POST
106 
107 #endif
Definition: algorithm.h:43
Template declaration.
Definition: alignment.h:59
Align As.
Definition: alignment.h:98