iceoryx_doc  1.0.1
relative_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_RELATIVE_POINTER_HPP
19 #define IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_HPP
20 
21 #include "base_relative_pointer.hpp"
22 
23 #include <cstdint>
24 #include <iostream>
25 #include <limits>
26 
27 namespace iox
28 {
29 namespace rp
30 {
32 template <typename T>
34 {
35  public:
39  RelativePointer(ptr_t ptr, id_t id) noexcept;
40 
44  RelativePointer(offset_t offset, id_t id) noexcept;
45 
48  RelativePointer(ptr_t ptr = nullptr) noexcept;
49 
52  RelativePointer(const BaseRelativePointer& other) noexcept;
53 
57  RelativePointer& operator=(const BaseRelativePointer& other) noexcept;
58 
62  RelativePointer& operator=(ptr_t ptr) noexcept;
63 
67  template <typename U = T>
68  typename std::enable_if<!std::is_void<U>::value, U&>::type operator*() noexcept;
69 
72  T* operator->() noexcept;
73 
77  template <typename U = T>
78  typename std::enable_if<!std::is_void<U>::value, const U&>::type operator*() const noexcept;
79 
82  T* operator->() const noexcept;
83 
86  T* get() const noexcept;
87 
90  operator T*() const noexcept;
91 
95  bool operator==(T* const ptr) const noexcept;
96 
100  bool operator!=(T* const ptr) const noexcept;
101 };
102 
103 } // namespace rp
104 } // namespace iox
105 
106 #include "iceoryx_utils/internal/relocatable_pointer/relative_pointer.inl"
107 
108 #endif // IOX_UTILS_RELOCATABLE_POINTER_RELATIVE_POINTER_HPP
109 
pointer class to use when pointer and pointee are located in different shared memory segments We can ...
Definition: base_relative_pointer.hpp:53
typed version so we can use operator->
Definition: relative_pointer.hpp:34
RelativePointer & operator=(const BaseRelativePointer &other) noexcept
assign this to point to the same pointee as the BaseRelativePointer other
Definition: relative_pointer.inl:53
T * get() const noexcept
access the underlying object
Definition: relative_pointer.inl:96
RelativePointer(ptr_t ptr, id_t id) noexcept
constructs a RelativePointer pointing to the same pointee as ptr in a segment identified by id
Definition: relative_pointer.inl:28
T * operator->() noexcept
access to the underlying object
Definition: relative_pointer.inl:77
bool operator!=(T *const ptr) const noexcept
checks if this and ptr point not to the same pointee
Definition: relative_pointer.inl:114
std::enable_if<!std::is_void< U >::value, U & >::type operator*() noexcept
dereferencing operator which returns a reference to the underlying object
Definition: relative_pointer.inl:71
bool operator==(T *const ptr) const noexcept
checks if this and ptr point to the same pointee
Definition: relative_pointer.inl:108
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28