13#ifndef IOX2_BB_LAYOUT_HPP
14#define IOX2_BB_LAYOUT_HPP
36 static auto from() -> std::enable_if_t<!std::is_same<T, void>::value,
Layout>;
40 static auto from() -> std::enable_if_t<std::is_same<T, void>::value,
Layout>;
49 auto size() const -> uint64_t;
55 static auto is_power_of_two(uint64_t value) ->
bool;
57 static auto round_up_to(uint64_t value, uint64_t multiple) -> uint64_t;
68 return Layout {
sizeof(T),
alignof(T) };
78 if (!is_power_of_two(align)) {
82 return Layout(round_up_to(
size, align), align);
93inline auto Layout::is_power_of_two(
const uint64_t value) ->
bool {
94 return (value != 0) && ((value & (value - 1)) == 0);
97inline auto Layout::round_up_to(
const uint64_t value,
const uint64_t multiple) -> uint64_t {
98 return (value % multiple == 0) ? value : multiple * ((value / multiple) + 1);
102inline Layout::Layout(
const uint64_t
size,
const uint64_t align)
104 , m_align { align } {
static auto from() -> std::enable_if_t<!std::is_same< T, void >::value, Layout >
static auto from() -> std::enable_if_t< std::is_same< T, void >::value, Layout >
Creates a new [Layout] with size == 0 and alignment == 1.
auto alignment() const -> uint64_t
Returns the stored alignment.
auto size() const -> uint64_t
Returns the stored size.
static auto create(uint64_t size, uint64_t align) -> iox2::bb::Expected< Layout, LayoutCreationError >
LayoutCreationError
Defines all errors that can occur while creating a new [Layout].
@ InvalidAlignment
The provided alignment was not a power of two.
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected