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 272 FlatMutableBar::ConstOffset my_mutable()
const;
337 FlatMutableBar::Offset my_mutable();
466 namespace rti {
namespace flat {
470 inline 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);
480 template <
typename T,
unsigned int N>
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_;
731 template <
typename T>
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[absolute_offset_ % 4];
890 struct MutableOffsetHelper {
893 static offset_t calculate_serialized_size(
894 rti::flat::SampleBase *sample,
895 offset_t absolute_offset,
898 RTI_FLAT_ASSERT(sample != NULL,
return 0);
900 return RTIXCdrFlatSample_getMutableSampleSize(
901 sample->get_buffer(),
915 typedef variable_size_type_tag_t offset_kind;
916 typedef MutableOffsetHelper Helper;
925 offset_t absolute_offset,
926 offset_t serialized_size)
934 template <
typename U>
935 U deserialize(member_id_t member_id, U default_val = U())
const 937 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
939 rti::xcdr::Stream::Memento stream_memento(stream_);
941 offset_t member_size = 0;
942 if (!RTIXCdrStream_findV2MutableSampleMember(
949 return stream_.deserialize_fast<U>();
953 template <
typename U>
954 bool serialize(member_id_t member_id, U value)
956 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
958 rti::xcdr::Stream::Memento stream_memento(stream_);
960 offset_t member_size = 0;
961 if (!RTIXCdrStream_findV2MutableSampleMember(
968 stream_.serialize_fast<U>(value);
972 template <
typename U>
973 U get_member(member_id_t member_id)
const 975 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return U());
977 rti::xcdr::Stream::Memento stream_memento(stream_);
979 offset_t member_size = 0;
980 if (!RTIXCdrStream_findV2MutableSampleMember(
987 return get_member_impl<U>(
989 detail::ptrdiff(stream_.current_position(), sample_->get_buffer()),
991 typename U::offset_kind());
995 template <
typename U>
997 offset_t absolute_member_offset,
998 offset_t member_size,
999 variable_size_type_tag_t)
const 1001 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1004 return U(sample_, absolute_member_offset, member_size);
1007 template <
typename U>
1009 offset_t absolute_member_offset,
1010 offset_t member_size,
1011 fixed_size_type_tag_t)
const 1015 RTI_FLAT_ASSERT(absolute_member_offset > 0,
return U());
1016 RTI_FLAT_ASSERT(member_size == U::serialized_size(0),
return U());
1019 return U(sample_, absolute_member_offset);
1031 template <
typename T>
1034 typedef fixed_size_type_tag_t offset_kind;
1042 offset_t absolute_offset)
1050 bool is_cpp_compatible()
const 1052 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1053 return sizeof(T) == 1 || !stream_.needs_byte_swap();
1063 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return T());
1064 RTI_FLAT_ASSERT(stream_.check_size(
sizeof(T)),
return T());
1066 return stream_.deserialize_fast<T>();
1069 static offset_t serialized_size(offset_t)
1074 static offset_t serialized_size_w_padding()
1076 return serialized_size(0);
1097 template <
typename T>
1106 offset_t absolute_offset)
1120 RTI_FLAT_OFFSET_CHECK_NOT_NULL(
return false);
1121 RTI_FLAT_ASSERT(this->stream_.check_size(
sizeof(T)),
return false);
1123 this->stream_.template serialize_fast<T>(value);
1130 #endif // RTI_DDS_FLAT_FLATOFFSETS_HPP_ Represents the Offset to an arbitrary user-defined FlatData mutable IDL struct.
Definition: Offset.hpp:203
Represents the Offset to an arbitrary user-defined FlatData mutable IDL union.
Definition: Offset.hpp:375
friend bool operator==(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to the same position.
Definition: Offset.hpp:623
An Offset to an optional primitive member.
Definition: Offset.hpp:1098
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
OffsetType::ConstOffset ConstOffset
The related read-only Offset type.
Definition: FlatSample.hpp:162
friend bool operator!=(const OffsetBase &s1, const OffsetBase &s2)
Determines if two offets point to different positions.
Definition: Offset.hpp:634
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:208
Offset to an array of variable-size elements.
Definition: SequenceOffsets.hpp:567
Base class of all Offset types.
Definition: Offset.hpp:489
const rti::flat::PrimitiveArrayOffset< int32_t, 10 > my_primitive_array() const
Retrieves a const Offset to a primitive array.
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:732
MyFlatMutableOffset()
Creates a null Offset.
Definition: Offset.hpp:220
friend bool operator<(const OffsetBase &s1, const OffsetBase &s2)
Compares two Offsets.
Definition: Offset.hpp:579
MyFlatUnionOffset()
Creates a null Offset.
Definition: Offset.hpp:388
FlatFinalBar::ConstOffset my_complex() const
Retrieves a const Offset to a complex member.
Offset to a string.
Definition: SequenceOffsets.hpp:251
Offset to an array of final elements.
Definition: Offset.hpp:481
OffsetType Offset
The related Offset type.
Definition: FlatSample.hpp:155
Represents the Offset to an arbitrary user-defined FlatData final IDL struct.
Definition: Offset.hpp:125
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:601
Offset to an array of final elements.
Definition: SequenceOffsets.hpp:715
MyFlatUnionConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:381
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:590
rti::flat::FinalArrayOffset< FlatFinalBar::ConstOffset, 10 > my_complex_array() const
Retrieves a const Offset to a complex array.
MyFlatMutableConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:213
int32_t my_primitive() const
Retrieves the value for a primitive member.
offset_t get_buffer_size() const
Gets the size, in bytes, of this member in the buffer.
Definition: Offset.hpp:568
The base class of all Offsets to a final struct type.
Definition: Offset.hpp:913
Definition: AggregationBuilders.hpp:17
A const Offset to an optional primitive member.
Definition: Offset.hpp:1032
Offset to a sequence of non-primitive elements.
Definition: SequenceOffsets.hpp:459
MyFlatFinalOffset()
Creates a null Offset.
Definition: Offset.hpp:142
MyFlatFinalConstOffset ConstOffset
The equivalent read-only Offset type.
Definition: Offset.hpp:135
bool is_cpp_compatible() const
Indicates whether rti::flat::plain_cast() is possible.
Definition: Offset.hpp:522