2323#include < utility>
2424#include < variant>
2525
26+ #include " iox2/iceoryx2.hpp"
27+
2628namespace score ::mw::com::impl
2729{
2830
@@ -105,7 +107,7 @@ class SampleAllocateePtr
105107 // coverity[autosar_cpp14_a15_5_3_violation : FALSE]
106108 pointer operator ->() const noexcept ;
107109
108- private:
110+
109111 template <typename T>
110112 // Suppress "AUTOSAR C++14 A0-1-3" rule finding. This rule states: "Every function defined in an anonymous
111113 // namespace, or static function with internal linkage, or private member function shall be used.".
@@ -114,7 +116,17 @@ class SampleAllocateePtr
114116 explicit SampleAllocateePtr (T ptr) : internal_{std::move (ptr)}
115117 {
116118 }
119+ template <typename T>
120+ explicit SampleAllocateePtr (T ptr, std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void >> iox2_sample) :
121+ internal_{std::move (ptr)}, iox2_sample_{std::move (iox2_sample)}
122+ {
123+ }
117124
125+ std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void >> GetIox2Sample () const noexcept
126+ {
127+ return iox2_sample_;
128+ }
129+ private:
118130 // Suppress "AUTOSAR C++14 A11-3-1", The rule states: "Friend declarations shall not be used".
119131 // Friend class required to access private constructor as we do not have everything we need public.
120132 // This is because we want to shield the end user from implementation details and avoid wrong usage.
@@ -133,7 +145,8 @@ class SampleAllocateePtr
133145 friend class SampleAllocateePtrMutableView ;
134146
135147 // We don't use the pimpl idiom because it would require dynamic memory allocation (that we want to avoid)
136- std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>> internal_;
148+ std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType*> internal_;
149+ std::shared_ptr<iox2::SampleMut<iox2::ServiceType::Ipc, SampleType, void >> iox2_sample_;
137150};
138151
139152template <typename SampleType>
@@ -175,8 +188,13 @@ void SampleAllocateePtr<SampleType>::reset() noexcept
175188 internal_ptr.reset (nullptr );
176189 },
177190 // coverity[autosar_cpp14_a7_1_7_violation]
178- [](const score::cpp::blank&) noexcept -> void {});
191+ [](const score::cpp::blank&) noexcept -> void {},
192+ [](SampleType* internal_ptr) noexcept -> void {
193+ internal_ptr = nullptr ;
194+ }
195+ );
179196 std::visit (visitor, internal_);
197+ // iox2_sample_.reset();
180198}
181199
182200template <typename SampleType>
@@ -185,6 +203,7 @@ void SampleAllocateePtr<SampleType>::Swap(SampleAllocateePtr<SampleType>& other)
185203 // Search for custom swap functions via ADL, and use std::swap if none are found.
186204 using std::swap;
187205 swap (internal_, other.internal_ );
206+ swap (iox2_sample_, other.iox2_sample_ );
188207}
189208
190209template <typename SampleType>
@@ -213,7 +232,12 @@ auto SampleAllocateePtr<SampleType>::Get() const noexcept -> pointer
213232 // coverity[autosar_cpp14_a7_1_7_violation]
214233 [](const score::cpp::blank&) noexcept -> ReturnType {
215234 return nullptr ;
216- });
235+ },
236+ [](SampleType* internal_ptr) noexcept -> ReturnType {
237+ return internal_ptr;
238+ }
239+
240+ );
217241
218242 return std::visit (visitor, internal_);
219243}
@@ -241,7 +265,11 @@ SampleAllocateePtr<SampleType>::operator bool() const noexcept
241265 // coverity[autosar_cpp14_a7_1_7_violation]
242266 [](const score::cpp::blank&) noexcept -> bool {
243267 return false ;
244- });
268+ },
269+ [](SampleType* internal_ptr) noexcept -> bool {
270+ return internal_ptr != nullptr ;
271+ }
272+ );
245273
246274 return std::visit (visitor, internal_);
247275}
@@ -273,7 +301,11 @@ typename std::add_lvalue_reference<SampleType>::type SampleAllocateePtr<SampleTy
273301 // coverity[autosar_cpp14_a7_1_7_violation]
274302 [](const score::cpp::blank&) noexcept -> ReturnType {
275303 std::terminate ();
276- });
304+ },
305+ [](SampleType* internal_ptr) noexcept -> ReturnType {
306+ return *internal_ptr;
307+ }
308+ );
277309
278310 return std::visit (visitor, internal_);
279311}
@@ -304,7 +336,11 @@ auto SampleAllocateePtr<SampleType>::operator->() const noexcept -> pointer
304336 // coverity[autosar_cpp14_a7_1_7_violation]
305337 [](const score::cpp::blank&) noexcept -> ReturnType {
306338 std::terminate ();
307- });
339+ },
340+ [](SampleType* internal_ptr) noexcept -> ReturnType {
341+ return internal_ptr;
342+ }
343+ );
308344
309345 return std::visit (visitor, internal_);
310346}
@@ -353,7 +389,7 @@ class SampleAllocateePtrView
353389 return std::get_if<T>(&ptr_.internal_ );
354390 }
355391
356- const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
392+ const std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType* >&
357393 GetUnderlyingVariant () const noexcept
358394 {
359395 return ptr_.internal_ ;
@@ -370,7 +406,7 @@ class SampleAllocateePtrMutableView
370406 public:
371407 explicit SampleAllocateePtrMutableView (SampleAllocateePtr<SampleType>& ptr) : ptr_{ptr} {}
372408
373- std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>>&
409+ std::variant<score::cpp::blank, lola::SampleAllocateePtr<SampleType>, std::unique_ptr<SampleType>, SampleType* >&
374410 GetUnderlyingVariant () noexcept
375411 {
376412 // Suppress "AUTOSAR C++14 A9-3-1", The rule states: "Member functions shall not return non-const “raw” pointers
0 commit comments