Skip to content

iceoryx_utils/internal/relocatable_pointer/base_relative_pointer.hpp🔗

Namespaces🔗

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

Classes🔗

Name
class iox::rp::BaseRelativePointer
pointer class to use when pointer and pointee are located in different shared memory segments We can have the following scenario: Pointer p is stored in segment S1 and points to object X of type T in segment S2.

Source code🔗

// Copyright (c) 2019 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_UTILS_RELOCATABLE_POINTER_BASE_RELATIVE_POINTER_HPP
#define IOX_UTILS_RELOCATABLE_POINTER_BASE_RELATIVE_POINTER_HPP

#include "pointer_repository.hpp"

#include <cstdint>
#include <limits>

namespace iox
{
namespace rp
{
class BaseRelativePointer
{
  public:
    using id_t = uint64_t;
    using ptr_t = void*;
    using const_ptr_t = const void* const;
    using offset_t = std::uintptr_t;

    BaseRelativePointer(ptr_t ptr, id_t id) noexcept;

    BaseRelativePointer(offset_t offset, id_t id) noexcept;

    BaseRelativePointer(ptr_t ptr = nullptr) noexcept;

    BaseRelativePointer(const BaseRelativePointer& other) noexcept;

    BaseRelativePointer(BaseRelativePointer&& other) noexcept;

    BaseRelativePointer& operator=(const BaseRelativePointer& other) noexcept;

    BaseRelativePointer& operator=(void* ptr) noexcept;

    BaseRelativePointer& operator=(BaseRelativePointer&& other) noexcept;

    ptr_t get() const noexcept;

    id_t getId() const noexcept;

    offset_t getOffset() const noexcept;

    ptr_t getBasePtr() const noexcept;

    static id_t registerPtr(const ptr_t ptr, uint64_t size = 0U) noexcept;

    static bool registerPtr(const id_t id, const ptr_t ptr, uint64_t size = 0U) noexcept;

    static bool unregisterPtr(const id_t id) noexcept;

    static ptr_t getBasePtr(const id_t id) noexcept;

    static void unregisterAll() noexcept;

    static offset_t getOffset(const id_t id, const_ptr_t ptr) noexcept;

    static ptr_t getPtr(const id_t id, const offset_t offset) noexcept;

    static id_t searchId(ptr_t ptr) noexcept;

    static bool isValid(id_t id) noexcept;

    static PointerRepository<id_t, ptr_t>& getRepository() noexcept;

    offset_t computeOffset(ptr_t ptr) const noexcept;

    ptr_t computeRawPtr() const noexcept;

    static constexpr id_t NULL_POINTER_ID = std::numeric_limits<id_t>::max();
    static constexpr offset_t NULL_POINTER_OFFSET = std::numeric_limits<offset_t>::max();

  protected:
    id_t m_id{NULL_POINTER_ID};
    offset_t m_offset{NULL_POINTER_OFFSET};
};
} // namespace rp
} // namespace iox

#endif // IOX_UTILS_RELOCATABLE_POINTER_BASE_RELATIVE_POINTER_HPP

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