Commit f2d88166 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add relational operators to update - WIP

parent f6ff0355
......@@ -54,7 +54,7 @@ namespace ITA
/// \param other object to copy from.
///
CUpdateScene ( const CUpdateScene& other );
///
/// \brief Assignment operator.
/// \param other object to copy from.
......@@ -90,12 +90,18 @@ namespace ITA
///
unsigned int getReferenceID ( ) const;
///
/// \brief Get the timestamp of update.
/// \return the timestamp of update.
///
double getTimeStamp ( ) const;
///
/// \brief Compare two CUpdateScene, with a given tolerance.
///
/// Similar to operator==(), this function compares two CUpdateScene.
/// However, this comparison allows for a tolerance for the comparison of the source and receiver.
/// And does \b not compare the unique ID of the update.
/// And does \b not compare the unique ID and timestamp of the update.
/// \sa C3DObject::isEqualTolerance()
/// \param obj the object to check against.
/// \param dTolerance the allowed tolerance.
......@@ -173,13 +179,35 @@ namespace ITA
///
inline bool operator==( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
auto lhsSourceReceiverPair = lhs.getSourceReceiverPair ( );
auto rhsSourceReceiverPair = rhs.getSourceReceiverPair ( );
const auto lhsSourceReceiverPair = lhs.getSourceReceiverPair ( );
const auto rhsSourceReceiverPair = rhs.getSourceReceiverPair ( );
return lhs.getID ( ) == rhs.getID ( ) &&
lhs.getReferenceID ( ) == rhs.getReferenceID ( ) &&
lhs.getTimeStamp ( ) == rhs.getTimeStamp ( ) &&
*lhsSourceReceiverPair.source == *rhsSourceReceiverPair.source &&
*lhsSourceReceiverPair.receiver == *rhsSourceReceiverPair.receiver;
}
///
/// \brief Relational operator for CUpdateScene.
/// \retrun true if m_dTimeStamp is smaller for lhs, else false.
///
inline bool operator< ( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
return lhs.getTimeStamp ( ) < rhs.getTimeStamp ( );
}
inline bool operator> ( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
return rhs < lhs;
}
inline bool operator<=( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
return !( lhs > rhs );
}
inline bool operator>=( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
return !( lhs < rhs );
}
} // namespace simulation_scheduler
} // namespace ITA
......
......@@ -67,6 +67,10 @@ namespace ITA
{
return m_iReferenceID;
}
double ITA::simulation_scheduler::CUpdateScene::getTimeStamp ( ) const
{
return m_dTimeStamp;
}
bool CUpdateScene::isEqualTolerance ( const CUpdateScene& obj, double dTolerance ) const
{
return m_pSource->isEqualTolerance(*obj.m_pSource, dTolerance) &&
......
......@@ -92,4 +92,13 @@ TEST_F( UpdateSceneTest , copyConstructor)
auto copy = std::make_unique<simsched::CUpdateScene> ( *update );
EXPECT_EQ ( *update, *copy );
}
TEST_F ( UpdateSceneTest, relationalOperators )
{
const auto laterUpdate = std::make_unique<simsched::CUpdateScene> ( 1 );
EXPECT_TRUE ( *update < *laterUpdate );
EXPECT_FALSE( *update > *laterUpdate );
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment