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);
124struct PrimitiveSequenceOffsetHelper;
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))),
154#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
157 rti::xcdr::Stream::Memento stream_memento(this->stream_);
158 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
159 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
160#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
171 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
173 return element_count_;
177 unsigned int element_count_;
182struct PrimitiveSequenceOffsetHelper {
183 static offset_t calculate_serialized_size(
184 rti::flat::SampleBase *sample,
185 offset_t absolute_offset,
188 RTI_FLAT_ASSERT(sample != NULL,
return 0);
189 RTI_FLAT_ASSERT(max_size >
sizeof(rti::xcdr::length_t),
return 0);
191 PrimitiveSequenceOffset<T> tmp(sample, absolute_offset, max_size);
194 if ((RTIXCdrUnsignedLong_MAX
195 -
static_cast<unsigned int>(
sizeof(rti::xcdr::length_t)))
196 /
static_cast<unsigned int>(
sizeof(T))
197 < tmp.element_count()) {
198 RTI_FLAT_OFFSET_PRECONDITION_ERROR(
199 "Serialized size of a sequence of primitive elements "
200 "exceeds maximum representable 32-bit unsigned integer.",
203 return (tmp.element_count() *
static_cast<unsigned int>(
sizeof(T)))
204 +
static_cast<unsigned int>(
sizeof(rti::xcdr::length_t));
219template <
typename T,
unsigned int N>
222 typedef fixed_size_type_tag_t offset_kind;
247 static offset_t serialized_size(offset_t)
249 return sizeof(T) * N;
256struct StringOffsetHelper;
265 typedef variable_size_type_tag_t offset_kind;
266 typedef StringOffsetHelper Helper;
274 offset_t absolute_offset,
275 offset_t serialized_size)
290 return reinterpret_cast<char*
>(this->
get_buffer());
299 return reinterpret_cast<const char*
>(this->
get_buffer());
309 RTI_FLAT_CHECK_PRECONDITION(
317struct StringOffsetHelper {
318 static offset_t calculate_serialized_size(
319 rti::flat::SampleBase *sample,
320 offset_t absolute_offset,
323 StringOffset tmp(sample, absolute_offset, max_size);
324 return tmp.element_count()
326 + (
unsigned int)
sizeof(rti::xcdr::length_t);
331typedef PrimitiveSequenceOffset<unsigned char> WStringOffset;
345template <
typename ElementOffset>
361 rti::flat::SampleBase *sample,
363 offset_t sequence_size)
372 bool is_cpp_compatible() const
374 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
375 return !stream_.needs_byte_swap()
376 && rti::xcdr::has_cpp_friendly_cdr_layout_collection<
380 ElementOffset get_element(
unsigned int i)
382 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
384 return get_element_impl<ElementOffset>(
386 typename ElementOffset::offset_kind());
403 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
416 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
426 template <
typename E>
427 E get_element_impl(
unsigned int i, variable_size_type_tag_t)
430 while (it !=
end() && i > 0) {
441 template <
typename E>
442 E get_element_impl(
unsigned int i, fixed_size_type_tag_t)
444 offset_t size = i * E::serialized_size_w_padding();
447 if (!stream_.check_size(size + E::serialized_size(0))) {
451 return E(this->sample_, this->absolute_offset_ + size);
455template <
typename ElementOffset>
456struct SequenceOffsetHelper;
472template <
typename ElementOffset>
475 typedef variable_size_type_tag_t offset_kind;
476 typedef SequenceOffsetHelper<ElementOffset> Helper;
483 rti::flat::SampleBase *sample,
485 offset_t sequence_size)
488 sequence_size >=
sizeof(rti::xcdr::length_t) ? sample: NULL,
493 RTIXCdrAlignment_alignSizeUp(offset, RTI_XCDR_SEQ_LENGTH_ALIGNMENT)
494 +
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)),
495 sequence_size -
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t))),
498#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
501 rti::xcdr::Stream::Memento stream_memento(this->stream_);
502 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
503 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
504#ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
517 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
519 if (i >= element_count_) {
520 return ElementOffset();
530 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
532 return element_count_;
536 unsigned int element_count_;
540struct SequenceOffsetHelper {
542 static offset_t calculate_serialized_size(
543 rti::flat::SampleBase *sample,
544 offset_t absolute_offset,
550 SequenceOffset<E> tmp(
553 max_offset - absolute_offset);
554 unsigned int count = tmp.element_count();
556 for (
unsigned int i = 0; i < count; i++) {
562 return detail::ptrdiff(it.get_position(), sample->get_buffer())
581template <
typename ElementOffset,
unsigned int N>
584 typedef variable_size_type_tag_t offset_kind;
591 rti::flat::SampleBase *sample,
593 offset_t sequence_size)
610 return ElementOffset();
636template <
typename ElementOffset,
unsigned int N>
639 typedef fixed_size_type_tag_t offset_kind;
648 rti::flat::SampleBase *sample,
649 offset_t absolute_offset,
650 offset_t first_element_size,
651 offset_t element_size)
655 first_element_size + element_size * (N - 1)),
656 first_element_size_(first_element_size),
657 element_size_(element_size)
669 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
672 return ElementOffset();
675 offset_t element_offset = this->absolute_offset_;
677 element_offset += this->first_element_size_
678 + (i - 1) * this->element_size_;
681 return ElementOffset(this->sample_, element_offset);
685 offset_t first_element_size_;
686 offset_t element_size_;
729template <
typename ElementOffset,
unsigned int N>
732 typedef fixed_size_type_tag_t offset_kind;
741 rti::flat::SampleBase *sample,
742 offset_t absolute_offset)
752 static offset_t serialized_size(offset_t)
755 return ElementOffset::serialized_size_w_padding() * (N - 1)
756 + ElementOffset::serialized_size(0);
770 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
773 return ElementOffset();
Base class of Offsets to sequences and arrays of non-primitive members.
Definition: SequenceOffsets.hpp:346
iterator end()
Gets an iterator to the past-the-end element.
Definition: SequenceOffsets.hpp:414
iterator begin()
Gets an iterator to the first Offset.
Definition: SequenceOffsets.hpp:401
SequenceIterator< ElementOffset, typename ElementOffset::offset_kind > iterator
The iterator type, SequenceIterator.
Definition: SequenceOffsets.hpp:353
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:730
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:768
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:637
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:667
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:582
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:607
Base class of all Offset types.
Definition: Offset.hpp:489
bool is_null() const
Indicates whether this Offset doesn't point to a valid element.
Definition: Offset.hpp:509
const unsigned char * get_buffer() const
Gets this member's position in the buffer.
Definition: Offset.hpp:554
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:568
Offset to an array of primitive elements.
Definition: SequenceOffsets.hpp:220
unsigned int element_count() const
Returns the number of elements, N.
Definition: SequenceOffsets.hpp:242
Offset to a sequence of primitive elements.
Definition: SequenceOffsets.hpp:134
unsigned int element_count() const
Returns the number of elements.
Definition: SequenceOffsets.hpp:169
Iterator for collections of Offsets.
Definition: SequenceIterator.hpp:44
Offset to a sequence of non-primitive elements.
Definition: SequenceOffsets.hpp:473
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:515
unsigned int element_count() const
The number of elements.
Definition: SequenceOffsets.hpp:528
Offset to a string.
Definition: SequenceOffsets.hpp:263
char * get_string()
Gets the string.
Definition: SequenceOffsets.hpp:288
unsigned int element_count() const
Returns the number of characters.
Definition: SequenceOffsets.hpp:307
const char * get_string() const
Gets the string (const)
Definition: SequenceOffsets.hpp:297
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