11 #ifndef RTI_DDS_FLAT_SEQUENCEOFFSETS_HPP_ 12 #define RTI_DDS_FLAT_SEQUENCEOFFSETS_HPP_ 14 #include "rti/flat/Offset.hpp" 15 #include "rti/flat/SequenceIterator.hpp" 17 namespace rti {
namespace flat {
37 rti::flat::SampleBase *sample,
39 offset_t sequence_size)
46 bool is_cpp_compatible()
const 48 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
49 return sizeof(T) == 1 || !stream_.needs_byte_swap();
67 return reinterpret_cast<T*
>(this->
get_buffer());
75 const T * get_elements()
const 77 return reinterpret_cast<const T*
>(this->
get_buffer());
92 if (!stream_.check_size((i + 1) * ((
unsigned int)
sizeof(T)))) {
96 return OffsetBase::template deserialize<T>(i * (
unsigned int)
sizeof(T));
115 if (!stream_.check_size((i + 1) * static_cast<unsigned int>(
sizeof(T)))) {
119 return OffsetBase::serialize(i * static_cast<unsigned int>(
sizeof(T)), value);
123 template <
typename T>
124 struct PrimitiveSequenceOffsetHelper;
133 template <
typename T>
136 typedef variable_size_type_tag_t offset_kind;
137 typedef PrimitiveSequenceOffsetHelper<T> Helper;
144 rti::flat::SampleBase *sample,
146 offset_t serialized_size)
149 serialized_size >=
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)) ? sample : NULL,
150 offset +
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)),
151 serialized_size -
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)))
153 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 156 rti::xcdr::Stream::Memento stream_memento(this->stream_);
157 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
158 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
159 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 170 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
172 return element_count_;
176 unsigned int element_count_;
180 template <
typename T>
181 struct PrimitiveSequenceOffsetHelper {
182 static offset_t calculate_serialized_size(
183 rti::flat::SampleBase *sample,
184 offset_t absolute_offset,
187 RTI_FLAT_ASSERT(sample != NULL,
return 0);
188 RTI_FLAT_ASSERT(max_size >
sizeof(rti::xcdr::length_t),
return 0);
192 return (tmp.
element_count() *
sizeof(T)) +
sizeof(rti::xcdr::length_t);
207 template <
typename T,
unsigned int N>
210 typedef fixed_size_type_tag_t offset_kind;
235 static offset_t serialized_size(offset_t)
237 return sizeof(T) * N;
244 struct StringOffsetHelper;
253 typedef variable_size_type_tag_t offset_kind;
254 typedef StringOffsetHelper Helper;
262 offset_t absolute_offset,
263 offset_t serialized_size)
278 return reinterpret_cast<char*
>(this->get_buffer());
287 return reinterpret_cast<const char*
>(this->get_buffer());
303 struct StringOffsetHelper {
304 static offset_t calculate_serialized_size(
305 rti::flat::SampleBase *sample,
306 offset_t absolute_offset,
312 + (
unsigned int)
sizeof(rti::xcdr::length_t);
331 template <
typename ElementOffset>
347 rti::flat::SampleBase *sample,
349 offset_t sequence_size)
358 bool is_cpp_compatible()
const 360 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
361 return !stream_.needs_byte_swap()
362 && rti::xcdr::has_cpp_friendly_cdr_layout_collection<
368 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
370 return get_element_impl<ElementOffset>(
372 typename ElementOffset::offset_kind());
389 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
402 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
412 template <
typename E>
413 E get_element_impl(
unsigned int i, variable_size_type_tag_t)
416 while (it != end() && i > 0) {
427 template <
typename E>
428 E get_element_impl(
unsigned int i, fixed_size_type_tag_t)
430 offset_t size = i * E::serialized_size_w_padding();
433 if (!stream_.check_size(size + E::serialized_size(0))) {
437 return E(this->sample_, this->absolute_offset_ + size);
441 template <
typename ElementOffset>
442 struct SequenceOffsetHelper;
458 template <
typename ElementOffset>
461 typedef variable_size_type_tag_t offset_kind;
462 typedef SequenceOffsetHelper<ElementOffset> Helper;
469 rti::flat::SampleBase *sample,
471 offset_t sequence_size)
474 sequence_size >=
sizeof(rti::xcdr::length_t) ? sample: NULL,
479 RTIXCdrAlignment_alignSizeUp(offset, RTI_XCDR_SEQ_LENGTH_ALIGNMENT)
480 +
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)),
481 sequence_size -
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)))
483 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 486 rti::xcdr::Stream::Memento stream_memento(this->stream_);
487 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
488 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
489 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 502 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
504 if (i >= element_count_) {
505 return ElementOffset();
515 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
517 return element_count_;
521 unsigned int element_count_;
524 template <
typename E>
525 struct SequenceOffsetHelper {
527 static offset_t calculate_serialized_size(
528 rti::flat::SampleBase *sample,
529 offset_t absolute_offset,
538 max_offset - absolute_offset);
541 for (
unsigned int i = 0; i < count; i++) {
547 return detail::ptrdiff(it.get_position(), sample->get_buffer())
566 template <
typename ElementOffset,
unsigned int N>
569 typedef variable_size_type_tag_t offset_kind;
576 rti::flat::SampleBase *sample,
578 offset_t sequence_size)
595 return ElementOffset();
621 template <
typename ElementOffset,
unsigned int N>
624 typedef fixed_size_type_tag_t offset_kind;
633 rti::flat::SampleBase *sample,
634 offset_t absolute_offset,
635 offset_t first_element_size,
636 offset_t element_size)
640 first_element_size + element_size * (N - 1)),
641 first_element_size_(first_element_size),
642 element_size_(element_size)
654 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
657 return ElementOffset();
660 offset_t element_offset = this->absolute_offset_;
662 element_offset += this->first_element_size_
663 + (i - 1) * this->element_size_;
666 return ElementOffset(this->sample_, element_offset);
670 offset_t first_element_size_;
671 offset_t element_size_;
714 template <
typename ElementOffset,
unsigned int N>
717 typedef fixed_size_type_tag_t offset_kind;
726 rti::flat::SampleBase *sample,
727 offset_t absolute_offset)
737 static offset_t serialized_size(offset_t)
740 return ElementOffset::serialized_size_w_padding() * (N - 1)
741 + ElementOffset::serialized_size(0);
755 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
758 return ElementOffset();
767 #endif // RTI_DDS_FLAT_SEQUENCEOFFSETS_HPP_ unsigned int element_count() const
Returns the number of characters.
Definition: SequenceOffsets.hpp:295
Base class of Offsets to sequences and arrays of non-primitive members.
Definition: SequenceOffsets.hpp:332
unsigned int element_count() const
Returns the number of elements, N.
Definition: SequenceOffsets.hpp:230
SequenceIterator< ElementOffset, typename ElementOffset::offset_kind > iterator
The iterator type, SequenceIterator.
Definition: SequenceOffsets.hpp:339
Offset to a sequence of primitive elements.
Definition: SequenceOffsets.hpp:134
const unsigned char * get_buffer() const
Gets this member's position in the buffer.
Definition: Offset.hpp:554
Given a Sample, an Offset or a Builder, it allows obtaining the other types.
Definition: FlatSample.hpp:340
Offset to an array of primitive elements.
Definition: SequenceOffsets.hpp:208
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:567
Base class of all Offset types.
Definition: Offset.hpp:489
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:753
T get_element(unsigned int i) const
Returns an element by index.
Definition: SequenceOffsets.hpp:88
iterator begin()
Gets an iterator to the first Offset.
Definition: SequenceOffsets.hpp:387
bool set_element(unsigned int i, T value)
Sets an element by index.
Definition: SequenceOffsets.hpp:111
char * get_string()
Gets the string.
Definition: SequenceOffsets.hpp:276
Offset to a string.
Definition: SequenceOffsets.hpp:251
Offset to an array of final elements.
Definition: Offset.hpp:481
bool advance()
Advances to the next element, reporting any errors by returning false.
Definition: SequenceIterator.hpp:132
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:715
bool is_null() const
Indicates whether this Offset doesn't point to a valid element.
Definition: Offset.hpp:509
const char * get_string() const
Gets the string (const)
Definition: SequenceOffsets.hpp:285
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:500
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:592
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:568
Definition: AggregationBuilders.hpp:17
Base class for Offsets to sequences and arrays of primitive types.
Definition: SequenceOffsets.hpp:27
Iterator for collections of Offsets.
Definition: SequenceIterator.hpp:44
Offset to a sequence of non-primitive elements.
Definition: SequenceOffsets.hpp:459
unsigned int element_count() const
Returns the number of elements.
Definition: SequenceOffsets.hpp:168
unsigned int element_count() const
The number of elements.
Definition: SequenceOffsets.hpp:513
iterator end()
Gets an iterator to the past-the-end element.
Definition: SequenceOffsets.hpp:400
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:652