iceoryx_doc  1.0.1
relative_pointer_data.hpp
1 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 
17 #ifndef IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP
18 #define IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP
19 
20 #include "iceoryx_utils/cxx/helplets.hpp"
21 
22 #include <cstdint>
23 
24 namespace iox
25 {
26 namespace rp
27 {
31 {
32  public:
33  using id_t = uint16_t;
34  using offset_t = uint64_t;
35 
37  constexpr RelativePointerData() noexcept = default;
38 
42  constexpr RelativePointerData(id_t id, offset_t offset) noexcept;
43 
46  id_t id() const noexcept;
47 
50  offset_t offset() const noexcept;
51 
53  void reset() noexcept;
54 
57  bool isLogicalNullptr() const noexcept;
58 
60  static constexpr id_t ID_RANGE{std::numeric_limits<id_t>::max()};
62  static constexpr id_t NULL_POINTER_ID{ID_RANGE};
64  static constexpr id_t MAX_VALID_ID{ID_RANGE - 1U};
66  static constexpr offset_t OFFSET_RANGE{(1ULL << 48U) - 1U};
68  static constexpr offset_t NULL_POINTER_OFFSET{OFFSET_RANGE};
70  static constexpr offset_t MAX_VALID_OFFSET{OFFSET_RANGE - 1U};
72  static constexpr offset_t LOGICAL_NULLPTR{NULL_POINTER_OFFSET << 16 | NULL_POINTER_ID};
73 
74  private:
75  uint64_t m_idAndOffset{LOGICAL_NULLPTR};
76 };
77 
78 } // namespace rp
79 } // namespace iox
80 
81 #include "iceoryx_utils/internal/relocatable_pointer/relative_pointer_data.inl"
82 
83 #endif // IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_DATA_HPP
This are the data for a relative pointer. To be able so safely be used in the shared memory and preve...
Definition: relative_pointer_data.hpp:31
static constexpr offset_t LOGICAL_NULLPTR
Definition: relative_pointer_data.hpp:72
static constexpr id_t NULL_POINTER_ID
Definition: relative_pointer_data.hpp:62
offset_t offset() const noexcept
Getter for the offset within the segment.
static constexpr offset_t MAX_VALID_OFFSET
Definition: relative_pointer_data.hpp:70
static constexpr id_t MAX_VALID_ID
Definition: relative_pointer_data.hpp:64
static constexpr id_t ID_RANGE
Definition: relative_pointer_data.hpp:60
void reset() noexcept
Resets the pointer to a logically nullptr.
constexpr RelativePointerData() noexcept=default
Default constructed RelativePointerData which is logically equal to a nullptr.
bool isLogicalNullptr() const noexcept
Checks if the pointer is logically a nullptr.
static constexpr offset_t OFFSET_RANGE
id_t is 16 bit and the offset consumes the remaining 48 bits -> offset range is 2^48 - 1
Definition: relative_pointer_data.hpp:66
static constexpr offset_t NULL_POINTER_OFFSET
Definition: relative_pointer_data.hpp:68
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28