Components/Storage/src/include/Storage/Types.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Types.h
8  *
9  ****/
10 #pragma once
11 
12 #include <cstdint>
13 #include <limits>
14 #include <algorithm>
15 
16 #ifdef ENABLE_STORAGE_SIZE64
17 using storage_size_t = uint64_t;
18 #else
19 using storage_size_t = uint32_t;
20 #endif
21 
22 namespace Storage
23 {
27 inline bool isSize64(uint64_t value)
28 {
29  using Lim = std::numeric_limits<uint32_t>;
30  return value < Lim::min() || value > Lim::max();
31 }
32 
36 inline bool isSize64(int64_t value)
37 {
38  using Lim = std::numeric_limits<int32_t>;
39  return value < Lim::min() || value > Lim::max();
40 }
41 
49 template <typename T> constexpr typename std::enable_if<(sizeof(T) <= 4), uint8_t>::type getSizeBits(T value)
50 {
51  return __builtin_ffs(value) - 1;
52 }
53 
54 template <typename T> constexpr typename std::enable_if<(sizeof(T) > 4), uint8_t>::type getSizeBits(T value)
55 {
56  return __builtin_ffsll(value) - 1;
57 }
63 template <typename T> constexpr bool isLog2(T value)
64 {
65  return value == (T(1U) << getSizeBits(value));
66 }
67 
68 } // namespace Storage
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19
Definition: FileDevice.h:26
constexpr std::enable_if<(sizeof(T)<=4), uint8_t >::type getSizeBits(T value)
Definition: Components/Storage/src/include/Storage/Types.h:49
constexpr bool isLog2(T value)
Determine if a value is an exact power of 2.
Definition: Components/Storage/src/include/Storage/Types.h:63
bool isSize64(uint64_t value)
Determine if a value requires 64-bits to store.
Definition: Components/Storage/src/include/Storage/Types.h:27