17 #ifndef IOX_HOOFS_CXX_HELPLETS_HPP
18 #define IOX_HOOFS_CXX_HELPLETS_HPP
20 #include "iceoryx_hoofs/cxx/string.hpp"
21 #include "iceoryx_hoofs/cxx/type_traits.hpp"
28 #include <type_traits>
30 #include "iceoryx_hoofs/platform/platform_correction.hpp"
31 #include "iceoryx_hoofs/platform/platform_settings.hpp"
37 template <u
int64_t Capacity>
39 struct TruncateToCapacity_t;
44 template <
bool GreaterU
int8,
bool GreaterU
int16,
bool GreaterU
int32>
45 struct BestFittingTypeImpl
47 using Type_t = uint64_t;
51 struct BestFittingTypeImpl<false, false, false>
53 using Type_t = uint8_t;
57 struct BestFittingTypeImpl<true, false, false>
59 using Type_t = uint16_t;
63 struct BestFittingTypeImpl<true, true, false>
65 using Type_t = uint32_t;
68 constexpr
char ASCII_A =
'a';
69 constexpr
char ASCII_Z =
'z';
70 constexpr
char ASCII_CAPITAL_A =
'A';
71 constexpr
char ASCII_CAPITAL_Z =
'Z';
72 constexpr
char ASCII_0 =
'0';
73 constexpr
char ASCII_9 =
'9';
74 constexpr
char ASCII_MINUS =
'-';
75 constexpr
char ASCII_DOT =
'.';
76 constexpr
char ASCII_COLON =
':';
77 constexpr
char ASCII_UNDERSCORE =
'_';
80 template <typename T, typename = typename std::enable_if<std::is_pointer<T>::value,
void>::type>
87 Expects(t !=
nullptr);
90 constexpr
operator T()
const noexcept
99 template <
typename T, T Minimum>
106 Expects(t >= Minimum);
109 constexpr
operator T()
const noexcept
118 template <
typename T, T Minimum, T Maximum>
125 Expects(t >= Minimum && t <= Maximum);
128 constexpr
operator T()
const noexcept
137 template <
typename T>
138 T align(
const T value,
const T alignment) noexcept
140 T remainder = value % alignment;
141 return value + ((remainder == 0u) ? 0u : alignment - remainder);
148 void* alignedAlloc(
const uint64_t alignment,
const uint64_t size) noexcept;
152 void alignedFree(
void*
const memory) noexcept;
155 template <
size_t s = 0>
156 constexpr
size_t maxAlignment() noexcept
162 template <
typename T,
typename... Args>
163 constexpr
size_t maxAlignment() noexcept
165 return alignof(T) > maxAlignment<Args...>() ?
alignof(T) : maxAlignment<Args...>();
169 template <
size_t s = 0>
170 constexpr
size_t maxSize() noexcept
176 template <
typename T,
typename... Args>
177 constexpr
size_t maxSize() noexcept
179 return sizeof(T) > maxSize<Args...>() ?
sizeof(T) : maxSize<Args...>();
183 template <
typename T,
typename Enumeration>
184 const char* convertEnumToString(T port,
const Enumeration source) noexcept
186 return port[
static_cast<size_t>(source)];
190 template <
typename enum_type>
191 auto enumTypeAsUnderlyingType(enum_type
const value) noexcept ->
typename std::underlying_type<enum_type>::type
193 return static_cast<typename std::underlying_type<enum_type>::type
>(value);
201 template <
typename Container,
typename Functor>
202 void forEach(Container& c,
const Functor& f) noexcept
204 for (
auto& element : c)
214 template <u
int64_t SizeValue>
215 static constexpr uint64_t strlen2(
char const (&)[SizeValue]) noexcept
217 return SizeValue - 1;
221 template <u
int64_t Value>
225 #pragma GCC diagnostic push
226 #pragma GCC diagnostic ignored "-Wtype-limits"
227 using Type_t =
typename internal::BestFittingTypeImpl<(Value > std::numeric_limits<uint8_t>::max()),
228 (Value > std::numeric_limits<uint16_t>::max()),
229 (Value > std::numeric_limits<uint32_t>::max())>::
Type_t;
230 #pragma GCC diagnostic pop
233 template <u
int64_t Value>
238 constexpr
bool isCompiledOn32BitSystem() noexcept
240 return INTPTR_MAX == INT32_MAX;
245 template <
typename T>
246 constexpr
bool isPowerOfTwo(
const T n) noexcept
248 static_assert(std::is_unsigned<T>::value && !std::is_same<T, bool>::value,
"Only unsigned integer are allowed!");
249 return n && ((n & (n - 1U)) == 0U);
254 template <u
int64_t StringCapacity>
255 bool isValidFileName(
const string<StringCapacity>& name) noexcept;
259 template <u
int64_t StringCapacity>
260 bool isValidFilePath(
const string<StringCapacity>& name) noexcept;
302 template <
typename F,
typename T>
303 constexpr T from(
const F value) noexcept;
315 template <
typename T,
typename F>
316 constexpr T into(
const F value) noexcept;
344 #define IOX_BUILDER_PARAMETER(type, name, defaultValue) \
346 decltype(auto) name(type const& value)&& \
349 return std::move(*this); \
352 decltype(auto) name(type&& value)&& \
354 m_##name = std::move(value); \
355 return std::move(*this); \
359 type m_##name{defaultValue};
364 #include "iceoryx_hoofs/internal/cxx/helplets.inl"
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29
get the best fitting unsigned integer type for a given value at compile time
Definition: helplets.hpp:223
typename internal::BestFittingTypeImpl<(Value > std::numeric_limits< uint8_t >::max()),(Value > std::numeric_limits< uint16_t >::max()),(Value > std::numeric_limits< uint32_t >::max())>::Type_t Type_t
ignore the warnings because we need the comparisons to find the best fitting type
Definition: helplets.hpp:229
Definition: helplets.hpp:101
Definition: helplets.hpp:82
Definition: helplets.hpp:120