Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
largest_generator.h
00001 ///\file 00002 00003 /****************************************************************************** 00004 The MIT License(MIT) 00005 00006 Embedded Template Library. 00007 https://github.com/ETLCPP/etl 00008 https://www.etlcpp.com 00009 00010 Copyright(c) 2014 jwellbelove 00011 00012 Permission is hereby granted, free of charge, to any person obtaining a copy 00013 of this software and associated documentation files(the "Software"), to deal 00014 in the Software without restriction, including without limitation the rights 00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 00016 copies of the Software, and to permit persons to whom the Software is 00017 furnished to do so, subject to the following conditions : 00018 00019 The above copyright notice and this permission notice shall be included in all 00020 copies or substantial portions of the Software. 00021 00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00028 SOFTWARE. 00029 ******************************************************************************/ 00030 00031 /*[[[cog 00032 import cog 00033 cog.outl("#if 0") 00034 ]]]*/ 00035 /*[[[end]]]*/ 00036 #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. 00037 /*[[[cog 00038 import cog 00039 cog.outl("#endif") 00040 ]]]*/ 00041 /*[[[end]]]*/ 00042 00043 /*[[[cog 00044 import cog 00045 cog.outl("//***************************************************************************") 00046 cog.outl("// This file has been auto generated. Do not edit this file.") 00047 cog.outl("//***************************************************************************") 00048 ]]]*/ 00049 /*[[[end]]]*/ 00050 00051 //*************************************************************************** 00052 // To generate to header file, run this at the command line. 00053 // Note: You will need Python and COG installed. 00054 // 00055 // python -m cogapp -d -e -olargest.h -DNTypes=<n> largest_generator.h 00056 // Where <n> is the number of types to support. 00057 // 00058 // e.g. 00059 // To generate handlers for up to 16 types... 00060 // python -m cogapp -d -e -olargest.h -DNTypes=16 largest_generator.h 00061 // 00062 // See generate.bat 00063 //*************************************************************************** 00064 00065 #ifndef __ETL_LARGEST__ 00066 #define __ETL_LARGEST__ 00067 00068 ///\defgroup largest largest 00069 ///\ingroup utilities 00070 00071 #include "platform.h " 00072 #include "type_traits.h " 00073 #include "smallest.h " 00074 #include "static_assert.h" 00075 00076 namespace etl 00077 { 00078 /*[[[cog 00079 import cog 00080 cog.outl("//***************************************************************************") 00081 cog.outl("/// Template to determine the largest type and size.") 00082 cog.outl("/// Supports up to %s types." % NTypes) 00083 cog.outl("/// Defines 'value_type' which is the type of the largest parameter.") 00084 cog.outl("/// Defines 'size' which is the size of the largest parameter.") 00085 cog.outl("///\ingroup largest") 00086 cog.outl("//***************************************************************************") 00087 cog.out("template <typename T1, ") 00088 for n in range(2, int(NTypes)): 00089 cog.out("typename T%s = void, " % n) 00090 if n % 4 == 0: 00091 cog.outl("") 00092 cog.out(" ") 00093 cog.outl("typename T%s = void>" % int(NTypes)) 00094 cog.outl("struct largest_type") 00095 cog.outl("{") 00096 cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ") 00097 cog.out(" typedef typename largest_type<") 00098 for n in range(2, int(NTypes)): 00099 cog.out("T%s, " % n) 00100 if n % 16 == 0: 00101 cog.outl("") 00102 cog.out(" ") 00103 cog.outl("T%s>::type largest_other;" % int(NTypes)) 00104 cog.outl("") 00105 cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.") 00106 cog.outl(" // This is recursive.") 00107 cog.outl(" typedef typename etl::conditional<(sizeof(T1) > sizeof(largest_other)), // Boolean") 00108 cog.outl(" T1, // TrueType") 00109 cog.outl(" largest_other> // FalseType") 00110 cog.outl(" ::type type; // The largest type of the two.") 00111 cog.outl("") 00112 cog.outl(" // The size of the largest type.") 00113 cog.outl(" enum") 00114 cog.outl(" {") 00115 cog.outl(" size = sizeof(type)") 00116 cog.outl(" };") 00117 cog.outl("};") 00118 cog.outl("") 00119 cog.outl("//***************************************************************************") 00120 cog.outl("// Specialisation for one template parameter.") 00121 cog.outl("//***************************************************************************") 00122 cog.outl("template <typename T1>") 00123 cog.out("struct largest_type<T1, ") 00124 for n in range(2, int(NTypes)): 00125 cog.out("void, ") 00126 if n % 8 == 0: 00127 cog.outl("") 00128 cog.out(" ") 00129 cog.outl("void>") 00130 cog.outl("{") 00131 cog.outl(" typedef T1 type;") 00132 cog.outl("") 00133 cog.outl(" enum") 00134 cog.outl(" {") 00135 cog.outl(" size = sizeof(type)") 00136 cog.outl(" };") 00137 cog.outl("};") 00138 ]]]*/ 00139 /*[[[end]]]*/ 00140 00141 /*[[[cog 00142 import cog 00143 cog.outl("//***************************************************************************") 00144 cog.outl("/// Template to determine the largest alignment.") 00145 cog.outl("/// Supports up to %s types." % int(NTypes)) 00146 cog.outl("/// Defines <b>value</b> which is the largest alignment of all the parameters.") 00147 cog.outl("///\ingroup largest") 00148 cog.outl("//***************************************************************************") 00149 cog.out("template <typename T1, ") 00150 for n in range(2, int(NTypes)): 00151 cog.out("typename T%s = void, " % n) 00152 if n % 4 == 0: 00153 cog.outl("") 00154 cog.out(" ") 00155 cog.outl("typename T%s = void>" % int(NTypes)) 00156 cog.outl("struct largest_alignment") 00157 cog.outl("{") 00158 cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ") 00159 cog.out(" typedef typename largest_alignment<") 00160 for n in range(2, int(NTypes)): 00161 cog.out("T%s, " % n) 00162 if n % 16 == 0: 00163 cog.outl("") 00164 cog.out(" ") 00165 cog.outl("T%s>::type largest_other;" % int(NTypes)) 00166 cog.outl("") 00167 cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.") 00168 cog.outl(" // This is recursive.") 00169 cog.outl(" typedef typename etl::conditional<(etl::alignment_of<T1>::value > etl::alignment_of<largest_other>::value), // Boolean") 00170 cog.outl(" T1, // TrueType") 00171 cog.outl(" largest_other> // FalseType") 00172 cog.outl(" ::type type; // The largest type of the two.") 00173 cog.outl("") 00174 cog.outl(" // The largest alignment.") 00175 cog.outl(" enum") 00176 cog.outl(" {") 00177 cog.outl(" value = etl::alignment_of<type>::value") 00178 cog.outl(" };") 00179 cog.outl("};") 00180 cog.outl("") 00181 cog.outl("//***************************************************************************") 00182 cog.outl("// Specialisation for one template parameter.") 00183 cog.outl("//***************************************************************************") 00184 cog.outl("template <typename T1>") 00185 cog.out("struct largest_alignment<T1, ") 00186 for n in range(2, int(NTypes)): 00187 cog.out("void, ") 00188 if n % 8 == 0: 00189 cog.outl("") 00190 cog.out(" ") 00191 cog.outl("void>") 00192 cog.outl("{") 00193 cog.outl(" typedef T1 type;") 00194 cog.outl("") 00195 cog.outl(" enum") 00196 cog.outl(" {") 00197 cog.outl(" value = etl::alignment_of<type>::value") 00198 cog.outl(" };") 00199 cog.outl("};") 00200 ]]]*/ 00201 /*[[[end]]]*/ 00202 00203 //*************************************************************************** 00204 /// Defines a type that is as larger or larger than the specified type. 00205 /// Will return the specified type is there is not a larger type. 00206 ///\ingroup largest 00207 //*************************************************************************** 00208 template <typename T> 00209 struct larger_int_type 00210 { 00211 STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type"); 00212 00213 typedef typename etl::smallest_int_for_bits<etl::integral_limits<typename etl::make_signed<T>::type>::bits + 1>::type type; 00214 }; 00215 00216 //*************************************************************************** 00217 /// Defines a type that is as larger or larger than the specified type. 00218 /// Will return the specified type is there is not a larger type. 00219 ///\ingroup largest 00220 //*************************************************************************** 00221 template <typename T> 00222 struct larger_uint_type 00223 { 00224 STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type"); 00225 00226 typedef typename etl::smallest_uint_for_bits<etl::integral_limits<typename etl::make_unsigned<T>::type>::bits + 1>::type type; 00227 }; 00228 00229 //*************************************************************************** 00230 /// Defines a type that is as larger or larger than the specified type. 00231 /// Will return the specified type is there is not a larger type. 00232 /// The returned type will be of the same sign. 00233 ///\ingroup largest 00234 //*************************************************************************** 00235 template <typename T, bool IS_SIGNED = etl::is_signed<T>::value> 00236 struct larger_type; 00237 00238 template <typename T> 00239 struct larger_type<T, false> 00240 { 00241 STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type"); 00242 00243 typedef typename etl::smallest_uint_for_bits<etl::integral_limits<T>::bits + 1>::type type; 00244 }; 00245 00246 template <typename T> 00247 struct larger_type<T, true> 00248 { 00249 STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type"); 00250 00251 typedef typename etl::smallest_int_for_bits<etl::integral_limits<T>::bits + 1>::type type; 00252 }; 00253 00254 /*[[[cog 00255 import cog 00256 cog.outl("//***************************************************************************") 00257 cog.outl("/// Template to determine the largest type, size and alignment.") 00258 cog.outl("/// Supports up to %s types." % NTypes) 00259 cog.outl("/// Defines <b>value</b> which is the largest type, size and alignment of all the parameters.") 00260 cog.outl("///\ingroup largest") 00261 cog.outl("//***************************************************************************") 00262 cog.out("template <typename T1, ") 00263 for n in range(2, int(NTypes)): 00264 cog.out("typename T%s = void, " % n) 00265 if n % 4 == 0: 00266 cog.outl("") 00267 cog.out(" ") 00268 cog.outl("typename T%s = void>" % NTypes) 00269 cog.outl("struct largest") 00270 cog.outl("{") 00271 cog.out(" typedef typename etl::largest_type<") 00272 for n in range(1, int(NTypes)): 00273 cog.out("T%s, " % n) 00274 if n % 16 == 0: 00275 cog.outl("") 00276 cog.out(" ") 00277 cog.outl("T%s>::type type;" % NTypes) 00278 cog.outl("") 00279 cog.outl(" enum") 00280 cog.outl(" {") 00281 cog.out(" size = etl::largest_type<") 00282 for n in range(1, int(NTypes)): 00283 cog.out("T%s, " % n) 00284 if n % 16 == 0: 00285 cog.outl("") 00286 cog.out(" ") 00287 cog.outl("T%s>::size," % NTypes) 00288 cog.out(" alignment = etl::largest_alignment<") 00289 for n in range(1, int(NTypes)): 00290 cog.out("T%s, " % n) 00291 if n % 16 == 0: 00292 cog.outl("") 00293 cog.out(" ") 00294 cog.outl("T%s>::value" % NTypes) 00295 cog.outl(" };") 00296 cog.outl("};") 00297 ]]]*/ 00298 /*[[[end]]]*/ 00299 } 00300 00301 #endif 00302
Generated on Tue Jul 12 2022 14:05:42 by
