RTI Routing Service Version 7.6.0
LoanedSamples.hpp
1/* $Id$
2
3(c) Copyright, Real-Time Innovations, 2013-2016.
4All rights reserved.
5
6No duplications, whole or partial, manual or electronic, may be made
7without express written permission. Any such copies, or
8revisions thereof, must display this notice unaltered.
9This code contains trade secrets of Real-Time Innovations, Inc.
10
11
12============================================================================= */
13
14#ifndef RTI_ROUTING_PROCESSOR_LOANED_SAMPLES_HPP_
15#define RTI_ROUTING_PROCESSOR_LOANED_SAMPLES_HPP_
16
17#include <utility> // std::move
18#include <iterator>
19
20#include "routingservice/routingservice_adapter_new.h"
21#include <dds/core/types.hpp>
22#include <rti/routing/processor/LoanedSample.hpp>
23#include <rti/routing/adapter/StreamReader.hpp>
24#include <rti/routing/processor/SampleIterator.hpp>
25
26namespace rti { namespace routing { namespace processor {
27
28template <typename T, typename U> class TypedInput;
29
30
77template <typename T, typename U = dds::sub::SampleInfo>
79public:
80
82 typedef typename std::vector<StreamReader::SamplePtr> SampleSeqType;
83 typedef typename std::vector<StreamReader::InfoPtr> InfoSeqType;
84
90 typedef typename SampleIterator<T, U>::value_type value_type;
91 typedef std::ptrdiff_t difference_type;
92
96 LoanedSamples() : input_(NULL)
97 {
98 native_samples_.data_array = NULL;
99 native_samples_.info_array = NULL;
100 native_samples_.length = 0;
101
102 }
103
104public:
105 // Private c-tor only to be used by static method create_from_loans()
107 RTI_RoutingServiceInput *native_input,
108 RTI_RoutingServiceLoanedSamples& native_samples)
109 : input_(native_input),
110 native_samples_(native_samples)
111 {
112 }
113
114public:
115
123 {
124 try {
125 return_loan();
126 } catch (const std::exception&) { // Do not throw in destructor
127
128 }
129 }
130
131
142 LoanedSample<T,U> operator [] (size_t index)
143 {
144 return native_samples_.info_array == NULL
145 ? LoanedSample<T, U>(native_samples_.data_array[index], NULL)
146 : LoanedSample<T, U>(
147 native_samples_.data_array[index],
148 native_samples_.info_array[index]);
149 }
150
154 int32_t length() const
155 {
156 return native_samples_.length;
157 }
158
182 {
183 if (input_) {
184 if (!RTI_RoutingServiceInput_return_loan(
185 input_,
186 &native_samples_)) {
187 throw dds::core::Error("error returning loaned samples to native input");
188 }
189 input_ = NULL; // Indicate that this object doesn't hold a loan anymore
190 }
191 }
192
193
199 {
200 return (native_samples_.info_array != NULL);
201 }
202
203
208 {
209 return iterator(
210 native_samples_.data_array,
211 native_samples_.info_array,
212 native_samples_.length);
213 }
214
219 {
220 return iterator(
221 native_samples_.data_array,
222 native_samples_.info_array,
223 native_samples_.length,
224 native_samples_.length);
225 }
226
231 {
232 return const_iterator(
233 native_samples_.data_array,
234 native_samples_.info_array,
235 native_samples_.length);
236 }
237
242 {
243 return const_iterator(
244 native_samples_.data_array,
245 native_samples_.info_array,
246 native_samples_.length,
247 native_samples_.length);
248 }
249
253 void swap(LoanedSamples& other) throw()
254 {
255 std::swap(input_, other.input_);
256 std::swap(native_samples_, other.native_samples_);
257 }
258
260 :input_(NULL)
261 {
262 native_samples_.data_array = NULL;
263 native_samples_.info_array = NULL;
264 native_samples_.length = 0;
265 other.swap(*this);
266 }
267
268
269 LoanedSamples& operator= (LoanedSamples&& other) throw ()
270 {
271 // clean up existing values
272 LoanedSamples temp(std::move(other));
273 temp.swap(*this);
274 return *this;
275 }
276
277private:
278 friend class TypedInput<T, U>;
279
280 void release()
281 {
282 input_ = NULL;
283 }
284
285 RTI_RoutingServiceLoanedSamples& native_samples()
286 {
287 return native_samples_;
288 }
289
290private:
291 // reference to the reader that created this LoanedSamples object
292 RTI_RoutingServiceInput *input_;
293 RTI_RoutingServiceLoanedSamples native_samples_;
294
295};
296
297template <typename T, typename U>
298LoanedSamples<T, U> move(LoanedSamples<T,U> & ls) OMG_NOEXCEPT
299{
300 return std::move(ls);
301}
302
303
304} } }
305
306#endif // RTI_ROUTING_PROCESSOR_LOANED_SAMPLES_HPP_
Provides a way to read samples of a specific type from a data domain. In the XML configuration file,...
Definition: StreamReader.hpp:45
Provides temporary access to a collection of samples (data and info) from a TypedInput.
Definition: LoanedSamples.hpp:78
SampleIterator< T, U > iterator
The iterator type.
Definition: LoanedSamples.hpp:88
int32_t length() const
Gets the number of samples in this collection.
Definition: LoanedSamples.hpp:154
const_iterator end() const
Gets an iterator to one past the last sample.
Definition: LoanedSamples.hpp:241
iterator end()
Gets an iterator to one past the last sample.
Definition: LoanedSamples.hpp:218
LoanedSample< T, U > operator[](size_t index)
Provides access to the underlying LoanedSample object in array-like syntax.
Definition: LoanedSamples.hpp:142
bool has_infos()
Returns whether the Info part is available for each Data item of this set of loaned samples.
Definition: LoanedSamples.hpp:198
const_iterator begin() const
Gets an iterator to the first sample.
Definition: LoanedSamples.hpp:230
void swap(LoanedSamples &other)
Swaps two LoanedSamples containers.
Definition: LoanedSamples.hpp:253
iterator begin()
Gets an iterator to the first sample.
Definition: LoanedSamples.hpp:207
LoanedSamples()
Creates an empty LoanedSamples object.
Definition: LoanedSamples.hpp:96
void return_loan()
Returns the samples to the TypedInput used to get these samples.
Definition: LoanedSamples.hpp:181
~LoanedSamples()
Automatically returns the loan to the TypedInput used to obtained these samples.
Definition: LoanedSamples.hpp:122
A random-access iterator of LoanedSample.
Definition: SampleIterator.hpp:44