iceoryx_doc  1.0.1
typed_unique_id.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. 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 #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_TYPED_UNIQUE_ID_HPP
17 #define IOX_POSH_POPO_BUILDING_BLOCKS_TYPED_UNIQUE_ID_HPP
18 
19 #include "iceoryx_utils/cxx/newtype.hpp"
20 #include "iceoryx_utils/error_handling/error_handling.hpp"
21 
22 #include <atomic>
23 #include <cstdint>
24 #include <limits>
25 
26 namespace iox
27 {
28 namespace popo
29 {
30 namespace internal
31 {
38 void setUniqueRouDiId(const uint16_t id) noexcept;
39 
41 void unsetUniqueRouDiId() noexcept;
42 
45 uint16_t getUniqueRouDiId() noexcept;
46 } // namespace internal
47 
50 {
51 };
52 constexpr InvalidId_t InvalidId = InvalidId_t();
53 
69 //
97 template <typename T>
98 class TypedUniqueId : public cxx::NewType<uint64_t,
99  cxx::newtype::ProtectedConstructByValueCopy,
100  cxx::newtype::Comparable,
101  cxx::newtype::Sortable,
102  cxx::newtype::Convertable,
103  cxx::newtype::CopyConstructable,
104  cxx::newtype::MoveConstructable,
105  cxx::newtype::CopyAssignable,
106  cxx::newtype::MoveAssignable>
107 {
108  public:
109  using ThisType::ThisType;
110 
113  TypedUniqueId() noexcept;
114 
116  TypedUniqueId(InvalidId_t) noexcept;
117 
118  bool isValid() const noexcept;
119 
120  private:
121  static constexpr uint64_t INVALID_UNIQUE_ID = 0u;
122  static constexpr uint64_t ROUDI_ID_BIT_LENGTH = 16u;
123  static constexpr uint64_t UNIQUE_ID_BIT_LENGTH = 48u;
124  static std::atomic<uint64_t> globalIDCounter; // = 0u
125 };
126 
127 } // namespace popo
128 } // namespace iox
129 
130 #include "iceoryx_posh/internal/popo/building_blocks/typed_unique_id.inl"
131 
132 #endif
Unique ID depending on a type. If you would like to assign different types consistent unique ids use ...
Definition: typed_unique_id.hpp:107
Definition: service_description.hpp:29
Struct to signal the constructor to create an invalid id.
Definition: typed_unique_id.hpp:50