Skip to content

iceoryx_utils/internal/relocatable_pointer/base_relocatable_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::BaseRelocatablePointer
pointer class to use when pointer and pointee are located in the same shared memory segment We can have the following scenario: Pointer p points to object X of type T and both are stored in shared memory segment S.

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_RELOCATABLE_POINTER_HPP
#define IOX_UTILS_RELOCATABLE_POINTER_BASE_RELOCATABLE_POINTER_HPP

#include <cstdint>
#include <limits>

namespace iox
{
namespace rp
{
class BaseRelocatablePointer
{
    template <typename T>
    friend class RelocatablePointer;

  public:
    using offset_t = std::ptrdiff_t;

    BaseRelocatablePointer() noexcept;

    explicit BaseRelocatablePointer(const void* ptr) noexcept;

    BaseRelocatablePointer(const BaseRelocatablePointer& other) noexcept;

    BaseRelocatablePointer(BaseRelocatablePointer&& other) noexcept;

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

    BaseRelocatablePointer& operator=(const void* rawPtr) noexcept;

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

    const void* operator*() const noexcept;

    operator bool() const noexcept;

    bool operator!() const noexcept;

    const void* get() const noexcept;

    offset_t getOffset() const noexcept;

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

  protected:
    offset_t m_offset{NULL_POINTER_OFFSET};

    offset_t computeOffset(const void* ptr) const noexcept;

    void* computeRawPtr() const noexcept;
};

} // namespace rp
} // namespace iox

#endif // IOX_UTILS_RELOCATABLE_POINTER_BASE_RELOCATABLE_POINTER_HPP

Updated on 26 April 2021 at 15:31:01 CEST