Fast DDS  Version 3.0.1
Fast DDS
Loading...
Searching...
No Matches
GuidPrefix_t.hpp
1// Copyright 2016-2019 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
19#ifndef FASTDDS_RTPS_COMMON__GUIDPREFIX_T_HPP
20#define FASTDDS_RTPS_COMMON__GUIDPREFIX_T_HPP
21
22#include <fastdds/fastdds_dll.hpp>
23#include <fastdds/rtps/common/Types.hpp>
24
25#include <cstdint>
26#include <cstring>
27#include <sstream>
28#include <iomanip>
29
30namespace eprosima {
31namespace fastdds {
32namespace rtps {
33
36struct FASTDDS_EXPORTED_API GuidPrefix_t
37{
38 static constexpr unsigned int size = 12;
39 octet value[size];
40
43 {
44 memset(value, 0, size);
45 }
46
57 const GuidPrefix_t& other_guid_prefix) const;
58
64 bool is_from_this_host() const;
65
76 const GuidPrefix_t& other_guid_prefix) const;
77
84
86 {
87 return GuidPrefix_t();
88 }
89
90#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
91
97 bool operator ==(
98 const GuidPrefix_t& prefix) const
99 {
100 return (memcmp(value, prefix.value, size) == 0);
101 }
102
108 bool operator !=(
109 const GuidPrefix_t& prefix) const
110 {
111 return (memcmp(value, prefix.value, size) != 0);
112 }
113
119 bool operator <(
120 const GuidPrefix_t& prefix) const
121 {
122 return std::memcmp(value, prefix.value, size) < 0;
123 }
124
135 static int cmp(
136 const GuidPrefix_t& prefix1,
137 const GuidPrefix_t& prefix2)
138 {
139 return std::memcmp(prefix1.value, prefix2.value, size);
140 }
141
142#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
143};
144
146
147inline std::ostream& operator <<(
148 std::ostream& output,
149 const GuidPrefix_t& guiP)
150{
151 std::stringstream ss;
152 ss << std::hex;
153 char old_fill = ss.fill('0');
154 for (uint8_t i = 0; i < 11; ++i)
155 {
156 ss << std::setw(2) << (int)guiP.value[i] << ".";
157 }
158 ss << std::setw(2) << (int)guiP.value[11];
159 ss.fill(old_fill);
160 ss << std::dec;
161 return output << ss.str();
162}
163
164inline std::istream& operator >>(
165 std::istream& input,
166 GuidPrefix_t& guiP)
167{
168 std::istream::sentry s(input);
169
170 if (s)
171 {
172 char point;
173 unsigned short hex;
174 std::ios_base::iostate excp_mask = input.exceptions();
175
176 try
177 {
178 input.exceptions(excp_mask | std::ios_base::failbit | std::ios_base::badbit);
179 input >> std::hex >> hex;
180
181 if (hex > 255)
182 {
183 input.setstate(std::ios_base::failbit);
184 }
185
186 guiP.value[0] = static_cast<octet>(hex);
187
188 for (int i = 1; i < 12; ++i)
189 {
190 input >> point >> hex;
191 if ( point != '.' || hex > 255 )
192 {
193 input.setstate(std::ios_base::failbit);
194 }
195 guiP.value[i] = static_cast<octet>(hex);
196 }
197
198 input >> std::dec;
199 }
200 catch (std::ios_base::failure& )
201 {
202 guiP = GuidPrefix_t::unknown();
203 }
204
205 input.exceptions(excp_mask);
206 }
207
208 return input;
209}
210
211} // namespace rtps
212} // namespace fastdds
213} // namespace eprosima
214
215#endif // FASTDDS_RTPS_COMMON__GUIDPREFIX_T_HPP
std::istream & operator>>(std::istream &input, EntityId_t &enP)
Definition EntityId_t.hpp:289
std::ostream & operator<<(std::ostream &output, BuiltinTransports transports)
Definition BuiltinTransports.hpp:117
unsigned char octet
Definition Types.hpp:83
const GuidPrefix_t c_GuidPrefix_Unknown
Definition GuidPrefix_t.hpp:145
eProsima namespace.
Structure GuidPrefix_t, Guid Prefix of GUID_t.
Definition GuidPrefix_t.hpp:37
bool is_from_this_host() const
Checks whether this guid prefix is from a (Fast-DDS) entity created on this host (from where this met...
GuidPrefix_t()
Default constructor. Set the Guid prefix to 0.
Definition GuidPrefix_t.hpp:42
bool is_from_this_process() const
Checks whether this guid prefix is from a (Fast-DDS) entity created on this host and process (from wh...
static int cmp(const GuidPrefix_t &prefix1, const GuidPrefix_t &prefix2)
Guid Prefix compare static method.
Definition GuidPrefix_t.hpp:135
bool is_on_same_host_as(const GuidPrefix_t &other_guid_prefix) const
Checks whether this guid prefix is from an entity on the same host as another guid prefix.
bool is_on_same_process_as(const GuidPrefix_t &other_guid_prefix) const
Checks whether this guid prefix is for an entity on the same host and process as another guid prefix.
octet value[size]
Definition GuidPrefix_t.hpp:39
static GuidPrefix_t unknown()
Definition GuidPrefix_t.hpp:85