Fast DDS  Version 3.1.2
Fast DDS
Loading...
Searching...
No Matches
SampleIdentity.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
19#ifndef FASTDDS_RTPS_COMMON__SAMPLEIDENTITY_HPP
20#define FASTDDS_RTPS_COMMON__SAMPLEIDENTITY_HPP
21
22#include <fastdds/rtps/common/Guid.hpp>
23#include <fastdds/rtps/common/SequenceNumber.hpp>
24
25namespace eprosima {
26namespace fastdds {
27namespace rtps {
28
33class FASTDDS_EXPORTED_API SampleIdentity
34{
35public:
36
41 : writer_guid_(GUID_t::unknown())
42 , sequence_number_(SequenceNumber_t::unknown())
43 {
44 }
45
50 const SampleIdentity& sample_id)
51 : writer_guid_(sample_id.writer_guid_)
52 , sequence_number_(sample_id.sequence_number_)
53 {
54 }
55
60 SampleIdentity&& sample_id)
61 : writer_guid_(std::move(sample_id.writer_guid_))
62 , sequence_number_(std::move(sample_id.sequence_number_))
63 {
64 }
65
69 SampleIdentity& operator =(
70 const SampleIdentity& sample_id)
71 {
72 writer_guid_ = sample_id.writer_guid_;
73 sequence_number_ = sample_id.sequence_number_;
74 return *this;
75 }
76
80 SampleIdentity& operator =(
81 SampleIdentity&& sample_id)
82 {
83 writer_guid_ = std::move(sample_id.writer_guid_);
84 sequence_number_ = std::move(sample_id.sequence_number_);
85 return *this;
86 }
87
91 bool operator ==(
92 const SampleIdentity& sample_id) const
93 {
94 return (writer_guid_ == sample_id.writer_guid_) && (sequence_number_ == sample_id.sequence_number_);
95 }
96
100 bool operator !=(
101 const SampleIdentity& sample_id) const
102 {
103 return !(*this == sample_id);
104 }
105
111 bool operator <(
112 const SampleIdentity& sample) const
113 {
114 return writer_guid_ < sample.writer_guid_
115 || (writer_guid_ == sample.writer_guid_
116 && sequence_number_ < sample.sequence_number_);
117 }
118
120 const GUID_t& guid)
121 {
122 writer_guid_ = guid;
123 return *this;
124 }
125
127 GUID_t&& guid)
128 {
129 writer_guid_ = std::move(guid);
130 return *this;
131 }
132
133 const GUID_t& writer_guid() const
134 {
135 return writer_guid_;
136 }
137
139 {
140 return writer_guid_;
141 }
142
144 const SequenceNumber_t& seq)
145 {
146 sequence_number_ = seq;
147 return *this;
148 }
149
151 SequenceNumber_t&& seq)
152 {
153 sequence_number_ = std::move(seq);
154 return *this;
155 }
156
158 {
159 return sequence_number_;
160 }
161
163 {
164 return sequence_number_;
165 }
166
168 {
169 return SampleIdentity();
170 }
171
172private:
173
174 GUID_t writer_guid_;
175
176 SequenceNumber_t sequence_number_;
177
178 friend std::istream& operator >>(
179 std::istream& input,
180 SampleIdentity& sid);
181 friend std::ostream& operator <<(
182 std::ostream& output,
183 const SampleIdentity& sid);
184};
185
186#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
187
194inline std::istream& operator >>(
195 std::istream& input,
196 SampleIdentity& sid)
197{
198 std::istream::sentry s(input);
199
200 if (s)
201 {
202 std::ios_base::iostate excp_mask = input.exceptions();
203
204 try
205 {
206 input.exceptions(excp_mask | std::ios_base::failbit | std::ios_base::badbit);
207
208 char sep;
209 input >> sid.writer_guid_ >> sep >> sid.sequence_number_;
210
211 if (sep != '|')
212 {
213 input.setstate(std::ios_base::failbit);
214 }
215 }
216 catch (std::ios_base::failure&)
217 {
218 // maybe is unknown or just invalid
219 sid.writer_guid_ = GUID_t::unknown();
220 sid.sequence_number_ = SequenceNumber_t::unknown();
221 }
222
223 input.exceptions(excp_mask);
224 }
225
226 return input;
227}
228
235inline std::ostream& operator <<(
236 std::ostream& output,
237 const SampleIdentity& sid)
238{
239 output << sid.writer_guid_ << '|' << sid.sequence_number_;
240
241 return output;
242}
243
244#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
245
246} //namespace rtps
247} //namespace fastdds
248} //namespace eprosima
249
250#endif // FASTDDS_RTPS_COMMON__SAMPLEIDENTITY_HPP
This class is used to specify a sample.
Definition SampleIdentity.hpp:34
SampleIdentity(const SampleIdentity &sample_id)
Copy constructor.
Definition SampleIdentity.hpp:49
static SampleIdentity unknown()
Definition SampleIdentity.hpp:167
SampleIdentity()
Default constructor.
Definition SampleIdentity.hpp:40
SampleIdentity & sequence_number(const SequenceNumber_t &seq)
Definition SampleIdentity.hpp:143
const GUID_t & writer_guid() const
Definition SampleIdentity.hpp:133
SampleIdentity & writer_guid(GUID_t &&guid)
Definition SampleIdentity.hpp:126
GUID_t & writer_guid()
Definition SampleIdentity.hpp:138
SampleIdentity & sequence_number(SequenceNumber_t &&seq)
Definition SampleIdentity.hpp:150
SequenceNumber_t & sequence_number()
Definition SampleIdentity.hpp:162
SampleIdentity(SampleIdentity &&sample_id)
Move constructor.
Definition SampleIdentity.hpp:59
SampleIdentity & writer_guid(const GUID_t &guid)
Definition SampleIdentity.hpp:119
const SequenceNumber_t & sequence_number() const
Definition SampleIdentity.hpp:157
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
eProsima namespace.
Definition EntityId_t.hpp:388
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
static GUID_t unknown() noexcept
Definition Guid.hpp:138
Structure SequenceNumber_t, different for each change in the same writer.
Definition SequenceNumber.hpp:38
static SequenceNumber_t unknown() noexcept
Definition SequenceNumber.hpp:123