Skip to content

Commit

Permalink
iox-#1036 Remove creation pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 2, 2023
1 parent daa1737 commit 503a0da
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 292 deletions.
2 changes: 1 addition & 1 deletion doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@
#include "iceoryx_hoofs/design_pattern/creation.hpp"

// after
#include "iceoryx_dust/design/creation.hpp"
// fully removed
```

```cpp
Expand Down
150 changes: 0 additions & 150 deletions iceoryx_dust/include/iceoryx_dust/design/creation.hpp

This file was deleted.

86 changes: 0 additions & 86 deletions iceoryx_dust/include/iceoryx_dust/internal/design/creation.inl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#ifndef IOX_POSH_MEPOO_SHARED_POINTER_HPP
#define IOX_POSH_MEPOO_SHARED_POINTER_HPP

#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iox/expected.hpp"

namespace iox
{
Expand All @@ -30,22 +30,22 @@ enum class SharedPointerError
SharedChunkIsEmpty
};

/// @brief DesignPattern::Creation offers us a create method which forwards the arguments to
/// the constructor. Use this class like in the code example below
/// @brief A typed shared pointer for the untyped 'SharedChunk'.
/// @code
/// // expected
/// auto sharedPointer = SharedPointer<int>::Create(mySharedChunk, 123);
/// auto sharedPointer = SharedPointer<int>::create(mySharedChunk, 123);
/// if ( sharedPointer.has_error() ) {
/// // ...
/// } else {
/// // ...
/// }
/// @endcode
template <typename T>
class SharedPointer : public DesignPattern::Creation<SharedPointer<T>, SharedPointerError>
class SharedPointer
{
public:
using CreationPattern_t = DesignPattern::Creation<SharedPointer<T>, SharedPointerError>;
template <typename... Targs>
static expected<SharedPointer<T>, SharedPointerError> create(const SharedChunk& chunk, Targs&&... args) noexcept;

SharedPointer() = default;
SharedPointer(const SharedPointer&) = default;
Expand All @@ -66,13 +66,15 @@ class SharedPointer : public DesignPattern::Creation<SharedPointer<T>, SharedPoi

explicit operator bool() const noexcept;

friend class DesignPattern::Creation<SharedPointer<T>, SharedPointerError>;

private:
template <typename... Targs>
SharedPointer(const SharedChunk& chunk, Targs&&... args) noexcept;

SharedPointer(const SharedChunk& chunk) noexcept;

void deleteManagedObjectIfNecessary() noexcept;

private:
SharedChunk m_chunk;
};

Expand Down
28 changes: 14 additions & 14 deletions iceoryx_posh/include/iceoryx_posh/internal/mepoo/shared_pointer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ namespace mepoo
{
template <typename T>
template <typename... Targs>
inline SharedPointer<T>::SharedPointer(const SharedChunk& chunk, Targs&&... args) noexcept
: m_chunk(chunk)
inline expected<SharedPointer<T>, SharedPointerError> SharedPointer<T>::create(const SharedChunk& chunk,
Targs&&... args) noexcept
{
if (chunk.m_chunkManagement != nullptr)
{
new (chunk.m_chunkManagement->m_chunkHeader->userPayload()) T(std::forward<Targs>(args)...);
this->m_isInitialized = true;
}
else
if (chunk.m_chunkManagement == nullptr)
{
this->m_isInitialized = false;
this->m_errorValue = SharedPointerError::SharedChunkIsEmpty;
return err(SharedPointerError::SharedChunkIsEmpty);
}

new (chunk.m_chunkManagement->m_chunkHeader->userPayload()) T(std::forward<Targs>(args)...);

return ok(SharedPointer(chunk));
}

template <typename T>
inline SharedPointer<T>::SharedPointer(const SharedChunk& chunk) noexcept
: m_chunk(chunk)
{
}

template <typename T>
Expand All @@ -50,8 +54,6 @@ inline SharedPointer<T>& SharedPointer<T>::operator=(const SharedPointer& rhs) n
{
deleteManagedObjectIfNecessary();

CreationPattern_t::operator=(rhs);

m_chunk = rhs.m_chunk;
}
return *this;
Expand All @@ -64,8 +66,6 @@ inline SharedPointer<T>& SharedPointer<T>::operator=(SharedPointer&& rhs) noexce
{
deleteManagedObjectIfNecessary();

CreationPattern_t::operator=(std::move(rhs));

m_chunk = std::move(rhs.m_chunk);
}
return *this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class TypedMemPool

template <typename... Targs>
expected<SharedPointer<T>, TypedMemPoolError> createObject(Targs&&... args) noexcept;
template <typename ErrorType, typename... Targs>
expected<SharedPointer<T>, variant<TypedMemPoolError, ErrorType>>
createObjectWithCreationPattern(Targs&&... args) noexcept;
uint32_t getChunkCount() const noexcept;
uint32_t getUsedChunks() const noexcept;

Expand Down
Loading

0 comments on commit 503a0da

Please sign in to comment.