/src/Fast-DDS/include/fastdds/rtps/common/WriteParams.hpp
Line | Count | Source (jump to first uncovered line) |
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 | | /** |
16 | | * @file WriteParams.hpp |
17 | | */ |
18 | | #ifndef FASTDDS_RTPS_COMMON__WRITEPARAMS_HPP |
19 | | #define FASTDDS_RTPS_COMMON__WRITEPARAMS_HPP |
20 | | |
21 | | #include <memory> |
22 | | |
23 | | #include <fastdds/rtps/common/SampleIdentity.hpp> |
24 | | #include <fastdds/rtps/common/Time_t.hpp> |
25 | | |
26 | | namespace eprosima { |
27 | | namespace fastdds { |
28 | | namespace rtps { |
29 | | |
30 | | /*! |
31 | | * @brief This class contains additional information of a CacheChange. |
32 | | * |
33 | | * @ingroup COMMON_MODULE |
34 | | */ |
35 | | class FASTDDS_EXPORTED_API WriteParams |
36 | | { |
37 | | public: |
38 | | |
39 | | /** |
40 | | * @brief Base class storing custom information in the |
41 | | * WriteParams structure for later filtering. |
42 | | * |
43 | | * This struct serves as a base class that allows derived |
44 | | * classes to be deleted safely through a pointer to this base type. |
45 | | * It is intended to be user-extensible. |
46 | | */ |
47 | | struct FASTDDS_EXPORTED_API UserWriteData |
48 | | { |
49 | | UserWriteData() = default; |
50 | | |
51 | | virtual ~UserWriteData() = default; |
52 | | }; |
53 | | |
54 | | /** |
55 | | * Set the value of the sample_identity member. |
56 | | * |
57 | | * @param sample_id New value for the sample_identity member. |
58 | | * |
59 | | * @return Reference to the modified object in order to allow daisy chaining. |
60 | | */ |
61 | | WriteParams& sample_identity( |
62 | | const SampleIdentity& sample_id) |
63 | 0 | { |
64 | 0 | sample_identity_ = sample_id; |
65 | 0 | return *this; |
66 | 0 | } |
67 | | |
68 | | /** |
69 | | * Set the value of the sample_identity member. |
70 | | * |
71 | | * @param sample_id New value for the sample_identity member. |
72 | | * |
73 | | * @return Reference to the modified object in order to allow daisy chaining. |
74 | | */ |
75 | | WriteParams& sample_identity( |
76 | | SampleIdentity&& sample_id) |
77 | 0 | { |
78 | 0 | sample_identity_ = std::move(sample_id); |
79 | 0 | return *this; |
80 | 0 | } |
81 | | |
82 | | /** |
83 | | * Get the value of the sample_identity member. |
84 | | * |
85 | | * @return Constant reference to the sample_identity member. |
86 | | */ |
87 | | const SampleIdentity& sample_identity() const |
88 | 0 | { |
89 | 0 | return sample_identity_; |
90 | 0 | } |
91 | | |
92 | | /** |
93 | | * Set the value of the sample_identity member. |
94 | | * |
95 | | * @return Reference to the sample_identity member. |
96 | | */ |
97 | | SampleIdentity& sample_identity() |
98 | 0 | { |
99 | 0 | return sample_identity_; |
100 | 0 | } |
101 | | |
102 | | /** |
103 | | * Set the value of the related_sample_identity member of this class. |
104 | | * |
105 | | * @param sample_id New value for the related_sample_identity member. |
106 | | * |
107 | | * @return Reference to the modified object in order to allow daisy chaining. |
108 | | */ |
109 | | WriteParams& related_sample_identity( |
110 | | const SampleIdentity& sample_id) |
111 | 0 | { |
112 | 0 | related_sample_identity_ = sample_id; |
113 | 0 | return *this; |
114 | 0 | } |
115 | | |
116 | | /** |
117 | | * Set the related_sample_identity member of this class. |
118 | | * |
119 | | * @param sample_id New value for the related_sample_identity member. |
120 | | * |
121 | | * @return Reference to the modified object in order to allow daisy chaining. |
122 | | */ |
123 | | WriteParams& related_sample_identity( |
124 | | SampleIdentity&& sample_id) |
125 | 0 | { |
126 | 0 | related_sample_identity_ = std::move(sample_id); |
127 | 0 | return *this; |
128 | 0 | } |
129 | | |
130 | | /** |
131 | | * Get the value of the related_sample_identity member. |
132 | | * |
133 | | * @return Constant reference to the related_sample_identity member. |
134 | | */ |
135 | | const SampleIdentity& related_sample_identity() const |
136 | 0 | { |
137 | 0 | return related_sample_identity_; |
138 | 0 | } |
139 | | |
140 | | /** |
141 | | * Set the value of the related_sample_identity member. |
142 | | * |
143 | | * @return Reference to the related_sample_identity member. |
144 | | */ |
145 | | SampleIdentity& related_sample_identity() |
146 | 0 | { |
147 | 0 | return related_sample_identity_; |
148 | 0 | } |
149 | | |
150 | | /** |
151 | | * Get the value of the source_timestamp member. |
152 | | * |
153 | | * @return Current value of the source_timestamp member. |
154 | | */ |
155 | | Time_t source_timestamp() const |
156 | 0 | { |
157 | 0 | return source_timestamp_; |
158 | 0 | } |
159 | | |
160 | | /** |
161 | | * Set the value of the source_timestamp member. |
162 | | * |
163 | | * @return Reference to the source_timestamp member. |
164 | | */ |
165 | | Time_t& source_timestamp() |
166 | 0 | { |
167 | 0 | return source_timestamp_; |
168 | 0 | } |
169 | | |
170 | | /** |
171 | | * Set the source_timestamp member of this class. |
172 | | * |
173 | | * @param timestamp New value for the source_timestamp member. |
174 | | * |
175 | | * @return Reference to the modified object in order to allow daisy chaining. |
176 | | */ |
177 | | WriteParams& source_timestamp( |
178 | | const Time_t& timestamp) |
179 | 0 | { |
180 | 0 | source_timestamp_ = timestamp; |
181 | 0 | return *this; |
182 | 0 | } |
183 | | |
184 | | /** |
185 | | * Set the source_timestamp member of this class. |
186 | | * |
187 | | * @param timestamp New value for the source_timestamp member. |
188 | | * |
189 | | * @return Reference to the modified object in order to allow daisy chaining. |
190 | | */ |
191 | | WriteParams& source_timestamp( |
192 | | Time_t&& timestamp) |
193 | 0 | { |
194 | 0 | source_timestamp_ = std::move(timestamp); |
195 | 0 | return *this; |
196 | 0 | } |
197 | | |
198 | | /** |
199 | | * @brief Retrieves the user write data. |
200 | | * |
201 | | * @return Shared pointer to the user write data. |
202 | | */ |
203 | | std::shared_ptr<UserWriteData> user_write_data() const |
204 | 0 | { |
205 | 0 | return user_write_data_; |
206 | 0 | } |
207 | | |
208 | | /** |
209 | | * Set the user write data. |
210 | | * |
211 | | * @param write_data New value for the user_write_data member. |
212 | | * |
213 | | * @return Reference to the modified object in order to allow daisy chaining. |
214 | | */ |
215 | | WriteParams& user_write_data( |
216 | | std::shared_ptr<UserWriteData> write_data) |
217 | 0 | { |
218 | 0 | user_write_data_ = write_data; |
219 | 0 | return *this; |
220 | 0 | } |
221 | | |
222 | | static WriteParams WRITE_PARAM_DEFAULT; |
223 | | |
224 | | /** |
225 | | * Default value for methods receiving a WriteParams. |
226 | | * |
227 | | * Will contain the following values on its members: |
228 | | * - sample_identity: Invalid SampleIdentity |
229 | | * - related_sample_identity: Invalid SampleIdentity |
230 | | * - source_timestamp: Invalid Time_t |
231 | | * |
232 | | * @note This should not return a reference to the static value if this value is meant to be |
233 | | * read and written from different threads. |
234 | | */ |
235 | | static WriteParams write_params_default() noexcept |
236 | 0 | { |
237 | 0 | return WriteParams(); |
238 | 0 | } |
239 | | |
240 | | private: |
241 | | |
242 | | class FASTDDS_EXPORTED_API UserWriteDataPtr : public std::shared_ptr<UserWriteData> |
243 | | { |
244 | | public: |
245 | | |
246 | | UserWriteDataPtr( |
247 | | std::shared_ptr<UserWriteData> ptr) |
248 | 4 | : std::shared_ptr<UserWriteData>(ptr) |
249 | 4 | { |
250 | 4 | } |
251 | | |
252 | | }; |
253 | | |
254 | | /// Attribute that holds sample_identity member value |
255 | | SampleIdentity sample_identity_; |
256 | | /// Attribute that holds related_sample_identity member value |
257 | | SampleIdentity related_sample_identity_; |
258 | | /// Attribute that holds source_timestamp member value |
259 | | Time_t source_timestamp_{ -1, TIME_T_INFINITE_NANOSECONDS }; |
260 | | /// User write data |
261 | | UserWriteDataPtr user_write_data_{nullptr}; |
262 | | }; |
263 | | |
264 | | } // namespace rtps |
265 | | } // namespace fastdds |
266 | | } // namespace eprosima |
267 | | |
268 | | #endif //FASTDDS_RTPS_COMMON__WRITEPARAMS_HPP |