From 35e723e022a67050f13080770889cf81d2750196 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 17 Sep 2021 10:41:57 +0200 Subject: [PATCH] Reverting changes on rtps/common headers. Signed-off-by: Miguel Company --- include/fastdds/rtps/common/EntityId_t.hpp | 9 +- include/fastdds/rtps/common/Guid.h | 97 +-- include/fastdds/rtps/common/InstanceHandle.h | 64 +- include/fastdds/rtps/common/Time_t.h | 670 +++++++++++-------- 4 files changed, 505 insertions(+), 335 deletions(-) diff --git a/include/fastdds/rtps/common/EntityId_t.hpp b/include/fastdds/rtps/common/EntityId_t.hpp index de5ed5588ca..6fe9e6bdd70 100644 --- a/include/fastdds/rtps/common/EntityId_t.hpp +++ b/include/fastdds/rtps/common/EntityId_t.hpp @@ -231,7 +231,14 @@ inline bool operator !=( const EntityId_t& id1, const EntityId_t& id2) { - return !(id1 == id2); + for (uint8_t i = 0; i < 4; ++i) + { + if (id1.value[i] != id2.value[i]) + { + return true; + } + } + return false; } #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC diff --git a/include/fastdds/rtps/common/Guid.h b/include/fastdds/rtps/common/Guid.h index 93f08227bc0..4fdb35a28e1 100644 --- a/include/fastdds/rtps/common/Guid.h +++ b/include/fastdds/rtps/common/Guid.h @@ -122,62 +122,81 @@ struct RTPS_DllAPI GUID_t return *reinterpret_cast(this); } +}; + #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - /** - * GUID comparison operator - * @param other Second GUID to compare - * @return True if equal - */ - inline bool operator ==( - const GUID_t& other) const +/** + * GUID comparison operator + * @param g1 First GUID to compare + * @param g2 Second GUID to compare + * @return True if equal + */ +inline bool operator ==( + const GUID_t& g1, + const GUID_t& g2) +{ + if (g1.guidPrefix == g2.guidPrefix && g1.entityId == g2.entityId) { - return (guidPrefix == other.guidPrefix && entityId == other.entityId); + return true; + } + else + { + return false; } +} - /** - * GUID comparison operator - * @param other Second GUID to compare - * @return True if not equal - */ - inline bool operator !=( - const GUID_t& other) const +/** + * GUID comparison operator + * @param g1 First GUID to compare + * @param g2 Second GUID to compare + * @return True if not equal + */ +inline bool operator !=( + const GUID_t& g1, + const GUID_t& g2) +{ + if (g1.guidPrefix != g2.guidPrefix || g1.entityId != g2.entityId) { - return (guidPrefix != other.guidPrefix || entityId != other.entityId); + return true; + } + else + { + return false; } +} - inline bool operator <( - const GUID_t& other) const +inline bool operator <( + const GUID_t& g1, + const GUID_t& g2) +{ + for (uint8_t i = 0; i < 12; ++i) { - for (uint8_t i = 0; i < 12; ++i) + if (g1.guidPrefix.value[i] < g2.guidPrefix.value[i]) { - if (guidPrefix.value[i] < other.guidPrefix.value[i]) - { - return true; - } - else if (guidPrefix.value[i] > other.guidPrefix.value[i]) - { - return false; - } + return true; } - for (uint8_t i = 0; i < 4; ++i) + else if (g1.guidPrefix.value[i] > g2.guidPrefix.value[i]) { - if (entityId.value[i] < other.entityId.value[i]) - { - return true; - } - else if (entityId.value[i] > other.entityId.value[i]) - { - return false; - } + return false; + } + } + for (uint8_t i = 0; i < 4; ++i) + { + if (g1.entityId.value[i] < g2.entityId.value[i]) + { + return true; + } + else if (g1.entityId.value[i] > g2.entityId.value[i]) + { + return false; } - return false; } + return false; +} #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -}; - const GUID_t c_Guid_Unknown; #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC diff --git a/include/fastdds/rtps/common/InstanceHandle.h b/include/fastdds/rtps/common/InstanceHandle.h index 52e35219756..37fa6a34cb4 100644 --- a/include/fastdds/rtps/common/InstanceHandle.h +++ b/include/fastdds/rtps/common/InstanceHandle.h @@ -126,50 +126,41 @@ struct RTPS_DllAPI InstanceHandle_t return *reinterpret_cast(this); } - /** - * Strictly less than operator - * @param other The other InstanceHandle_t to compare - * @return True if the value of this handle lexicographically preceeds that of \p other - */ - inline bool operator <( - const InstanceHandle_t& other) const - { - return memcmp(value, other.value, 16) < 0; - } +}; + +const InstanceHandle_t c_InstanceHandle_Unknown; #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - /** - * Comparison operator - * @param other Second InstanceHandle_t to compare - * @return True if equal - */ - inline bool operator ==( - const InstanceHandle_t& other) const +/** + * Comparison operator + * @param ihandle1 First InstanceHandle_t to compare + * @param ihandle2 Second InstanceHandle_t to compare + * @return True if equal + */ +inline bool operator ==( + const InstanceHandle_t& ihandle1, + const InstanceHandle_t& ihandle2) +{ + for (uint8_t i = 0; i < 16; ++i) { - for (uint8_t i = 0; i < 16; ++i) + if (ihandle1.value[i] != ihandle2.value[i]) { - if (value[i] != other.value[i]) - { - return false; - } + return false; } - return true; } + return true; +} - inline bool operator !=( - const InstanceHandle_t& other) const - { - return !(*this == other); - } +inline bool operator !=( + const InstanceHandle_t& ihandle1, + const InstanceHandle_t& ihandle2) +{ + return !(ihandle1 == ihandle2); +} #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -}; - -const InstanceHandle_t c_InstanceHandle_Unknown; - - /** * Convert InstanceHandle_t to GUID * @param guid GUID to store the results @@ -216,6 +207,13 @@ inline GUID_t iHandle2GUID( return guid; } +inline bool operator <( + const InstanceHandle_t& h1, + const InstanceHandle_t& h2) +{ + return memcmp(h1.value, h2.value, 16) < 0; +} + #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC /** diff --git a/include/fastdds/rtps/common/Time_t.h b/include/fastdds/rtps/common/Time_t.h index 0a87c6d5e66..6620c7c009b 100644 --- a/include/fastdds/rtps/common/Time_t.h +++ b/include/fastdds/rtps/common/Time_t.h @@ -73,159 +73,10 @@ struct RTPS_DllAPI Time_t */ static void now( Time_t& ret); - - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - - /** - * Comparison operator - * @param other Second Time_t to compare - * @return True if equal - */ - inline bool operator ==( - const Time_t& other) const - { - if (seconds != other.seconds) - { - return false; - } - if (nanosec != other.nanosec) - { - return false; - } - return true; - } - - /** - * Comparison operator - * @param other Second Time_t to compare - * @return True if not equal - */ - inline bool operator !=( - const Time_t& other) const - { - return !(*this == other); - } - - /** - * Checks if a Time_t is less than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is less than the second - */ - inline bool operator <( - const Time_t& other) const - { - if (seconds < other.seconds) - { - return true; - } - else if (seconds > other.seconds) - { - return false; - } - else - { - if (nanosec < other.nanosec) - { - return true; - } - else - { - return false; - } - } - } - - /** - * Checks if a Time_t is greater than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is greater than the second - */ - inline bool operator >( - const Time_t& other) const - { - return other < *this; - } - - /** - * Checks if a Time_t is less or equal than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is less or equal than the second - */ - inline bool operator <=( - const Time_t& other) const - { - return !(*this > other); - } - - /** - * Checks if a Time_t is greater or equal than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is greater or equal than the second - */ - inline bool operator >=( - const Time_t& other) const - { - return !(*this < other); - } - - /** - * Adds two Time_t. - * @param other Second Time_t to add - * @return A new Time_t with the result. - */ - inline Time_t operator +( - const Time_t& other) const - { - Time_t result(seconds + other.seconds, nanosec + other.nanosec); - if (result.nanosec < nanosec) // Overflow is detected by any of them - { - ++result.seconds; - } - return result; - } - - /** - * Subtracts two Time_t. - * @param other Second Time_t to subtract - * @return A new Time_t with the result. - */ - inline Time_t operator -( - const Time_t& other) const - { - Time_t result(seconds - other.seconds, nanosec - other.nanosec); - if (result.nanosec > nanosec) // Overflow is detected by ta - { - --result.seconds; - } - return result; - } - -#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - }; using Duration_t = Time_t; -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -inline std::ostream& operator <<( - std::ostream& output, - const Time_t& t) -{ - long double t_aux = t.seconds + (((long double)t.nanosec) / 1000000000ULL); - return output << t_aux; -} - -#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -//! Time_t (Duration_t) representing an infinite time. DONT USE IT IN CONSTRUCTORS -const Time_t c_TimeInfinite{TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS}; -//! Time_t (Duration_t) representing a zero time. DONT USE IT IN CONSTRUCTORS -const Time_t c_TimeZero{0, 0}; -//! Time_t (Duration_t) representing an invalid time. DONT USE IT IN CONSTRUCTORS -const Time_t c_TimeInvalid{-1, TIME_T_INFINITE_NANOSECONDS}; - namespace rtps { /** @@ -321,153 +172,191 @@ class RTPS_DllAPI Time_t static void now( Time_t& ret); +private: + + //!Seconds + int32_t seconds_ = 0; + + //!Fraction of second (1 fraction = 1/(2^32) seconds) + uint32_t fraction_ = 0; + + //!Nanoseconds + uint32_t nanosec_ = 0; + + void set_fraction( + uint32_t frac); + + void set_nanosec( + uint32_t nanos); +}; + #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - /** - * Comparison operator - * @param other Second Time_t to compare - * @return True if equal - */ - inline bool operator ==( - const Time_t& other) const +/** + * Comparison assignment + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if equal + */ +static inline bool operator ==( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() != t2.seconds()) + { + return false; + } + if (t1.fraction() != t2.fraction()) + { + return false; + } + return true; +} + +/** + * Comparison assignment + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if not equal + */ +static inline bool operator !=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() != t2.seconds()) { - if (seconds() != other.seconds()) + return true; + } + if (t1.fraction() != t2.fraction()) + { + return true; + } + return false; +} + +/** + * Checks if a Time_t is less than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is less than the second + */ +static inline bool operator <( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() < t2.seconds()) + { + return true; + } + else if (t1.seconds() > t2.seconds()) + { + return false; + } + else + { + if (t1.fraction() < t2.fraction()) { - return false; + return true; } - if (fraction() != other.fraction()) + else { return false; } - return true; } +} - /** - * Comparison operator - * @param other Second Time_t to compare - * @return True if not equal - */ - inline bool operator !=( - const Time_t& other) const +/** + * Checks if a Time_t is greater than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is greater than the second + */ +static inline bool operator >( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() > t2.seconds()) { - return !(*this == other); + return true; } - - /** - * Checks if a Time_t is less than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is less than the second - */ - inline bool operator <( - const Time_t& other) const + else if (t1.seconds() < t2.seconds()) + { + return false; + } + else { - if (seconds() < other.seconds()) + if (t1.fraction() > t2.fraction()) { return true; } - else if (seconds() > other.seconds()) - { - return false; - } else { - if (fraction() < other.fraction()) - { - return true; - } - else - { - return false; - } + return false; } } +} - /** - * Checks if a Time_t is greater than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is greater than the second - */ - inline bool operator >( - const Time_t& other) const - { - return other < *this; - } - - /** - * Checks if a Time_t is less or equal than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is less or equal than the second - */ - inline bool operator <=( - const Time_t& other) const +/** + * Checks if a Time_t is less or equal than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is less or equal than the second + */ +static inline bool operator <=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() < t2.seconds()) { - return !(*this > other); + return true; } - - /** - * Checks if a Time_t is greater or equal than other. - * @param other Second Time_t to compare - * @return True if the first Time_t is greater or equal than the second - */ - inline bool operator >=( - const Time_t& other) const + else if (t1.seconds() > t2.seconds()) { - return !(*this < other); + return false; } - - /** - * Adds two Time_t. - * @param other Second Time_t to add - * @return A new Time_t with the result. - */ - inline Time_t operator +( - const Time_t& other) const + else { - Time_t result(seconds() + other.seconds(), fraction() + other.fraction()); - if (result.fraction() < fraction()) // Overflow is detected by any of them + if (t1.fraction() <= t2.fraction()) + { + return true; + } + else { - ++result.seconds(); + return false; } - return result; } +} - /** - * Subtracts two Time_t. - * @param other Second Time_t to subtract - * @return A new Time_t with the result. - */ - inline Time_t operator -( - const Time_t& other) const +/** + * Checks if a Time_t is greater or equal than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is greater or equal than the second + */ +static inline bool operator >=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds() > t2.seconds()) + { + return true; + } + else if (t1.seconds() < t2.seconds()) + { + return false; + } + else { - Time_t result(seconds() - other.seconds(), fraction() - other.fraction()); - if (result.fraction() > fraction()) // Overflow is detected by ta + if (t1.fraction() >= t2.fraction()) { - --result.seconds(); + return true; + } + else + { + return false; } - return result; } - -#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -private: - - //!Seconds - int32_t seconds_ = 0; - - //!Fraction of second (1 fraction = 1/(2^32) seconds) - uint32_t fraction_ = 0; - - //!Nanoseconds - uint32_t nanosec_ = 0; - - void set_fraction( - uint32_t frac); - - void set_nanosec( - uint32_t nanos); -}; - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC +} inline std::ostream& operator <<( std::ostream& output, @@ -514,6 +403,42 @@ inline std::istream& operator >>( return input; } +/** + * Adds two Time_t. + * @param ta First Time_t to add + * @param tb Second Time_t to add + * @return A new Time_t with the result. + */ +static inline Time_t operator +( + const Time_t& ta, + const Time_t& tb) +{ + Time_t result(ta.seconds() + tb.seconds(), ta.fraction() + tb.fraction()); + if (result.fraction() < ta.fraction()) // Overflow is detected by any of them + { + ++result.seconds(); + } + return result; +} + +/** + * Subtracts two Time_t. + * @param ta First Time_t to subtract + * @param tb Second Time_t to subtract + * @return A new Time_t with the result. + */ +static inline Time_t operator -( + const Time_t& ta, + const Time_t& tb) +{ + Time_t result(ta.seconds() - tb.seconds(), ta.fraction() - tb.fraction()); + if (result.fraction() > ta.fraction()) // Overflow is detected by ta + { + --result.seconds(); + } + return result; +} + #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC const Time_t c_RTPSTimeInfinite{0x7fffffff, 0xffffffff}; @@ -522,6 +447,227 @@ const Time_t c_RTPSTimeInvalid{-1, 0xffffffff}; } // namespace rtps +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * Comparison assignment + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if equal + */ +static inline bool operator ==( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds != t2.seconds) + { + return false; + } + if (t1.nanosec != t2.nanosec) + { + return false; + } + return true; +} + +/** + * Comparison assignment + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if not equal + */ +static inline bool operator !=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds != t2.seconds) + { + return true; + } + if (t1.nanosec != t2.nanosec) + { + return true; + } + return false; +} + +/** + * Checks if a Time_t is less than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is less than the second + */ +static inline bool operator <( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds < t2.seconds) + { + return true; + } + else if (t1.seconds > t2.seconds) + { + return false; + } + else + { + if (t1.nanosec < t2.nanosec) + { + return true; + } + else + { + return false; + } + } +} + +/** + * Checks if a Time_t is greater than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is greater than the second + */ +static inline bool operator >( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds > t2.seconds) + { + return true; + } + else if (t1.seconds < t2.seconds) + { + return false; + } + else + { + if (t1.nanosec > t2.nanosec) + { + return true; + } + else + { + return false; + } + } +} + +/** + * Checks if a Time_t is less or equal than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is less or equal than the second + */ +static inline bool operator <=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds < t2.seconds) + { + return true; + } + else if (t1.seconds > t2.seconds) + { + return false; + } + else + { + if (t1.nanosec <= t2.nanosec) + { + return true; + } + else + { + return false; + } + } +} + +/** + * Checks if a Time_t is greater or equal than other. + * @param t1 First Time_t to compare + * @param t2 Second Time_t to compare + * @return True if the first Time_t is greater or equal than the second + */ +static inline bool operator >=( + const Time_t& t1, + const Time_t& t2) +{ + if (t1.seconds > t2.seconds) + { + return true; + } + else if (t1.seconds < t2.seconds) + { + return false; + } + else + { + if (t1.nanosec >= t2.nanosec) + { + return true; + } + else + { + return false; + } + } +} + +inline std::ostream& operator <<( + std::ostream& output, + const Time_t& t) +{ + long double t_aux = t.seconds + (((long double)t.nanosec) / 1000000000ULL); + return output << t_aux; +} + +/** + * Adds two Time_t. + * @param ta First Time_t to add + * @param tb Second Time_t to add + * @return A new Time_t with the result. + */ +static inline Time_t operator +( + const Time_t& ta, + const Time_t& tb) +{ + Time_t result(ta.seconds + tb.seconds, ta.nanosec + tb.nanosec); + if (result.nanosec < ta.nanosec) // Overflow is detected by any of them + { + ++result.seconds; + } + return result; +} + +/** + * Subtracts two Time_t. + * @param ta First Time_t to subtract + * @param tb Second Time_t to subtract + * @return A new Time_t with the result. + */ +static inline Time_t operator -( + const Time_t& ta, + const Time_t& tb) +{ + Time_t result(ta.seconds - tb.seconds, ta.nanosec - tb.nanosec); + if (result.nanosec > ta.nanosec) // Overflow is detected by ta + { + --result.seconds; + } + return result; +} + +#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +//! Time_t (Duration_t) representing an infinite time. DONT USE IT IN CONSTRUCTORS +const Time_t c_TimeInfinite{TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS}; +//! Time_t (Duration_t) representing a zero time. DONT USE IT IN CONSTRUCTORS +const Time_t c_TimeZero{0, 0}; +//! Time_t (Duration_t) representing an invalid time. DONT USE IT IN CONSTRUCTORS +const Time_t c_TimeInvalid{-1, TIME_T_INFINITE_NANOSECONDS}; + } // namespace fastrtps } // namespace eprosima