Embedded Template Library  1.0
platform.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2016 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_PLATFORM_INCLUDED
32 #define ETL_PLATFORM_INCLUDED
33 
34 #include <stdint.h>
35 #include <limits.h>
36 
37 // Define a debug macro
38 #if (defined(_DEBUG) || defined(DEBUG)) && !defined(ETL_DEBUG)
39  #define ETL_DEBUG
40 #endif
41 
42 // Determine the bit width of the platform.
43 #define ETL_PLATFORM_16BIT (UINT16_MAX == UINTPTR_MAX)
44 #define ETL_PLATFORM_32BIT (UINT32_MAX == UINTPTR_MAX)
45 #define ETL_PLATFORM_64BIT (UINT64_MAX == UINTPTR_MAX)
46 
47 // Include the user's profile definition.
48 #if !defined(ETL_NO_PROFILE_HEADER) && defined(__has_include)
49  #if !__has_include("etl_profile.h")
50  #define ETL_NO_PROFILE_HEADER
51  #endif
52 #endif
53 
54 #if !defined(ETL_NO_PROFILE_HEADER)
55  #include "etl_profile.h"
56 #endif
57 
58 // Helper macro, so we don't have to use double negatives.
59 // The ETL will use the STL, unless ETL_NO_STL is defined.
60 // With this macro we can use '#if ETL_USING_STL' instead of '#if !ETL_NO_STL' in the code.
61 #if defined(ETL_NO_STL)
62  #define ETL_USING_STL 0
63  #define ETL_NOT_USING_STL 1
64 #else
65  #define ETL_USING_STL 1
66  #define ETL_NOT_USING_STL 0
67 #endif
68 
69 // Helper macros for ETL_STLPORT.
70 #if defined(ETL_STLPORT)
71  #define ETL_USING_STLPORT 1
72  #define ETL_NOT_USING_STLPORT 0
73 #else
74  #define ETL_USING_STLPORT 0
75  #define ETL_NOT_USING_STLPORT 1
76 #endif
77 
78 // Some targets do not support 8bit types.
79 #if (CHAR_BIT == 8)
80  #define ETL_USING_8BIT_TYPES 1
81  #define ETL_NOT_USING_8BIT_TYPES 0
82 #else
83  #define ETL_USING_8BIT_TYPES 0
84  #define ETL_NOT_USING_8BIT_TYPES 1
85 #endif
86 
87 #define ETL_8BIT_SUPPORT (CHAR_BIT == 8)
88 
89 // Helper macro for ETL_NO_64BIT_TYPES.
90 #if defined(ETL_NO_64BIT_TYPES)
91  #define ETL_USING_64BIT_TYPES 0
92  #define ETL_NOT_USING_64BIT_TYPES 1
93 #else
94  #define ETL_USING_64BIT_TYPES 1
95  #define ETL_NOT_USING_64BIT_TYPES 0
96 #endif
97 
98 // Figure out things about the compiler, if haven't already done so in etl_profile.h
101 
102 // See if we can determine the OS we're compiling on, if haven't already done so in etl_profile.h
104 
105 // Figure out if we can use the standard library <new> header, if haven't already done so in etl_profile.h
106 #if !defined(ETL_USING_STD_NEW)
107  #if defined(__has_include)
108  #define ETL_USING_STD_NEW __has_include(<new>)
109  #elif ETL_NOT_USING_STL || (defined(ARDUINO) && defined(__AVR__))
110  #define ETL_USING_STD_NEW 0
111  #else
112  #define ETL_USING_STD_NEW 1
113  #endif
114 #endif
115 
116 // Option to force string construction from a character pointer to be explicit.
117 #if defined(ETL_FORCE_EXPLICIT_STRING_CONVERSION_FROM_CHAR)
118  #define ETL_EXPLICIT_STRING_FROM_CHAR explicit
119 #else
120  #define ETL_EXPLICIT_STRING_FROM_CHAR
121 #endif
122 
123 // Option to disable truncation checks for strings.
124 #if defined(ETL_DISABLE_STRING_TRUNCATION_CHECKS)
125  #define ETL_STRING_TRUNCATION_CHECKS_ENABLED 0
126 #else
127  #define ETL_STRING_TRUNCATION_CHECKS_ENABLED 1
128 #endif
129 
130 // Option to disable clear-after-use functionality for strings.
131 #if defined(ETL_DISABLE_STRING_CLEAR_AFTER_USE)
132  #define ETL_STRING_CLEAR_AFTER_USE_ENABLED 0
133 #else
134  #define ETL_STRING_CLEAR_AFTER_USE_ENABLED 1
135 #endif
136 
137 // The macros below are dependent on the profile.
138 // C++11
139 #if ETL_CPP11_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
140  #define ETL_CONSTEXPR constexpr
141  #define ETL_CONSTANT constexpr
142  #define ETL_DELETE = delete
143  #define ETL_EXPLICIT explicit
144  #define ETL_OVERRIDE override
145  #define ETL_FINAL final
146  #define ETL_NORETURN [[noreturn]]
147 
148  #if defined(ETL_THROW_EXCEPTIONS)
149  #define ETL_NOEXCEPT noexcept
150  #define ETL_NOEXCEPT_EXPR(expression) noexcept(expression)
151  #else
152  #define ETL_NOEXCEPT
153  #define ETL_NOEXCEPT_EXPR(expression)
154  #endif
155 #else
156  #define ETL_CONSTEXPR
157  #define ETL_CONSTANT const
158  #define ETL_DELETE
159  #define ETL_EXPLICIT
160  #define ETL_OVERRIDE
161  #define ETL_FINAL
162  #define ETL_NORETURN
163  #define ETL_NOEXCEPT
164  #define ETL_NOEXCEPT_EXPR(expression)
165 #endif
166 
167 // C++14
168 #if ETL_CPP14_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
169  #define ETL_CONSTEXPR14 constexpr
170  #define ETL_DEPRECATED [[deprecated]]
171  #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]]
172 #else
173  #define ETL_CONSTEXPR14
174  #define ETL_DEPRECATED
175  #define ETL_DEPRECATED_REASON(reason)
176 #endif
177 
178 // C++17
179 #if ETL_CPP17_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
180  #define ETL_CONSTEXPR17 constexpr
181  #define ETL_IF_CONSTEXPR constexpr
182  #define ETL_NODISCARD [[nodiscard]]
183  #define ETL_FALLTHROUGH [[fallthrough]]
184  #define ETL_INLINE_VAR inline
185 #else
186  #define ETL_CONSTEXPR17
187  #define ETL_IF_CONSTEXPR
188  #define ETL_NODISCARD
189  #define ETL_FALLTHROUGH
190  #define ETL_INLINE_VAR
191 #endif
192 
193 // C++20
194 #if ETL_CPP20_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
195  #define ETL_LIKELY [[likely]]
196  #define ETL_UNLIKELY [[unlikely]]
197  #define ETL_CONSTEXPR20 constexpr
198  #define ETL_CONSTEVAL consteval
199  #define ETL_CONSTINIT constinit
200 #else
201  #define ETL_LIKELY
202  #define ETL_UNLIKELY
203  #define ETL_CONSTEXPR20
204  #define ETL_CONSTEVAL
205  #define ETL_CONSTINIT
206 #endif
207 
208 // Sort out namespaces for STL/No STL options.
210 
211 #endif