Skip to content

iceoryx_utils/internal/relocatable_pointer/relative_pointer_data.hpp🔗

Namespaces🔗

Name
iox
building block to easily create free function for logging in a library context
iox::rp

Classes🔗

Name
class iox::rp::RelativePointerData
This are the data for a relative pointer. To be able so safely be used in the shared memory and prevent torn writes/reads, the class must not be larger than 64 bits and trivially copy-able.

Source code🔗

// 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_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP
#define IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP

#include "iceoryx_utils/cxx/helplets.hpp"

#include <cstdint>

namespace iox
{
namespace rp
{
class RelativePointerData
{
  public:
    using id_t = uint16_t;
    using offset_t = uint64_t;

    constexpr RelativePointerData() noexcept = default;

    constexpr RelativePointerData(id_t id, offset_t offset) noexcept;

    id_t id() const noexcept;

    offset_t offset() const noexcept;

    void reset() noexcept;

    bool isLogicalNullptr() const noexcept;

    static constexpr id_t ID_RANGE{std::numeric_limits<id_t>::max()};
    static constexpr id_t NULL_POINTER_ID{ID_RANGE};
    static constexpr id_t MAX_VALID_ID{ID_RANGE - 1U};
    static constexpr offset_t OFFSET_RANGE{(1ULL << 48U) - 1U};
    static constexpr offset_t NULL_POINTER_OFFSET{OFFSET_RANGE};
    static constexpr offset_t MAX_VALID_OFFSET{OFFSET_RANGE - 1U};
    static constexpr offset_t LOGICAL_NULLPTR{NULL_POINTER_OFFSET << 16 | NULL_POINTER_ID};

  private:
    uint64_t m_idAndOffset{LOGICAL_NULLPTR};
};

} // namespace rp
} // namespace iox

#include "iceoryx_utils/internal/relocatable_pointer/relative_pointer_data.inl"

#endif // IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP

Updated on 17 June 2021 at 11:15:26 CEST