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"
30#include "iceoryx_hoofs/platform/platform_correction.hpp"
31#include "iceoryx_hoofs/platform/platform_settings.hpp"
37template <u
int64_t Capacity>
39struct TruncateToCapacity_t;
44template <
bool GreaterU
int8,
bool GreaterU
int16,
bool GreaterU
int32>
45struct BestFittingTypeImpl
47 using Type_t = uint64_t;
51struct BestFittingTypeImpl<false, false, false>
53 using Type_t = uint8_t;
57struct BestFittingTypeImpl<true, false, false>
59 using Type_t = uint16_t;
63struct BestFittingTypeImpl<true, true, false>
65 using Type_t = uint32_t;
68constexpr char ASCII_A =
'a';
69constexpr char ASCII_Z =
'z';
70constexpr char ASCII_CAPITAL_A =
'A';
71constexpr char ASCII_CAPITAL_Z =
'Z';
72constexpr char ASCII_0 =
'0';
73constexpr char ASCII_9 =
'9';
74constexpr char ASCII_MINUS =
'-';
75constexpr char ASCII_DOT =
'.';
76constexpr char ASCII_COLON =
':';
77constexpr char ASCII_UNDERSCORE =
'_';
80template <typename T, typename = typename std::enable_if<std::is_pointer<T>::value,
void>::type>
87 Expects(t !=
nullptr);
90 constexpr operator T()
const noexcept
99template <
typename T, T Minimum>
106 Expects(t >= Minimum);
109 constexpr operator T()
const noexcept
118template <
typename T, T Minimum, T Maximum>
125 Expects(t >= Minimum && t <= Maximum);
128 constexpr operator T()
const noexcept
138T align(
const T value,
const T alignment)
noexcept
140 T remainder = value % alignment;
141 return value + ((remainder == 0u) ? 0u : alignment - remainder);
148void* alignedAlloc(
const uint64_t alignment,
const uint64_t size)
noexcept;
152void alignedFree(
void*
const memory)
noexcept;
155template <
size_t s = 0>
156constexpr size_t maxAlignment() noexcept
162template <
typename T,
typename... Args>
163constexpr size_t maxAlignment() noexcept
165 return alignof(T) > maxAlignment<Args...>() ?
alignof(T) : maxAlignment<Args...>();
169template <
size_t s = 0>
170constexpr size_t maxSize() noexcept
176template <
typename T,
typename... Args>
177constexpr size_t maxSize() noexcept
179 return sizeof(T) > maxSize<Args...>() ?
sizeof(T) : maxSize<Args...>();
183template <
typename T,
typename Enumeration>
184const char* convertEnumToString(T port,
const Enumeration source)
noexcept
186 return port[
static_cast<size_t>(source)];
190template <
typename enum_type>
191auto 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);
201template <
typename Container,
typename Functor>
202void forEach(Container& c,
const Functor& f)
noexcept
204 for (
auto& element : c)
214template <u
int64_t SizeValue>
215static constexpr uint64_t strlen2(
char const (&)[SizeValue])
noexcept
217 return SizeValue - 1;
221template <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
233template <u
int64_t Value>
238constexpr bool isCompiledOn32BitSystem() noexcept
240 return INTPTR_MAX == INT32_MAX;
246constexpr 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);
254template <u
int64_t StringCapacity>
255bool isValidFileName(
const string<StringCapacity>& name)
noexcept;
259template <u
int64_t StringCapacity>
260bool isValidFilePath(
const string<StringCapacity>& name)
noexcept;
302template <
typename F,
typename T>
303constexpr T from(
const F value)
noexcept;
315template <
typename T,
typename F>
316constexpr 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