Fast DDS  Version 3.6.1.0
Fast DDS
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 
25 namespace eprosima {
26 namespace fastdds {
27 namespace rtps {
28 
33 class FASTDDS_EXPORTED_API SampleIdentity
34 {
35 public:
36 
41  const SampleIdentity& sample_id) const
42  {
43  return (writer_guid_ == sample_id.writer_guid_) && (sequence_number_ == sample_id.sequence_number_);
44  }
45 
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 
69  const GUID_t& guid)
70  {
71  writer_guid_ = guid;
72  return *this;
73  }
74 
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 
88  {
89  return writer_guid_;
90  }
91 
93  const SequenceNumber_t& seq)
94  {
95  sequence_number_ = seq;
96  return *this;
97  }
98 
100  SequenceNumber_t&& seq)
101  {
102  sequence_number_ = std::move(seq);
103  return *this;
104  }
105 
107  {
108  return sequence_number_;
109  }
110 
112  {
113  return sequence_number_;
114  }
115 
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
This class is used to specify a sample.
Definition: SampleIdentity.hpp:34
SampleIdentity & writer_guid(GUID_t &&guid)
Definition: SampleIdentity.hpp:75
SampleIdentity & sequence_number(const SequenceNumber_t &seq)
Definition: SampleIdentity.hpp:92
GUID_t & writer_guid()
Definition: SampleIdentity.hpp:87
SequenceNumber_t & sequence_number()
Definition: SampleIdentity.hpp:111
SampleIdentity & writer_guid(const GUID_t &guid)
Definition: SampleIdentity.hpp:68
const SequenceNumber_t & sequence_number() const
Definition: SampleIdentity.hpp:106
static SampleIdentity unknown()
Definition: SampleIdentity.hpp:116
SampleIdentity & sequence_number(SequenceNumber_t &&seq)
Definition: SampleIdentity.hpp:99
const GUID_t & writer_guid() const
Definition: SampleIdentity.hpp:82
std::istream & operator>>(std::istream &input, EntityId_t &enP)
Definition: EntityId_t.hpp:289
bool operator!=(const EntityId_t &id1, const EntityId_t &id2)
Guid prefix comparison operator.
Definition: EntityId_t.hpp:267
bool operator==(const BuiltinTransportsOptions &bto1, const BuiltinTransportsOptions &bto2)
Equal to operator.
Definition: BuiltinTransports.hpp:79
std::ostream & operator<<(std::ostream &output, BuiltinTransports transports)
Definition: BuiltinTransports.hpp:118
bool operator<(const GUID_t &g1, const GUID_t &g2)
Definition: Guid.hpp:192
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