11#ifndef RTI_DDS_FLAT_FLATOFFSETS_HPP_
12#define RTI_DDS_FLAT_FLATOFFSETS_HPP_
14#include "xcdr/xcdr_stream.h"
15#include "xcdr/xcdr_stream_impl.h"
16#include "xcdr/xcdr_interpreter.h"
18#include "rti/xcdr/Stream.hpp"
108#ifdef DOXYGEN_DOCUMENTATION_ONLY
466namespace rti {
namespace flat {
470inline rti::flat::offset_t ptrdiff(
unsigned char *a,
unsigned char *b)
472 RTI_FLAT_ASSERT(a - b < RTI_XCDR_MAX_SERIALIZED_SIZE,
return 0);
474 return static_cast<rti::flat::offset_t
>(a - b);
480template <
typename OffsetType,
typename Enable =
void>
481struct is_fixed_type_w_dheader {
488inline bool is_dheader_required_in_non_primitive_collections()
492#if defined(RTI_FLATDATA_NO_DHEADER_COLLECTIONS)
494#elif defined(RTI_FLATDATA_DHEADER_COLLECTIONS)
498 RTIXCdrXTypesComplianceMask xTypesComplianceMask;
499 xTypesComplianceMask = RTIXCdrInterpreter_getGlobalXtypeComplianceMask();
500 return RTIXCdrXTypesComplianceMask_isBitSet(
501 xTypesComplianceMask,
502 RTI_XCDR_XTYPES_DHEADER_IN_NON_PRIMITIVE_COLLECTIONS_BIT);
506inline bool is_dheader_required_in_enum_collections()
508#if defined(RTI_FLATDATA_NO_DHEADER_COLLECTIONS)
510#elif defined(RTI_FLATDATA_DHEADER_COLLECTIONS)
513 RTIXCdrXTypesComplianceMask xTypesComplianceMask;
514 xTypesComplianceMask = RTIXCdrInterpreter_getGlobalXtypeComplianceMask();
515 return RTIXCdrXTypesComplianceMask_isBitSet(
516 xTypesComplianceMask,
517 RTI_XCDR_XTYPES_DHEADER_IN_NON_PRIMITIVE_COLLECTIONS_BIT)
518 && !RTIXCdrXTypesComplianceMask_isBitSet(
519 xTypesComplianceMask,
520 RTI_XCDR_XTYPES_ENUM_AS_PRIMITIVE_IN_COLLECTIONS_BIT);
524template <
bool IsForEnum>
525struct collection_dheader_traits {
526 static bool dheader_required()
528 return is_dheader_required_in_non_primitive_collections();
531 static unsigned int dheader_size()
533 return dheader_required() ? RTI_XCDR_DHEADER_SIZE : 0;
538struct collection_dheader_traits<true> {
539 static bool dheader_required()
541 return is_dheader_required_in_enum_collections();
544 static unsigned int dheader_size()
546 return dheader_required() ? RTI_XCDR_DHEADER_SIZE : 0;
553template <
typename T,
unsigned int N>
554class FinalArrayOffset;
584 return sample_ == NULL;
607 unsigned char * get_buffer()
612 return stream_.current_position();
632 return stream_.current_position();
643 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
644 return stream_.total_size();
655 return s1.get_buffer() < s2.get_buffer();
666 return s1.get_buffer() > s2.get_buffer();
677 return s1.get_buffer() <= s2.get_buffer();
688 return s1.get_buffer() >= s2.get_buffer();
699 return s1.get_buffer() == s2.get_buffer();
723 offset_t absolute_offset,
724 offset_t serialized_size)
726 absolute_offset_(absolute_offset)
731 RTI_FLAT_CHECK_PRECONDITION(sample != NULL,
return);
733 sample_->initialize_stream(
740 template <
typename U>
741 U deserialize(offset_t member_offset)
const
743 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
744 RTI_FLAT_ASSERT(stream_.check_size(member_offset +
static_cast<offset_t
>(
sizeof(U))),
return U());
746 rti::xcdr::Stream::Memento stream_memento(stream_);
747 stream_.skip_fast(member_offset);
748 return stream_.deserialize_fast<U>();
752 template <
typename U>
753 bool serialize(offset_t member_offset, U value)
755 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
756 RTI_FLAT_ASSERT(stream_.check_size(member_offset +
static_cast<offset_t
>(
sizeof(U))),
return false);
758 rti::xcdr::Stream::Memento stream_memento(stream_);
760 stream_.skip_fast(member_offset);
761 stream_.serialize_fast<U>(value);
768 template <
typename U>
769 U get_member(offset_t relative_member_offset)
771 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
776 absolute_offset_ + relative_member_offset);
779 template <
typename U>
780 U get_member(offset_t relative_member_offset)
const
782 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
787 absolute_offset_ + relative_member_offset);
793 offset_t absolute_offset_;
794 mutable rti::xcdr::Stream stream_;
807 typedef fixed_size_type_tag_t offset_kind;
809 static offset_t serialized_size_w_padding()
811 RTI_FLAT_ASSERT(T::serialized_size(0) > 0,
return 0);
812 RTI_FLAT_ASSERT(T::required_alignment > 0,
return 0);
814 const offset_t element_size = T::serialized_size(0);
815 if (element_size % T::required_alignment != 0) {
816 return element_size + T::required_alignment
817 - element_size % T::required_alignment;
823 bool is_cpp_compatible()
const
825 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
826 return !stream_.needs_byte_swap()
827 && rti::xcdr::has_cpp_friendly_cdr_layout<
841 FinalOffset(SampleBase *sample, offset_t absolute_offset)
845 T::serialized_size(absolute_offset))
852 template <
typename U>
853 U deserialize(
const offset_t *relative_member_offsets)
const
855 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
867 return OffsetBase::deserialize<U>(
869 get_value_for_alignment(relative_member_offsets));
873 template <
typename U>
874 bool serialize(
const offset_t *relative_member_offsets, U value)
876 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return false);
878 return OffsetBase::serialize<U>(
880 get_value_for_alignment(relative_member_offsets), value);
887 template <
typename U>
888 U get_member(
const offset_t *relative_member_offsets)
890 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
892 return OffsetBase::get_member<U>(
893 get_value_for_alignment(relative_member_offsets));
896 template <
typename U>
897 U get_member(
const offset_t *relative_member_offsets)
const
899 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
901 return OffsetBase::get_member<U>(
902 get_value_for_alignment(relative_member_offsets));
906 template <
typename U,
unsigned int N>
908 const offset_t *relative_member_offsets,
909 const offset_t *first_element_sizes,
910 offset_t element_size)
914 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return ArrayType());
915 RTI_FLAT_ASSERT(first_element_sizes != NULL,
return ArrayType());
917 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ArrayType());
922 absolute_offset_ + get_value_for_alignment(relative_member_offsets),
924 get_value_for_alignment(first_element_sizes),
929 template <
typename U,
unsigned int N>
931 const offset_t *relative_member_offsets,
932 const offset_t *first_element_sizes,
933 offset_t element_size)
const
937 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return ArrayType());
938 RTI_FLAT_ASSERT(first_element_sizes != NULL,
return ArrayType());
940 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ArrayType());
944 absolute_offset_ + get_value_for_alignment(relative_member_offsets),
946 get_value_for_alignment(first_element_sizes),
957 offset_t get_value_for_alignment(
const offset_t *values_per_alignment)
const
959 return values_per_alignment
960 [absolute_offset_ % RTI_XCDR_MAX_XCDR2_ALIGNMENT];
964struct MutableOffsetHelper {
967 static offset_t calculate_serialized_size(
968 rti::flat::SampleBase *sample,
969 offset_t absolute_offset,
972 RTI_FLAT_ASSERT(sample != NULL,
return 0);
974 return RTIXCdrFlatSample_getMutableSampleSize(
975 sample->get_buffer(),
989 typedef variable_size_type_tag_t offset_kind;
990 typedef MutableOffsetHelper Helper;
999 offset_t absolute_offset,
1000 offset_t serialized_size)
1008 template <
typename U>
1009 U deserialize(member_id_t member_id, U default_val = U())
const
1011 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
1013 rti::xcdr::Stream::Memento stream_memento(stream_);
1015 offset_t member_size = 0;
1016 if (!RTIXCdrStream_findV2MutableSampleMember(
1017 &stream_.c_stream(),
1023 return stream_.deserialize_fast<U>();
1027 template <
typename U>
1028 bool serialize(member_id_t member_id, U value)
1030 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1032 rti::xcdr::Stream::Memento stream_memento(stream_);
1034 offset_t member_size = 0;
1035 if (!RTIXCdrStream_findV2MutableSampleMember(
1036 &stream_.c_stream(),
1042 stream_.serialize_fast<U>(value);
1046 template <
typename U>
1047 U get_member(member_id_t member_id)
const
1049 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
1051 rti::xcdr::Stream::Memento stream_memento(stream_);
1053 offset_t member_size = 0;
1054 if (!RTIXCdrStream_findV2MutableSampleMember(
1055 &stream_.c_stream(),
1061 return get_member_impl<U>(
1063 detail::ptrdiff(stream_.current_position(), sample_->get_buffer()),
1065 typename U::offset_kind());
1069 template <
typename U>
1071 offset_t absolute_member_offset,
1072 offset_t member_size,
1073 variable_size_type_tag_t)
const
1075 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1078 return U(sample_, absolute_member_offset, member_size);
1081 template <
typename U>
1083 offset_t absolute_member_offset,
1084 offset_t member_size,
1085 fixed_size_type_tag_t)
const
1088 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1091 return U(sample_, absolute_member_offset);
1103template <
typename T>
1106 typedef fixed_size_type_tag_t offset_kind;
1114 offset_t absolute_offset)
1122 bool is_cpp_compatible()
const
1124 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1125 return sizeof(T) == 1 || !stream_.needs_byte_swap();
1135 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return T());
1136 RTI_FLAT_ASSERT(stream_.check_size(
sizeof(T)),
return T());
1138 return stream_.deserialize_fast<T>();
1141 static offset_t serialized_size(offset_t)
1146 static offset_t serialized_size_w_padding()
1148 return serialized_size(0);
1169template <
typename T>
1178 offset_t absolute_offset)
1192 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1193 RTI_FLAT_ASSERT(this->stream_.check_size(
sizeof(T)),
return false);
1195 this->stream_.template serialize_fast<T>(value);
Represents the Offset to an arbitrary user-defined FlatData final IDL struct.
Definition: Offset.hpp:125
bool my_primitive(int32_t value)
Sets the value for a primitive member.
FlatFinalBar::ConstOffset my_complex() const
Retrieves a const Offset to a complex member.
MyFlatFinalConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:135
FlatFinalBar::Offset my_complex()
Retrieves a non-const Offset to a complex member.
rti::flat::PrimitiveArrayOffset< int32_t, 10 > my_primitive_array()
Retrieves a non-const Offset to a primitive array.
int32_t my_primitive() const
Retrieves the value for a primitive member.
rti::flat::FinalArrayOffset< FlatFinalBar::ConstOffset, 10 > my_complex_array() const
Retrieves a const Offset to a complex array.
rti::flat::FinalArrayOffset< FlatFinalBar::Offset, 10 > my_complex_array()
Retrieves a non-const Offset to a complex array.
const rti::flat::PrimitiveArrayOffset< int32_t, 10 > my_primitive_array() const
Retrieves a const Offset to a primitive array.
MyFlatFinalOffset()
Creates a null Offset.
Definition: Offset.hpp:142
Represents the Offset to an arbitrary user-defined FlatData mutable IDL struct.
Definition: Offset.hpp:203
MyFlatFinal::Offset my_final()
Retrieves a non-const Offset to a complex member.
bool my_primitive(int32_t value)
Sets the value of a primitive member.
rti::flat::MutableArrayOffset< FlatMutableBar::ConstOffset, 10 > my_mutable_array() const
Retrieves a const Offset to a complex array.
int32_t my_primitive() const
Retrieves the value for a primitive member.
MyFlatFinal::ConstOffset my_final() const
Retrieves a const Offset to a complex member.
FlatMutableBar::ConstOffset my_mutable() const
Retrieves a const Offset to a complex member.
rti::flat::PrimitiveConstOffset< int32_t > my_optional_primitive() const
Retrieves a const Offset to an optional primitive.
rti::flat::SequenceOffset< MyFlatFinal::ConstOffset > my_final_seq() const
Retrieves a const Offset to a complex sequence.
rti::flat::PrimitiveSequenceOffset< int32_t > my_primitive_seq()
Retrieves a non-const Offset to a primitive sequence.
MyFlatMutableOffset()
Creates a null Offset.
Definition: Offset.hpp:220
rti::flat::SequenceOffset< rti::flat::StringOffset > my_string_seq()
Retrieves a non-const Offset to a sequence of strings.
rti::flat::FinalAlignedArrayOffset< MyFlatFinal::Offset, 10 > my_final_array()
Retrieves a non-const Offset to a complex array.
rti::flat::SequenceOffset< MyFlatFinal::Offset > my_final_seq()
Retrieves a non-const Offset to a complex sequence.
rti::flat::MutableArrayOffset< FlatMutableBar::Offset, 10 > my_mutable_array()
Retrieves a non-const Offset to a complex array.
rti::flat::SequenceOffset< const rti::flat::StringOffset > my_string_seq() const
Retrieves a const Offset to a sequence of strings.
const rti::flat::PrimitiveArrayOffset< int32_t, 10 > my_primitive_array() const
Retrieves a const Offset to a primitive array.
rti::flat::SequenceOffset< FlatMutableBar::Offset > my_mutable_seq()
Retrieves a non-const Offset to a complex sequence.
rti::flat::SequenceOffset< FlatMutableBar::ConstOffset > my_mutable_seq() const
Retrieves a const Offset to a complex sequence.
const rti::flat::PrimitiveSequenceOffset< int32_t > my_primitive_seq() const
Retrieves a const Offset to a primitive sequence.
FlatMutableBar::Offset my_mutable()
Retrieves a non-const Offset to a complex member.
const rti::flat::StringOffset my_string() const
Retrieves a const Offset to a string.
rti::flat::FinalAlignedArrayOffset< MyFlatFinal::ConstOffset, 10 > my_final_array() const
Retrieves a const Offset to a complex array.
rti::flat::PrimitiveArrayOffset< int32_t, 10 > my_primitive_array()
Retrieves a non-const Offset to a primitive array.
rti::flat::StringOffset my_string()
Retrieves a non-const Offset to a string.
MyFlatMutableConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:213
Represents the Offset to an arbitrary user-defined FlatData mutable IDL union.
Definition: Offset.hpp:376
MyFlatMutable::Offset my_mutable()
Retrieves a non-const Offset to a complex member.
bool my_primitive(int32_t value)
Sets the value for a primitive member.
int32_t my_primitive() const
Retrieves the value for a primitive member.
int32_t _d() const
Retrieves the union discriminator.
MyFlatFinal::Offset my_final()
Retrieves a non-const Offset to a complex member.
MyFlatUnionOffset()
Creates a null Offset.
Definition: Offset.hpp:388
MyFlatMutable::ConstOffset my_mutable() const
Retrieves a const Offset to a complex member.
MyFlatUnionConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:381
MyFlatFinal::ConstOffset my_final() const
Retrieves a const Offset to a complex member.
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:776
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:683
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:805
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:621
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:987
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
friend bool operator>=(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:685
friend bool operator<(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:652
const unsigned char * get_buffer() const
Gets this member's position in the buffer.
Definition: Offset.hpp:627
friend bool operator!=(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to different positions.
Definition: Offset.hpp:707
friend bool operator==(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to the same position.
Definition: Offset.hpp:696
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:641
friend bool operator<=(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:674
friend bool operator>(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:663
bool is_cpp_compatible() const
Indicates whether rti::flat::plain_cast() is possible.
Definition: Offset.hpp:595
Offset to an array of primitive elements.
Definition: SequenceOffsets.hpp:241
Offset to a sequence of primitive elements.
Definition: SequenceOffsets.hpp:146
OffsetType Offset
The related Offset type.
Definition: FlatSample.hpp:155
OffsetType::ConstOffset ConstOffset
The related read-only Offset type.
Definition: FlatSample.hpp:162
Offset to a sequence of non-primitive elements.
Definition: SequenceOffsets.hpp:501
Offset to a string.
Definition: SequenceOffsets.hpp:291
The RTI namespace.
Definition: AggregationBuilders.hpp:17
A const Offset to an optional primitive member.
Definition: Offset.hpp:1104
T get() const
Gets the value of this primitive member.
Definition: Offset.hpp:1133
An Offset to an optional primitive member.
Definition: Offset.hpp:1170
bool set(T value)
Sets a value for this primitive member.
Definition: Offset.hpp:1190
Given a Sample, an Offset or a Builder, it allows obtaining the other types.
Definition: FlatSample.hpp:340