iceoryx_posh/popo/sample.hpp🔗
Namespaces🔗
Name |
---|
iox |
iox::popo |
iox::popo::internal |
Classes🔗
Name | |
---|---|
class | iox::popo::PublisherInterface The PublisherInterface class defines the publisher interface used by the Sample class to make it generic. This allows any publisher specialization to be stored as a reference by the Sample class. It is also needed to avoid circular dependencies between Sample and Publisher. |
struct | iox::popo::internal::SamplePrivateData helper struct for sample |
struct | iox::popo::internal::SamplePrivateData< const T, H > specialization of helper struct for sample for const T |
class | iox::popo::Sample The Sample class is a mutable abstraction over types which are written to loaned shared memory. These samples are publishable to the iceoryx system. |
Source code🔗
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_POSH_POPO_SAMPLE_HPP
#define IOX_POSH_POPO_SAMPLE_HPP
#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iceoryx_utils/cxx/type_traits.hpp"
#include "iceoryx_utils/cxx/unique_ptr.hpp"
namespace iox
{
namespace popo
{
template <typename T, typename H>
class PublisherInterface;
namespace internal
{
template <typename T, typename H>
struct SamplePrivateData
{
SamplePrivateData(cxx::unique_ptr<T>&& sampleUniquePtr, PublisherInterface<T, H>& publisher) noexcept;
SamplePrivateData(SamplePrivateData&& rhs) noexcept = default;
SamplePrivateData& operator=(SamplePrivateData&& rhs) noexcept = default;
SamplePrivateData(const SamplePrivateData&) = delete;
SamplePrivateData& operator=(const SamplePrivateData&) = delete;
cxx::unique_ptr<T> sampleUniquePtr;
std::reference_wrapper<PublisherInterface<T, H>> publisherRef;
};
template <typename T, typename H>
struct SamplePrivateData<const T, H>
{
SamplePrivateData(cxx::unique_ptr<const T>&& sampleUniquePtr) noexcept;
SamplePrivateData(SamplePrivateData&& rhs) noexcept = default;
SamplePrivateData& operator=(SamplePrivateData&& rhs) noexcept = default;
SamplePrivateData(const SamplePrivateData&) = delete;
SamplePrivateData& operator=(const SamplePrivateData&) = delete;
cxx::unique_ptr<const T> sampleUniquePtr;
};
} // namespace internal
template <typename T, typename H = cxx::add_const_conditionally_t<mepoo::NoUserHeader, T>>
class Sample
{
static_assert(std::is_const<T>::value == std::is_const<H>::value,
"The type `T` and the user-header `H` must be equal in their const qualifier to ensure the same "
"access restrictions for the user-header as for the sample data!");
template <typename S, typename TT>
using ForPublisherOnly = std::enable_if_t<std::is_same<S, TT>::value && !std::is_const<TT>::value, S>;
template <typename S, typename TT>
using ForSubscriberOnly = std::enable_if_t<std::is_same<S, TT>::value && std::is_const<TT>::value, S>;
template <typename R, typename HH>
using HasUserHeader =
std::enable_if_t<std::is_same<R, HH>::value && !std::is_same<R, mepoo::NoUserHeader>::value, R>;
public:
template <typename S = T, typename = ForPublisherOnly<S, T>>
Sample(cxx::unique_ptr<T>&& sampleUniquePtr, PublisherInterface<T, H>& publisher) noexcept;
template <typename S = T, typename = ForSubscriberOnly<S, T>>
Sample(cxx::unique_ptr<T>&& sampleUniquePtr) noexcept;
~Sample() noexcept = default;
Sample<T, H>& operator=(Sample<T, H>&& rhs) noexcept = default;
Sample(Sample<T, H>&& rhs) noexcept = default;
Sample(const Sample<T, H>&) = delete;
Sample<T, H>& operator=(const Sample<T, H>&) = delete;
T* operator->() noexcept;
const T* operator->() const noexcept;
T& operator*() noexcept;
const T& operator*() const noexcept;
operator bool() const noexcept;
T* get() noexcept;
const T* get() const noexcept;
using ConditionalConstChunkHeader_t = cxx::add_const_conditionally_t<mepoo::ChunkHeader, T>;
ConditionalConstChunkHeader_t* getChunkHeader() noexcept;
const mepoo::ChunkHeader* getChunkHeader() const noexcept;
template <typename R = H, typename = HasUserHeader<R, H>>
R& getUserHeader() noexcept;
template <typename R = H, typename = HasUserHeader<R, H>>
const R& getUserHeader() const noexcept;
template <typename S = T, typename = ForPublisherOnly<S, T>>
void publish() noexcept;
private:
template <typename, typename, typename>
friend class PublisherImpl;
T* release() noexcept;
private:
internal::SamplePrivateData<T, H> m_members;
};
} // namespace popo
} // namespace iox
#include "iceoryx_posh/internal/popo/sample.inl"
#endif // IOX_POSH_POPO_SAMPLE_HPP
Updated on 31 May 2022 at 15:29:16 CEST