SampleIdentity.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  15. * @file SampleIdentity.h
  16. */
  17. #ifndef _FASTDDS_RTPS_COMMON_SAMPLEIDENTITY_H_
  18. #define _FASTDDS_RTPS_COMMON_SAMPLEIDENTITY_H_
  19. #include <fastdds/rtps/common/Guid.h>
  20. #include <fastdds/rtps/common/SequenceNumber.h>
  21. namespace eprosima {
  22. namespace fastrtps {
  23. namespace rtps {
  24. /*!
  25. * @brief This class is used to specify a sample
  26. * @ingroup COMMON_MODULE
  27. */
  28. class RTPS_DllAPI SampleIdentity
  29. {
  30. public:
  31. /*!
  32. * @brief Default constructor. Constructs an unknown SampleIdentity.
  33. */
  34. SampleIdentity()
  35. : writer_guid_(GUID_t::unknown())
  36. , sequence_number_(SequenceNumber_t::unknown())
  37. {
  38. }
  39. /*!
  40. * @brief Copy constructor.
  41. */
  42. SampleIdentity(
  43. const SampleIdentity& sample_id)
  44. : writer_guid_(sample_id.writer_guid_)
  45. , sequence_number_(sample_id.sequence_number_)
  46. {
  47. }
  48. /*!
  49. * @brief Move constructor.
  50. */
  51. SampleIdentity(
  52. SampleIdentity&& sample_id)
  53. : writer_guid_(std::move(sample_id.writer_guid_))
  54. , sequence_number_(std::move(sample_id.sequence_number_))
  55. {
  56. }
  57. /*!
  58. * @brief Assignment operator.
  59. */
  60. SampleIdentity& operator=(
  61. const SampleIdentity& sample_id)
  62. {
  63. writer_guid_ = sample_id.writer_guid_;
  64. sequence_number_ = sample_id.sequence_number_;
  65. return *this;
  66. }
  67. /*!
  68. * @brief Move constructor.
  69. */
  70. SampleIdentity& operator=(
  71. SampleIdentity&& sample_id)
  72. {
  73. writer_guid_ = std::move(sample_id.writer_guid_);
  74. sequence_number_ = std::move(sample_id.sequence_number_);
  75. return *this;
  76. }
  77. /*!
  78. * @brief
  79. */
  80. bool operator==(
  81. const SampleIdentity& sample_id) const
  82. {
  83. return (writer_guid_ == sample_id.writer_guid_) && (sequence_number_ == sample_id.sequence_number_);
  84. }
  85. /*!
  86. * @brief
  87. */
  88. bool operator!=(
  89. const SampleIdentity& sample_id) const
  90. {
  91. return !(*this == sample_id);
  92. }
  93. /**
  94. * @brief To allow using SampleIdentity as map key.
  95. * @param sample
  96. * @return
  97. */
  98. bool operator<(
  99. const SampleIdentity& sample) const
  100. {
  101. return writer_guid_ < sample.writer_guid_
  102. || (writer_guid_ == sample.writer_guid_
  103. && sequence_number_ < sample.sequence_number_);
  104. }
  105. SampleIdentity& writer_guid(
  106. const GUID_t& guid)
  107. {
  108. writer_guid_ = guid;
  109. return *this;
  110. }
  111. SampleIdentity& writer_guid(
  112. GUID_t&& guid)
  113. {
  114. writer_guid_ = std::move(guid);
  115. return *this;
  116. }
  117. const GUID_t& writer_guid() const
  118. {
  119. return writer_guid_;
  120. }
  121. GUID_t& writer_guid()
  122. {
  123. return writer_guid_;
  124. }
  125. SampleIdentity& sequence_number(
  126. const SequenceNumber_t& seq)
  127. {
  128. sequence_number_ = seq;
  129. return *this;
  130. }
  131. SampleIdentity& sequence_number(
  132. SequenceNumber_t&& seq)
  133. {
  134. sequence_number_ = std::move(seq);
  135. return *this;
  136. }
  137. const SequenceNumber_t& sequence_number() const
  138. {
  139. return sequence_number_;
  140. }
  141. SequenceNumber_t& sequence_number()
  142. {
  143. return sequence_number_;
  144. }
  145. static SampleIdentity unknown()
  146. {
  147. return SampleIdentity();
  148. }
  149. private:
  150. GUID_t writer_guid_;
  151. SequenceNumber_t sequence_number_;
  152. };
  153. } //namespace rtps
  154. } //namespace fastrtps
  155. } //namespace eprosima
  156. #endif // _FASTDDS_RTPS_COMMON_SAMPLEIDENTITY_H_