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))),
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_;
181 template <
typename T>
182 struct 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);
194 if ((RTIXCdrUnsignedLong_MAX
195 - static_cast<unsigned int>(
sizeof(rti::xcdr::length_t)))
196 / static_cast<unsigned int>(
sizeof(T))
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));
219 template <
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;
256 struct 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());
315 struct StringOffsetHelper {
316 static offset_t calculate_serialized_size(
317 rti::flat::SampleBase *sample,
318 offset_t absolute_offset,
324 + (
unsigned int)
sizeof(rti::xcdr::length_t);
343 template <
typename ElementOffset>
359 rti::flat::SampleBase *sample,
361 offset_t sequence_size)
370 bool is_cpp_compatible()
const 372 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
373 return !stream_.needs_byte_swap()
374 && rti::xcdr::has_cpp_friendly_cdr_layout_collection<
380 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
382 return get_element_impl<ElementOffset>(
384 typename ElementOffset::offset_kind());
401 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
414 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return iterator(NULL, 0, 0));
424 template <
typename E>
425 E get_element_impl(
unsigned int i, variable_size_type_tag_t)
428 while (it != end() && i > 0) {
439 template <
typename E>
440 E get_element_impl(
unsigned int i, fixed_size_type_tag_t)
442 offset_t size = i * E::serialized_size_w_padding();
445 if (!stream_.check_size(size + E::serialized_size(0))) {
449 return E(this->sample_, this->absolute_offset_ + size);
453 template <
typename ElementOffset>
454 struct SequenceOffsetHelper;
470 template <
typename ElementOffset>
473 typedef variable_size_type_tag_t offset_kind;
474 typedef SequenceOffsetHelper<ElementOffset> Helper;
481 rti::flat::SampleBase *sample,
483 offset_t sequence_size)
486 sequence_size >=
sizeof(rti::xcdr::length_t) ? sample: NULL,
491 RTIXCdrAlignment_alignSizeUp(offset, RTI_XCDR_SEQ_LENGTH_ALIGNMENT)
492 +
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t)),
493 sequence_size -
static_cast<offset_t
>(
sizeof(rti::xcdr::length_t))),
496 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 499 rti::xcdr::Stream::Memento stream_memento(this->stream_);
500 this->stream_.skip_back(
sizeof(rti::xcdr::length_t));
501 element_count_ = this->stream_.template deserialize_fast<rti::xcdr::length_t>();
502 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS 515 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
517 if (i >= element_count_) {
518 return ElementOffset();
528 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
530 return element_count_;
534 unsigned int element_count_;
537 template <
typename E>
538 struct SequenceOffsetHelper {
540 static offset_t calculate_serialized_size(
541 rti::flat::SampleBase *sample,
542 offset_t absolute_offset,
551 max_offset - absolute_offset);
554 for (
unsigned int i = 0; i < count; i++) {
560 return detail::ptrdiff(it.get_position(), sample->get_buffer())
579 template <
typename ElementOffset,
unsigned int N>
582 typedef variable_size_type_tag_t offset_kind;
589 rti::flat::SampleBase *sample,
591 offset_t sequence_size)
608 return ElementOffset();
634 template <
typename ElementOffset,
unsigned int N>
637 typedef fixed_size_type_tag_t offset_kind;
646 rti::flat::SampleBase *sample,
647 offset_t absolute_offset,
648 offset_t first_element_size,
649 offset_t element_size)
653 first_element_size + element_size * (N - 1)),
654 first_element_size_(first_element_size),
655 element_size_(element_size)
667 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
670 return ElementOffset();
673 offset_t element_offset = this->absolute_offset_;
675 element_offset += this->first_element_size_
676 + (i - 1) * this->element_size_;
679 return ElementOffset(this->sample_, element_offset);
683 offset_t first_element_size_;
684 offset_t element_size_;
727 template <
typename ElementOffset,
unsigned int N>
730 typedef fixed_size_type_tag_t offset_kind;
739 rti::flat::SampleBase *sample,
740 offset_t absolute_offset)
750 static offset_t serialized_size(offset_t)
753 return ElementOffset::serialized_size_w_padding() * (N - 1)
754 + ElementOffset::serialized_size(0);
768 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ElementOffset());
771 return ElementOffset();
780 #endif // RTI_DDS_FLAT_SEQUENCEOFFSETS_HPP_ unsigned int element_count() const
Returns the number of characters.
Definition: SequenceOffsets.hpp:307
Base class of Offsets to sequences and arrays of non-primitive members.
Definition: SequenceOffsets.hpp:344
unsigned int element_count() const
Returns the number of elements, N.
Definition: SequenceOffsets.hpp:242
SequenceIterator< ElementOffset, typename ElementOffset::offset_kind > iterator
The iterator type, SequenceIterator.
Definition: SequenceOffsets.hpp:351
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:220
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:580
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:766
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:399
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:288
Offset to a string.
Definition: SequenceOffsets.hpp:263
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:728
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:297
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:513
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:605
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:471
unsigned int element_count() const
Returns the number of elements.
Definition: SequenceOffsets.hpp:169
unsigned int element_count() const
The number of elements.
Definition: SequenceOffsets.hpp:526
iterator end()
Gets an iterator to the past-the-end element.
Definition: SequenceOffsets.hpp:412
ElementOffset get_element(unsigned int i)
Gets the Offset to an element.
Definition: SequenceOffsets.hpp:665