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 T,
unsigned int N>
481class FinalArrayOffset;
511 return sample_ == NULL;
534 unsigned char * get_buffer()
539 return stream_.current_position();
559 return stream_.current_position();
570 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return 0);
571 return stream_.total_size();
582 return s1.get_buffer() < s2.get_buffer();
593 return s1.get_buffer() > s2.get_buffer();
604 return s1.get_buffer() <= s2.get_buffer();
615 return s1.get_buffer() >= s2.get_buffer();
626 return s1.get_buffer() == s2.get_buffer();
650 offset_t absolute_offset,
651 offset_t serialized_size)
653 absolute_offset_(absolute_offset)
658 RTI_FLAT_CHECK_PRECONDITION(sample != NULL,
return);
660 sample_->initialize_stream(
667 template <
typename U>
668 U deserialize(offset_t member_offset)
const
670 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
671 RTI_FLAT_ASSERT(stream_.check_size(member_offset +
static_cast<offset_t
>(
sizeof(U))),
return U());
673 rti::xcdr::Stream::Memento stream_memento(stream_);
674 stream_.skip_fast(member_offset);
675 return stream_.deserialize_fast<U>();
679 template <
typename U>
680 bool serialize(offset_t member_offset, U value)
682 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
683 RTI_FLAT_ASSERT(stream_.check_size(member_offset +
static_cast<offset_t
>(
sizeof(U))),
return false);
685 rti::xcdr::Stream::Memento stream_memento(stream_);
687 stream_.skip_fast(member_offset);
688 stream_.serialize_fast<U>(value);
695 template <
typename U>
696 U get_member(offset_t relative_member_offset)
698 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
703 absolute_offset_ + relative_member_offset);
706 template <
typename U>
707 U get_member(offset_t relative_member_offset)
const
709 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
714 absolute_offset_ + relative_member_offset);
720 offset_t absolute_offset_;
721 mutable rti::xcdr::Stream stream_;
734 typedef fixed_size_type_tag_t offset_kind;
736 static offset_t serialized_size_w_padding()
738 RTI_FLAT_ASSERT(T::serialized_size(0) > 0,
return 0);
739 RTI_FLAT_ASSERT(T::required_alignment > 0,
return 0);
741 const offset_t element_size = T::serialized_size(0);
742 if (element_size % T::required_alignment != 0) {
743 return element_size + T::required_alignment
744 - element_size % T::required_alignment;
750 bool is_cpp_compatible()
const
752 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
753 return !stream_.needs_byte_swap()
754 && rti::xcdr::has_cpp_friendly_cdr_layout<
768 FinalOffset(SampleBase *sample, offset_t absolute_offset)
772 T::serialized_size(absolute_offset))
779 template <
typename U>
780 U deserialize(
const offset_t *relative_member_offsets)
const
782 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
794 return OffsetBase::deserialize<U>(
796 get_value_for_alignment(relative_member_offsets));
800 template <
typename U>
801 bool serialize(
const offset_t *relative_member_offsets, U value)
803 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return false);
805 return OffsetBase::serialize<U>(
807 get_value_for_alignment(relative_member_offsets), value);
814 template <
typename U>
815 U get_member(
const offset_t *relative_member_offsets)
817 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
819 return OffsetBase::get_member<U>(
820 get_value_for_alignment(relative_member_offsets));
823 template <
typename U>
824 U get_member(
const offset_t *relative_member_offsets)
const
826 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return U());
828 return OffsetBase::get_member<U>(
829 get_value_for_alignment(relative_member_offsets));
833 template <
typename U,
unsigned int N>
835 const offset_t *relative_member_offsets,
836 const offset_t *first_element_sizes,
837 offset_t element_size)
841 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return ArrayType());
842 RTI_FLAT_ASSERT(first_element_sizes != NULL,
return ArrayType());
844 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ArrayType());
849 absolute_offset_ + get_value_for_alignment(relative_member_offsets),
851 get_value_for_alignment(first_element_sizes),
856 template <
typename U,
unsigned int N>
858 const offset_t *relative_member_offsets,
859 const offset_t *first_element_sizes,
860 offset_t element_size)
const
864 RTI_FLAT_ASSERT(relative_member_offsets != NULL,
return ArrayType());
865 RTI_FLAT_ASSERT(first_element_sizes != NULL,
return ArrayType());
867 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return ArrayType());
871 absolute_offset_ + get_value_for_alignment(relative_member_offsets),
873 get_value_for_alignment(first_element_sizes),
884 offset_t get_value_for_alignment(
const offset_t *values_per_alignment)
const
886 return values_per_alignment
887 [absolute_offset_ % RTI_XCDR_MAX_XCDR2_ALIGNMENT];
891struct MutableOffsetHelper {
894 static offset_t calculate_serialized_size(
895 rti::flat::SampleBase *sample,
896 offset_t absolute_offset,
899 RTI_FLAT_ASSERT(sample != NULL,
return 0);
901 return RTIXCdrFlatSample_getMutableSampleSize(
902 sample->get_buffer(),
916 typedef variable_size_type_tag_t offset_kind;
917 typedef MutableOffsetHelper Helper;
926 offset_t absolute_offset,
927 offset_t serialized_size)
935 template <
typename U>
936 U deserialize(member_id_t member_id, U default_val = U())
const
938 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
940 rti::xcdr::Stream::Memento stream_memento(stream_);
942 offset_t member_size = 0;
943 if (!RTIXCdrStream_findV2MutableSampleMember(
950 return stream_.deserialize_fast<U>();
954 template <
typename U>
955 bool serialize(member_id_t member_id, U value)
957 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
959 rti::xcdr::Stream::Memento stream_memento(stream_);
961 offset_t member_size = 0;
962 if (!RTIXCdrStream_findV2MutableSampleMember(
969 stream_.serialize_fast<U>(value);
973 template <
typename U>
974 U get_member(member_id_t member_id)
const
976 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
978 rti::xcdr::Stream::Memento stream_memento(stream_);
980 offset_t member_size = 0;
981 if (!RTIXCdrStream_findV2MutableSampleMember(
988 return get_member_impl<U>(
990 detail::ptrdiff(stream_.current_position(), sample_->get_buffer()),
992 typename U::offset_kind());
996 template <
typename U>
998 offset_t absolute_member_offset,
999 offset_t member_size,
1000 variable_size_type_tag_t)
const
1002 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1005 return U(sample_, absolute_member_offset, member_size);
1008 template <
typename U>
1010 offset_t absolute_member_offset,
1011 offset_t member_size,
1012 fixed_size_type_tag_t)
const
1016 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1017 RTI_FLAT_ASSERT(member_size == U::serialized_size(0),
return U());
1020 return U(sample_, absolute_member_offset);
1032template <
typename T>
1035 typedef fixed_size_type_tag_t offset_kind;
1043 offset_t absolute_offset)
1051 bool is_cpp_compatible()
const
1053 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1054 return sizeof(T) == 1 || !stream_.needs_byte_swap();
1064 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return T());
1065 RTI_FLAT_ASSERT(stream_.check_size(
sizeof(T)),
return T());
1067 return stream_.deserialize_fast<T>();
1070 static offset_t serialized_size(offset_t)
1075 static offset_t serialized_size_w_padding()
1077 return serialized_size(0);
1098template <
typename T>
1107 offset_t absolute_offset)
1121 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1122 RTI_FLAT_ASSERT(this->stream_.check_size(
sizeof(T)),
return false);
1124 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:728
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:635
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:732
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:580
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:914
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
friend bool operator>=(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:612
friend bool operator<(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:579
const unsigned char * get_buffer() const
Gets this member's position in the buffer.
Definition: Offset.hpp:554
friend bool operator!=(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to different positions.
Definition: Offset.hpp:634
friend bool operator==(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to the same position.
Definition: Offset.hpp:623
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:568
friend bool operator<=(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:601
friend bool operator>(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:590
bool is_cpp_compatible() const
Indicates whether rti::flat::plain_cast() is possible.
Definition: Offset.hpp:522
Offset to an array of primitive elements.
Definition: SequenceOffsets.hpp:220
Offset to a sequence of primitive elements.
Definition: SequenceOffsets.hpp:134
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:471
Offset to a string.
Definition: SequenceOffsets.hpp:263
The RTI namespace.
Definition: AggregationBuilders.hpp:17
A const Offset to an optional primitive member.
Definition: Offset.hpp:1033
T get() const
Gets the value of this primitive member.
Definition: Offset.hpp:1062
An Offset to an optional primitive member.
Definition: Offset.hpp:1099
bool set(T value)
Sets a value for this primitive member.
Definition: Offset.hpp:1119
Given a Sample, an Offset or a Builder, it allows obtaining the other types.
Definition: FlatSample.hpp:340