| Fast DDS Version 3.3.0 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
18
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
25 namespace eprosima {
26 namespace fastdds {
27 namespace rtps {
28
33 class FASTDDS_EXPORTED_API SampleIdentity
34{
35 public:
36
40 bool operator ==(
41 const SampleIdentity& sample_id) const
42 {
43 return (writer_guid_ == sample_id.writer_guid_) && (sequence_number_ == sample_id.sequence_number_);
44 }
45
49 bool operator !=(
50 const SampleIdentity& sample_id) const
51 {
52 return !(*this == sample_id);
53 }
54
60 bool operator <(
61 const SampleIdentity& sample) const
62 {
63 return writer_guid_ < sample.writer_guid_
64 || (writer_guid_ == sample.writer_guid_
65 && sequence_number_ < sample.sequence_number_);
66 }
67
68 SampleIdentity& writer_guid(
69 const GUID_t& guid)
70 {
71 writer_guid_ = guid;
72 return *this;
73 }
74
75 SampleIdentity& writer_guid(
76 GUID_t&& guid)
77 {
78 writer_guid_ = std::move(guid);
79 return *this;
80 }
81
82 const GUID_t& writer_guid() const
83 {
84 return writer_guid_;
85 }
86
87 GUID_t& writer_guid()
88 {
89 return writer_guid_;
90 }
91
92 SampleIdentity& sequence_number(
93 const SequenceNumber_t& seq)
94 {
95 sequence_number_ = seq;
96 return *this;
97 }
98
99 SampleIdentity& sequence_number(
100 SequenceNumber_t&& seq)
101 {
102 sequence_number_ = std::move(seq);
103 return *this;
104 }
105
106 const SequenceNumber_t& sequence_number() const
107 {
108 return sequence_number_;
109 }
110
111 SequenceNumber_t& sequence_number()
112 {
113 return sequence_number_;
114 }
115
116 static SampleIdentity unknown()
117 {
118 return SampleIdentity();
119 }
120
121 private:
122
123 GUID_t writer_guid_ = GUID_t::unknown();
124
125 SequenceNumber_t sequence_number_ = SequenceNumber_t::unknown();
126
127 friend std::istream& operator >>(
128 std::istream& input,
129 SampleIdentity& sid);
130 friend std::ostream& operator <<(
131 std::ostream& output,
132 const SampleIdentity& sid);
133};
134
135#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
136
143 inline std::istream& operator >>(
144 std::istream& input,
145 SampleIdentity& sid)
146{
147 std::istream::sentry s(input);
148
149 if (s)
150 {
151 std::ios_base::iostate excp_mask = input.exceptions();
152
153 try
154 {
155 input.exceptions(excp_mask | std::ios_base::failbit | std::ios_base::badbit);
156
157 char sep;
158 input >> sid.writer_guid_ >> sep >> sid.sequence_number_;
159
160 if (sep != '|')
161 {
162 input.setstate(std::ios_base::failbit);
163 }
164 }
165 catch (std::ios_base::failure&)
166 {
167 // maybe is unknown or just invalid
168 sid.writer_guid_ = GUID_t::unknown();
169 sid.sequence_number_ = SequenceNumber_t::unknown();
170 }
171
172 input.exceptions(excp_mask);
173 }
174
175 return input;
176}
177
184 inline std::ostream& operator <<(
185 std::ostream& output,
186 const SampleIdentity& sid)
187{
188 output << sid.writer_guid_ << '|' << sid.sequence_number_;
189
190 return output;
191}
192
193#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
194
195} //namespace rtps
196} //namespace fastdds
197} //namespace eprosima
198
199#endif // FASTDDS_RTPS_COMMON__SAMPLEIDENTITY_HPP
eprosima::fastdds::rtps::SampleIdentity
This class is used to specify a sample.
Definition SampleIdentity.hpp:34
eprosima::fastdds::rtps::SampleIdentity::unknown
static SampleIdentity unknown()
Definition SampleIdentity.hpp:116
eprosima::fastdds::rtps::SampleIdentity::sequence_number
SampleIdentity & sequence_number(const SequenceNumber_t &seq)
Definition SampleIdentity.hpp:92
eprosima::fastdds::rtps::SampleIdentity::writer_guid
const GUID_t & writer_guid() const
Definition SampleIdentity.hpp:82
eprosima::fastdds::rtps::SampleIdentity::writer_guid
SampleIdentity & writer_guid(GUID_t &&guid)
Definition SampleIdentity.hpp:75
eprosima::fastdds::rtps::SampleIdentity::writer_guid
GUID_t & writer_guid()
Definition SampleIdentity.hpp:87
eprosima::fastdds::rtps::SampleIdentity::sequence_number
SampleIdentity & sequence_number(SequenceNumber_t &&seq)
Definition SampleIdentity.hpp:99
eprosima::fastdds::rtps::SampleIdentity::sequence_number
SequenceNumber_t & sequence_number()
Definition SampleIdentity.hpp:111
eprosima::fastdds::rtps::SampleIdentity::writer_guid
SampleIdentity & writer_guid(const GUID_t &guid)
Definition SampleIdentity.hpp:68
eprosima::fastdds::rtps::SampleIdentity::sequence_number
const SequenceNumber_t & sequence_number() const
Definition SampleIdentity.hpp:106
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
eprosima
eProsima namespace.
eprosima::fastdds::rtps::GUID_t
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
eprosima::fastdds::rtps::GUID_t::unknown
static GUID_t unknown() noexcept
Definition Guid.hpp:138
eprosima::fastdds::rtps::SequenceNumber_t
Structure SequenceNumber_t, different for each change in the same writer.
Definition SequenceNumber.hpp:38
eprosima::fastdds::rtps::SequenceNumber_t::unknown
static SequenceNumber_t unknown() noexcept
Definition SequenceNumber.hpp:123