| Fast DDS Version 3.3.0 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
18
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
30 namespace eprosima {
31 namespace fastdds {
32 namespace rtps {
33
36 struct FASTDDS_EXPORTED_API GuidPrefix_t
37{
38 static constexpr unsigned int size = 12;
39 octet value[size];
40
42 GuidPrefix_t()
43 {
44 memset(value, 0, size);
45 }
46
56 bool is_on_same_host_as(
57 const GuidPrefix_t& other_guid_prefix) const;
58
64 bool is_from_this_host() const;
65
75 bool is_on_same_process_as(
76 const GuidPrefix_t& other_guid_prefix) const;
77
83 bool is_from_this_process() const;
84
85 static GuidPrefix_t unknown()
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
145 const GuidPrefix_t c_GuidPrefix_Unknown;
146
147 inline 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
164 inline 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
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<<
std::ostream & operator<<(std::ostream &output, BuiltinTransports transports)
Definition BuiltinTransports.hpp:118
eprosima::fastdds::rtps::octet
unsigned char octet
Definition Types.hpp:83
eprosima::fastdds::rtps::c_GuidPrefix_Unknown
const GuidPrefix_t c_GuidPrefix_Unknown
Definition GuidPrefix_t.hpp:145
eprosima::fastdds
eprosima
eProsima namespace.
eprosima::fastdds::rtps::GuidPrefix_t
Structure GuidPrefix_t, Guid Prefix of GUID_t.
Definition GuidPrefix_t.hpp:37
eprosima::fastdds::rtps::GuidPrefix_t::is_from_this_host
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...
eprosima::fastdds::rtps::GuidPrefix_t::GuidPrefix_t
GuidPrefix_t()
Default constructor. Set the Guid prefix to 0.
Definition GuidPrefix_t.hpp:42
eprosima::fastdds::rtps::GuidPrefix_t::is_from_this_process
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...
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::GuidPrefix_t::is_on_same_host_as
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.
eprosima::fastdds::rtps::GuidPrefix_t::is_on_same_process_as
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.
eprosima::fastdds::rtps::GuidPrefix_t::value
octet value[size]
Definition GuidPrefix_t.hpp:39
eprosima::fastdds::rtps::GuidPrefix_t::size
static constexpr unsigned int size
Definition GuidPrefix_t.hpp:38
eprosima::fastdds::rtps::GuidPrefix_t::unknown
static GuidPrefix_t unknown()
Definition GuidPrefix_t.hpp:85