Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1732 Squash me!
Browse files Browse the repository at this point in the history
Signed-off-by: Marika Lehmann <[email protected]>
  • Loading branch information
FerdinandSpitzschnueffler committed Nov 22, 2022
1 parent 3eda51e commit 5e3ff7a
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,19 @@ inline void swap(storable_function<Capacity, T>& f, storable_function<Capacity,
f.swap(g);
}

template <typename T>
void* allocate(byte_t* startAddress)
{
uint64_t alignedPosition = cxx::align(reinterpret_cast<uint64_t>(startAddress), alignof(T));
return reinterpret_cast<void*>(alignedPosition);
}

template <uint64_t Capacity, typename ReturnType, typename... Args>
template <typename Functor, typename>
inline void storable_function<Capacity, signature<ReturnType, Args...>>::storeFunctor(const Functor& functor) noexcept
{
using StoredType = typename std::remove_reference<Functor>::type;
uint64_t alignedPosition = cxx::align(reinterpret_cast<uint64_t>(&m_storage), alignof(StoredType));
alignedPosition -= reinterpret_cast<uint64_t>(&m_storage);
m_callable = static_cast<void*>(&m_storage + alignedPosition);
m_callable = allocate<StoredType>(m_storage);

// erase the functor type and store as reference to the call in storage
new (m_callable) StoredType(functor);
Expand All @@ -190,9 +195,7 @@ template <typename CallableType>
inline void storable_function<Capacity, signature<ReturnType, Args...>>::copy(const storable_function& src,
storable_function& dest) noexcept
{
uint64_t alignedPosition = cxx::align(reinterpret_cast<uint64_t>(&dest.m_storage), alignof(CallableType));
alignedPosition -= reinterpret_cast<uint64_t>(&dest.m_storage);
dest.m_callable = static_cast<void*>(&dest.m_storage + alignedPosition);
dest.m_callable = allocate<CallableType>(dest.m_storage);

// AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type
const auto obj = static_cast<CallableType*>(src.m_callable);
Expand All @@ -210,9 +213,7 @@ inline void storable_function<Capacity, signature<ReturnType, Args...>>::move(st
storable_function& dest) noexcept
{
// m_callable = static_cast<void*>(align(reinterpret_cast<uint64_t>(m_storage), alignof(CallableType)));
uint64_t alignedPosition = cxx::align(reinterpret_cast<uint64_t>(&dest.m_storage), alignof(CallableType));
alignedPosition -= reinterpret_cast<uint64_t>(&dest.m_storage);
dest.m_callable = static_cast<void*>(&dest.m_storage + alignedPosition);
dest.m_callable = allocate<CallableType>(dest.m_storage);

// AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type
const auto obj = static_cast<CallableType*>(src.m_callable);
Expand Down

0 comments on commit 5e3ff7a

Please sign in to comment.