iceoryx_doc  1.0.1
base_relocatable_pointer.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 
18 #ifndef IOX_UTILS_RELOCATABLE_POINTER_BASE_RELOCATABLE_POINTER_HPP
19 #define IOX_UTILS_RELOCATABLE_POINTER_BASE_RELOCATABLE_POINTER_HPP
20 
21 #include <cstdint>
22 #include <limits>
23 
24 namespace iox
25 {
26 namespace rp
27 {
44 {
45  template <typename T>
46  friend class RelocatablePointer;
47 
48  public:
49  using offset_t = std::ptrdiff_t;
50 
53 
56  explicit BaseRelocatablePointer(const void* ptr) noexcept;
57 
61 
65 
69  BaseRelocatablePointer& operator=(const BaseRelocatablePointer& other) noexcept;
70 
74  BaseRelocatablePointer& operator=(const void* rawPtr) noexcept;
75 
79  BaseRelocatablePointer& operator=(BaseRelocatablePointer&& other) noexcept;
80 
83  const void* operator*() const noexcept;
84 
87  operator bool() const noexcept;
88 
91  bool operator!() const noexcept;
92 
95  const void* get() const noexcept;
96 
99  offset_t getOffset() const noexcept;
100 
101  static constexpr offset_t NULL_POINTER_OFFSET = std::numeric_limits<offset_t>::max();
102 
103  protected:
104  offset_t m_offset{NULL_POINTER_OFFSET};
105 
106  offset_t computeOffset(const void* ptr) const noexcept;
107 
108  void* computeRawPtr() const noexcept;
109 };
110 
111 } // namespace rp
112 } // namespace iox
113 
114 #endif // IOX_UTILS_RELOCATABLE_POINTER_BASE_RELOCATABLE_POINTER_HPP
115 
pointer class to use when pointer and pointee are located in the same shared memory segment We can ha...
Definition: base_relocatable_pointer.hpp:44
offset_t getOffset() const noexcept
returns the offset
const void * get() const noexcept
access to the underlying object in shared memory
BaseRelocatablePointer() noexcept
default constructs a logical nullptr
typed version so we can use operator->
Definition: relocatable_pointer.hpp:30
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28