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"
17namespace 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);
126struct PrimitiveSequenceOffsetHelper;
128template <
typename T,
typename Enable =
void>
129struct primitive_sequence_header_length {
130 static size_t value()
132 return sizeof(rti::xcdr::length_t);
148 typedef variable_size_type_tag_t offset_kind;
149 typedef detail::PrimitiveSequenceOffsetHelper<T> Helper;
156 rti::flat::SampleBase *sample,
158 offset_t serialized_size)
161 serialized_size >=
static_cast<offset_t
>(header_length()) ? sample : NULL,
162 offset +
static_cast<offset_t
>(header_length()),
163 serialized_size -
static_cast<offset_t
>(header_length())),
166#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
169 rti::xcdr::Stream::Memento stream_memento(this->stream_);
170 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
171 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
172#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
183 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
185 return element_count_;
189 static size_t header_length()
191 return detail::primitive_sequence_header_length<T>::value();
194 unsigned int element_count_;
201struct PrimitiveSequenceOffsetHelper {
202 static offset_t calculate_serialized_size(
203 rti::flat::SampleBase *sample,
204 offset_t absolute_offset,
207 RTI_FLAT_ASSERT(sample != NULL,
return 0);
208 RTI_FLAT_ASSERT(max_size >
sizeof(rti::xcdr::length_t),
return 0);
210 PrimitiveSequenceOffset<T> tmp(sample, absolute_offset, max_size);
213 if ((RTIXCdrUnsignedLong_MAX
214 -
static_cast<unsigned int>(
sizeof(rti::xcdr::length_t)))
215 /
static_cast<unsigned int>(
sizeof(T))
216 < tmp.element_count()) {
217 RTI_FLAT_OFFSET_PRECONDITION_ERROR(
218 "Serialized size of a sequence of primitive elements "
219 "exceeds maximum representable 32-bit unsigned integer.",
222 return (tmp.element_count() *
static_cast<unsigned int>(
sizeof(T)))
223 +
static_cast<unsigned int>(
sizeof(rti::xcdr::length_t));
240template <
typename T,
unsigned int N>
243 typedef fixed_size_type_tag_t offset_kind;
252 offset +
static_cast<offset_t
>(header_length()),
268 static offset_t serialized_size(offset_t)
270 return sizeof(T) * N;
274 static size_t header_length()
276 return detail::primitive_sequence_header_length<T>::value()
277 -
sizeof(rti::xcdr::length_t);
284struct StringOffsetHelper;
293 typedef variable_size_type_tag_t offset_kind;
294 typedef StringOffsetHelper Helper;
302 offset_t absolute_offset,
303 offset_t serialized_size)
318 return reinterpret_cast<char*
>(this->
get_buffer());
327 return reinterpret_cast<const char*
>(this->
get_buffer());
337 RTI_FLAT_CHECK_PRECONDITION(
345struct StringOffsetHelper {
346 static offset_t calculate_serialized_size(
347 rti::flat::SampleBase *sample,
348 offset_t absolute_offset,
351 StringOffset tmp(sample, absolute_offset, max_size);
352 return tmp.element_count()
354 + (
unsigned int)
sizeof(rti::xcdr::length_t);
359typedef PrimitiveSequenceOffset<unsigned char> WStringOffset;
373template <
typename ElementOffset>
389 rti::flat::SampleBase *sample,
391 offset_t sequence_size)
400 bool is_cpp_compatible() const
402 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
403 return !stream_.needs_byte_swap()
404 && rti::xcdr::has_cpp_friendly_cdr_layout_collection<
408 ElementOffset get_element(
unsigned int i)
410 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
412 return get_element_impl<ElementOffset>(
414 typename ElementOffset::offset_kind());
431 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
444 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
454 template <
typename E>
455 E get_element_impl(
unsigned int i, variable_size_type_tag_t)
458 while (it !=
end() && i > 0) {
469 template <
typename E>
470 E get_element_impl(
unsigned int i, fixed_size_type_tag_t)
472 offset_t size = i * E::serialized_size_w_padding();
475 if (!stream_.check_size(size + E::serialized_size(0))) {
479 return E(this->sample_, this->absolute_offset_ + size);
483template <
typename ElementOffset>
484struct SequenceOffsetHelper;
500template <
typename ElementOffset>
503 typedef variable_size_type_tag_t offset_kind;
504 typedef SequenceOffsetHelper<ElementOffset> Helper;
511 rti::flat::SampleBase *sample,
513 offset_t sequence_size)
517 sequence_size >= header_length() ? sample : NULL,
522 RTIXCdrAlignment_alignSizeUp(
524 RTI_XCDR_SEQ_LENGTH_ALIGNMENT)
526 sequence_size - header_length()),
529#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
532 rti::xcdr::Stream::Memento stream_memento(this->stream_);
533 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
534 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
535#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
548 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
550 if (i >= element_count_) {
551 return ElementOffset();
561 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
563 return element_count_;
567 static offset_t header_length()
569 return static_cast<offset_t
>(
570 detail::collection_dheader_traits<false>::dheader_size()
571 +
sizeof(rti::xcdr::length_t));
575 unsigned int element_count_;
579struct SequenceOffsetHelper {
581 static offset_t calculate_serialized_size(
582 rti::flat::SampleBase *sample,
583 offset_t absolute_offset,
589 SequenceOffset<E> tmp(
592 max_offset - absolute_offset);
593 unsigned int count = tmp.element_count();
595 for (
unsigned int i = 0; i < count; i++) {
601 return detail::ptrdiff(it.get_position(), sample->get_buffer())
620template <
typename ElementOffset,
unsigned int N>
623 typedef variable_size_type_tag_t offset_kind;
630 rti::flat::SampleBase *sample,
632 offset_t sequence_size)
634 sequence_size >= header_length() ? sample : NULL,
635 offset + header_length(),
636 sequence_size - header_length())
649 return ElementOffset();
656 static offset_t header_length()
658 return static_cast<offset_t
>(
659 detail::collection_dheader_traits<false>::dheader_size());
682template <
typename ElementOffset,
unsigned int N>
685 typedef fixed_size_type_tag_t offset_kind;
694 rti::flat::SampleBase *sample,
695 offset_t absolute_offset,
696 offset_t first_element_size,
697 offset_t element_size)
701 first_element_size + element_size * (N - 1)),
702 first_element_size_(first_element_size),
703 element_size_(element_size)
715 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
718 return ElementOffset();
721 offset_t element_offset = this->absolute_offset_;
723 element_offset += this->first_element_size_
724 + (i - 1) * this->element_size_;
727 return ElementOffset(this->sample_, element_offset);
731 offset_t first_element_size_;
732 offset_t element_size_;
775template <
typename ElementOffset,
unsigned int N>
778 typedef fixed_size_type_tag_t offset_kind;
787 rti::flat::SampleBase *sample,
788 offset_t absolute_offset)
792 + detail::collection_dheader_traits<
793 false>::dheader_size(),
799 static offset_t serialized_size(offset_t)
802 return ElementOffset::serialized_size_w_padding() * (N - 1)
803 + ElementOffset::serialized_size(0);
817 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
820 return ElementOffset();
830template <
typename T,
unsigned int N>
831struct is_fixed_type_w_dheader<FinalAlignedArrayOffset<T, N> > {
834 return is_dheader_required_in_non_primitive_collections();
Base class of Offsets to sequences and arrays of non-primitive members.
Definition: SequenceOffsets.hpp:374
iterator end()
Gets an iterator to the past-the-end element.
Definition: SequenceOffsets.hpp:442
iterator begin()
Gets an iterator to the first Offset.
Definition: SequenceOffsets.hpp:429
SequenceIterator< ElementOffset, typename ElementOffset::offset_kind > iterator
The iterator type, SequenceIterator.
Definition: SequenceOffsets.hpp:381
Base class for Offsets to sequences and arrays of primitive types.
Definition: SequenceOffsets.hpp:27
bool set_element(unsigned int i, T value)
Sets an element by index.
Definition: SequenceOffsets.hpp:111
T get_element(unsigned int i) const
Returns an element by index.
Definition: SequenceOffsets.hpp:88
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:776
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:815
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:683
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:713
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:621
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:646
Base class of all Offset types.
Definition: Offset.hpp:562
bool is_null() const
Indicates whether this Offset doesn't point to a valid element.
Definition: Offset.hpp:582
const unsigned char * get_buffer() const
Gets this member's position in the buffer.
Definition: Offset.hpp:627
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:641
Offset to an array of primitive elements.
Definition: SequenceOffsets.hpp:241
unsigned int element_count() const
Returns the number of elements, N.
Definition: SequenceOffsets.hpp:263
Offset to a sequence of primitive elements.
Definition: SequenceOffsets.hpp:146
unsigned int element_count() const
Returns the number of elements.
Definition: SequenceOffsets.hpp:181
Iterator for collections of Offsets.
Definition: SequenceIterator.hpp:44
Offset to a sequence of non-primitive elements.
Definition: SequenceOffsets.hpp:501
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:546
unsigned int element_count() const
The number of elements.
Definition: SequenceOffsets.hpp:559
Offset to a string.
Definition: SequenceOffsets.hpp:291
char * get_string()
Gets the string.
Definition: SequenceOffsets.hpp:316
unsigned int element_count() const
Returns the number of characters.
Definition: SequenceOffsets.hpp:335
const char * get_string() const
Gets the string (const)
Definition: SequenceOffsets.hpp:325
The RTI namespace.
Definition: AggregationBuilders.hpp:17
Given a Sample, an Offset or a Builder, it allows obtaining the other types.
Definition: FlatSample.hpp:340