| Fast DDS Version 3.3.0 Fast DDS

Loading...
Searching...
No Matches
Guid.hpp
1// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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
18
19#ifndef FASTDDS_RTPS_COMMON__GUID_HPP
20#define FASTDDS_RTPS_COMMON__GUID_HPP
21
22#include <fastdds/fastdds_dll.hpp>
23#include <fastdds/rtps/common/Types.hpp>
24#include <fastdds/rtps/common/GuidPrefix_t.hpp>
25#include <fastdds/rtps/common/EntityId_t.hpp>
26
27#include <cstdint>
28#include <cstring>
29#include <sstream>
30
31 namespace eprosima {
32 namespace fastdds {
33 namespace rtps {
34
35 struct InstanceHandle_t;
36
39 struct FASTDDS_EXPORTED_API GUID_t
40{
42 GuidPrefix_t guidPrefix;
44 EntityId_t entityId;
45
49 GUID_t() noexcept
50 {
51 }
52
58 GUID_t(
59 const GuidPrefix_t& guid_prefix,
60 uint32_t id) noexcept
61 : guidPrefix(guid_prefix)
62 , entityId(id)
63 {
64 }
65
70 GUID_t(
71 const GuidPrefix_t& guid_prefix,
72 const EntityId_t& entity_id) noexcept
73 : guidPrefix(guid_prefix)
74 , entityId(entity_id)
75 {
76 }
77
87 bool is_on_same_host_as(
88 const GUID_t& other_guid) const
89 {
90 return guidPrefix.is_on_same_host_as(other_guid.guidPrefix);
91 }
92
98 bool is_from_this_host() const
99 {
100 return guidPrefix.is_from_this_host();
101 }
102
112 bool is_on_same_process_as(
113 const GUID_t& other_guid) const
114 {
115 return guidPrefix.is_on_same_process_as(other_guid.guidPrefix);
116 }
117
123 bool is_from_this_process() const
124 {
125 return guidPrefix.is_from_this_process();
126 }
127
133 bool is_builtin() const
134 {
135 return entityId.value[3] >= 0xC0;
136 }
137
138 static GUID_t unknown() noexcept
139 {
140 return GUID_t();
141 }
142
143 // TODO Review this conversion once InstanceHandle_t is implemented as DDS standard defines
144 explicit operator const InstanceHandle_t&() const
145 {
146 return *reinterpret_cast<const InstanceHandle_t*>(this);
147 }
148};
149
150#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
151
158 inline bool operator ==(
159 const GUID_t& g1,
160 const GUID_t& g2)
161{
162 if (g1.guidPrefix == g2.guidPrefix && g1.entityId == g2.entityId)
163 {
164 return true;
165 }
166 else
167 {
168 return false;
169 }
170}
171
178 inline bool operator !=(
179 const GUID_t& g1,
180 const GUID_t& g2)
181{
182 if (g1.guidPrefix != g2.guidPrefix || g1.entityId != g2.entityId)
183 {
184 return true;
185 }
186 else
187 {
188 return false;
189 }
190}
191
192 inline bool operator <(
193 const GUID_t& g1,
194 const GUID_t& g2)
195{
196 auto prefix_cmp = GuidPrefix_t::cmp(g1.guidPrefix, g2.guidPrefix);
197 if (prefix_cmp < 0)
198 {
199 return true;
200 }
201 else if (prefix_cmp > 0)
202 {
203 return false;
204 }
205 else
206 {
207 return g1.entityId < g2.entityId;
208 }
209}
210
211#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
212
213 const GUID_t c_Guid_Unknown;
214
215#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
216
223 inline std::ostream& operator <<(
224 std::ostream& output,
225 const GUID_t& guid)
226{
227 if (guid != c_Guid_Unknown)
228 {
229 output << guid.guidPrefix << "|" << guid.entityId;
230 }
231 else
232 {
233 output << "|GUID UNKNOWN|";
234 }
235 return output;
236}
237
244 inline std::istream& operator >>(
245 std::istream& input,
246 GUID_t& guid)
247{
248 std::istream::sentry s(input);
249
250 if (s)
251 {
252 std::ios_base::iostate excp_mask = input.exceptions();
253
254 try
255 {
256 input.exceptions(excp_mask | std::ios_base::failbit | std::ios_base::badbit);
257
258 char sep;
259 input >> guid.guidPrefix >> sep >> guid.entityId;
260
261 if (sep != '|')
262 {
263 input.setstate(std::ios_base::failbit);
264 }
265 }
266 catch (std::ios_base::failure&)
267 {
268 // maybe is unknown or just invalid
269 guid = c_Guid_Unknown;
270 }
271
272 input.exceptions(excp_mask);
273 }
274
275 return input;
276}
277
278#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
279
280} // namespace rtps
281} // namespace fastdds
282} // namespace eprosima
283
284#endif // FASTDDS_RTPS_COMMON__GUID_HPP
eprosima::fastdds::rtps
Contains the RTPS protocol implementation.
eprosima::fastdds::rtps::operator>>
std::istream & operator>>(std::istream &input, EntityId_t &enP)
Definition EntityId_t.hpp:289
eprosima::fastdds::rtps::operator==
bool operator==(const BuiltinTransportsOptions &bto1, const BuiltinTransportsOptions &bto2)
Equal to operator.
Definition BuiltinTransports.hpp:79
eprosima::fastdds::rtps::operator<<
std::ostream & operator<<(std::ostream &output, BuiltinTransports transports)
Definition BuiltinTransports.hpp:118
eprosima::fastdds::rtps::operator!=
bool operator!=(const EntityId_t &id1, const EntityId_t &id2)
Guid prefix comparison operator.
Definition EntityId_t.hpp:267
eprosima::fastdds::rtps::operator<
bool operator<(const GUID_t &g1, const GUID_t &g2)
Definition Guid.hpp:192
eprosima::fastdds::rtps::c_Guid_Unknown
const GUID_t c_Guid_Unknown
Definition Guid.hpp:213
eprosima::fastdds
eprosima
eProsima namespace.
eprosima::fastdds::rtps::EntityId_t
Structure EntityId_t, entity id part of GUID_t.
Definition EntityId_t.hpp:77
eprosima::fastdds::rtps::GUID_t
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
eprosima::fastdds::rtps::GUID_t::is_from_this_host
bool is_from_this_host() const
Checks whether this guid is from a (Fast-DDS) entity created on this host (from where this method is ...
Definition Guid.hpp:98
eprosima::fastdds::rtps::GUID_t::is_from_this_process
bool is_from_this_process() const
Checks whether this guid is from a (Fast-DDS) entity created on this process (from where this method ...
Definition Guid.hpp:123
eprosima::fastdds::rtps::GUID_t::GUID_t
GUID_t(const GuidPrefix_t &guid_prefix, const EntityId_t &entity_id) noexcept
Definition Guid.hpp:70
eprosima::fastdds::rtps::GUID_t::GUID_t
GUID_t(const GuidPrefix_t &guid_prefix, uint32_t id) noexcept
Construct.
Definition Guid.hpp:58
eprosima::fastdds::rtps::GUID_t::entityId
EntityId_t entityId
Entity id.
Definition Guid.hpp:44
eprosima::fastdds::rtps::GUID_t::unknown
static GUID_t unknown() noexcept
Definition Guid.hpp:138
eprosima::fastdds::rtps::GUID_t::is_builtin
bool is_builtin() const
Checks whether this guid corresponds to a builtin entity.
Definition Guid.hpp:133
eprosima::fastdds::rtps::GUID_t::is_on_same_process_as
bool is_on_same_process_as(const GUID_t &other_guid) const
Checks whether this guid is for an entity on the same host and process as another guid.
Definition Guid.hpp:112
eprosima::fastdds::rtps::GUID_t::is_on_same_host_as
bool is_on_same_host_as(const GUID_t &other_guid) const
Checks whether this guid is from an entity on the same host as another guid.
Definition Guid.hpp:87
eprosima::fastdds::rtps::GUID_t::GUID_t
GUID_t() noexcept
Default constructor.
Definition Guid.hpp:49
eprosima::fastdds::rtps::GUID_t::guidPrefix
GuidPrefix_t guidPrefix
Guid prefix.
Definition Guid.hpp:42
eprosima::fastdds::rtps::GuidPrefix_t
Structure GuidPrefix_t, Guid Prefix of GUID_t.
Definition GuidPrefix_t.hpp:37
eprosima::fastdds::rtps::GuidPrefix_t::cmp
static int cmp(const GuidPrefix_t &prefix1, const GuidPrefix_t &prefix2)
Guid Prefix compare static method.
Definition GuidPrefix_t.hpp:135
eprosima::fastdds::rtps::InstanceHandle_t
Struct InstanceHandle_t, used to contain the key for WITH_KEY topics.
Definition InstanceHandle.hpp:154