Skip to content

Commit

Permalink
Define operators inside the classes
Browse files Browse the repository at this point in the history
This facilitates the binding to Python

Signed-off-by: Iker Luengo <ikerluengo@eprosima.com>
  • Loading branch information
IkerLuengo committed Sep 7, 2021
1 parent 10c3924 commit 989b999
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 543 deletions.
1 change: 1 addition & 0 deletions include/fastdds/dds/topic/TypeSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define _FASTDDS_TYPE_SUPPORT_HPP_

#include <fastdds/dds/topic/TopicDataType.hpp>
#include <fastdds/rtps/common/InstanceHandle.h>
#include <fastrtps/types/DynamicPubSubType.h>
#include <fastrtps/types/TypesBase.h>

Expand Down
97 changes: 46 additions & 51 deletions include/fastdds/rtps/common/EntityId_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,72 +177,67 @@ struct RTPS_DllAPI EntityId_t
return EntityId_t();
}

};

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

/**
* Guid prefix comparison operator
* @param id1 EntityId to compare
* @param id2 ID prefix to compare
* @return True if equal
*/
inline bool operator ==(
EntityId_t& id1,
const uint32_t id2)
{
#if !FASTDDS_IS_BIG_ENDIAN_TARGET
id1.reverse();
#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
const bool result = 0 == memcmp(id1.value, &id2, sizeof(id2));
#if !FASTDDS_IS_BIG_ENDIAN_TARGET
id1.reverse();
#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
return result;
}
/**
* Guid prefix comparison operator
* @param ID prefix to compare
* @return True if equal
*/
inline bool operator ==(
const uint32_t other)
{
#if !FASTDDS_IS_BIG_ENDIAN_TARGET
reverse();
#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
const bool result = 0 == memcmp(value, &other, sizeof(other));
#if !FASTDDS_IS_BIG_ENDIAN_TARGET
reverse();
#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
return result;
}

/**
* Guid prefix comparison operator
* @param id1 First EntityId to compare
* @param id2 Second EntityId to compare
* @return True if equal
*/
inline bool operator ==(
const EntityId_t& id1,
const EntityId_t& id2)
{
for (uint8_t i = 0; i < 4; ++i)
/**
* Guid prefix comparison operator
* @param other Second EntityId to compare
* @return True if equal
*/
inline bool operator ==(
const EntityId_t& other) const
{
if (id1.value[i] != id2.value[i])
for (uint8_t i = 0; i < 4; ++i)
{
return false;
if (value[i] != other.value[i])
{
return false;
}
}
return true;
}
return true;
}

/**
* Guid prefix comparison operator
* @param id1 First EntityId to compare
* @param id2 Second EntityId to compare
* @return True if not equal
*/
inline bool operator !=(
const EntityId_t& id1,
const EntityId_t& id2)
{
for (uint8_t i = 0; i < 4; ++i)
/**
* Guid prefix comparison operator
* @param other Second EntityId to compare
* @return True if not equal
*/
inline bool operator !=(
const EntityId_t& other) const
{
if (id1.value[i] != id2.value[i])
for (uint8_t i = 0; i < 4; ++i)
{
return true;
if (value[i] != other.value[i])
{
return true;
}
}
return false;
}
return false;
}

#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

};


inline std::ostream& operator <<(
std::ostream& output,
const EntityId_t& enI)
Expand Down
101 changes: 48 additions & 53 deletions include/fastdds/rtps/common/Guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,81 +122,76 @@ struct RTPS_DllAPI GUID_t
return *reinterpret_cast<const InstanceHandle_t*>(this);
}

};

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

/**
* 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 true;
}
else
{
return false;
}
}

/**
* 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 true;
}
else
/**
* GUID comparison operator
* @param other Second GUID to compare
* @return True if equal
*/
inline bool operator ==(
const GUID_t& other) const
{
return false;
if (guidPrefix == other.guidPrefix && entityId == other.entityId)
{
return true;
}
else
{
return false;
}
}
}

inline bool operator <(
const GUID_t& g1,
const GUID_t& g2)
{
for (uint8_t i = 0; i < 12; ++i)
/**
* GUID comparison operator
* @param other Second GUID to compare
* @return True if not equal
*/
inline bool operator !=(
const GUID_t& other) const
{
if (g1.guidPrefix.value[i] < g2.guidPrefix.value[i])
if (guidPrefix != other.guidPrefix || entityId != other.entityId)
{
return true;
}
else if (g1.guidPrefix.value[i] > g2.guidPrefix.value[i])
else
{
return false;
}
}
for (uint8_t i = 0; i < 4; ++i)

inline bool operator <(
const GUID_t& other) const
{
if (g1.entityId.value[i] < g2.entityId.value[i])
for (uint8_t i = 0; i < 12; ++i)
{
return true;
if (guidPrefix.value[i] < other.guidPrefix.value[i])
{
return true;
}
else if (guidPrefix.value[i] > other.guidPrefix.value[i])
{
return false;
}
}
else if (g1.entityId.value[i] > g2.entityId.value[i])
for (uint8_t i = 0; i < 4; ++i)
{
return false;
if (entityId.value[i] < other.entityId.value[i])
{
return true;
}
else if (entityId.value[i] > other.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
Expand Down
64 changes: 33 additions & 31 deletions include/fastdds/rtps/common/InstanceHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,41 +126,50 @@ struct RTPS_DllAPI InstanceHandle_t
return *reinterpret_cast<const GUID_t*>(this);
}

};

const InstanceHandle_t c_InstanceHandle_Unknown;
/**
* 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;
}

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

/**
* 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)
/**
* Comparison operator
* @param other Second InstanceHandle_t to compare
* @return True if equal
*/
inline bool operator ==(
const InstanceHandle_t& other) const
{
if (ihandle1.value[i] != ihandle2.value[i])
for (uint8_t i = 0; i < 16; ++i)
{
return false;
if (value[i] != other.value[i])
{
return false;
}
}
return true;
}
return true;
}

inline bool operator !=(
const InstanceHandle_t& ihandle1,
const InstanceHandle_t& ihandle2)
{
return !(ihandle1 == ihandle2);
}
inline bool operator !=(
const InstanceHandle_t& other) const
{
return !(*this == other);
}

#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
Expand Down Expand Up @@ -207,13 +216,6 @@ 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

/**
Expand Down
Loading

0 comments on commit 989b999

Please sign in to comment.