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

Add copy functions to objects - WIP

parent 1963577d
......@@ -48,6 +48,13 @@ namespace ITA
///
C3DObject ( const VistaVector3D& position, const VistaQuaternion& orientation, Type type, int id );
///
/// \brief Copy constructor.
/// \param obj object to copy from.
///
C3DObject ( const C3DObject& obj ) = default;
///
/// \brief Get the position of the C3DObject.
/// \return a const ref to the position.
......
......@@ -46,6 +46,12 @@ namespace ITA
///
explicit CUpdateConfig ( ConfigChangeType type, std::string payload = "" );
///
/// \brief Copy constructor.
/// \param obj object to copy from.
///
CUpdateConfig ( const CUpdateConfig& obj ) = default;
///
/// \brief Get the ConfigChangeType of the update.
/// \return the ConfigChangeType of the update.
......
......@@ -26,8 +26,9 @@ namespace ITA
/// A scene change is a change of a source or receiver pose.
/// A change of either source or receiver can lead to a change in the transfer path between a corresponding source-receiver-pair.
/// Thus, a CUpdateScene combines pose information for such a source-receiver-pair.
/// \todo May be change the separate source and receiver pointers to the struct?
///
class ITA_SIMULATION_SCHEDULER_API CUpdateScene : public IUpdateMessage
class ITA_SIMULATION_SCHEDULER_API CUpdateScene : public IUpdateMessage
{
public:
///
......@@ -46,6 +47,21 @@ namespace ITA
///
explicit CUpdateScene ( unsigned int referenceID );
///
/// \brief Copy constructor.
/// \note This also copies the timestamp to keep the creation time of the original update.
/// In addition it creates copies for the source and receiver.
/// \param other object to copy from.
///
CUpdateScene ( const CUpdateScene& other );
///
/// \brief Assignment operator.
/// \param other object to copy from.
/// \return a copy of the other object.
///
CUpdateScene& operator=( const CUpdateScene& other );
///
/// \brief Get the source-receiver-pair of the update.
/// \return the SourceReceiverPair of the update.
......@@ -121,7 +137,7 @@ namespace ITA
///
/// \brief The unique ID of the update.
///
int m_iID = -1;
int m_iID = -1;
///
/// \brief The reference ID of the update (For the user).
......
......@@ -18,6 +18,26 @@ namespace ITA
{
m_iID = updateSceneMaxID++;
}
CUpdateScene::CUpdateScene ( const CUpdateScene& other )
: IUpdateMessage ( other ),
m_pSource ( new C3DObject ( *other.m_pSource ) ),
m_pReceiver ( new C3DObject ( *other.m_pReceiver ) ),
m_iID ( other.m_iID ),
m_iReferenceID ( other.m_iReferenceID ),
m_dTimeStamp ( other.m_dTimeStamp )
{ }
CUpdateScene& CUpdateScene::operator=( const CUpdateScene& other )
{
if ( this == &other )
return *this;
IUpdateMessage::operator =( other );
m_pSource = std::make_unique<C3DObject> ( *other.m_pSource );
m_pReceiver = std::make_unique<C3DObject> ( *other.m_pReceiver );
m_iID = other.m_iID;
m_iReferenceID = other.m_iReferenceID;
m_dTimeStamp = other.m_dTimeStamp;
return *this;
}
SourceReceiverPair CUpdateScene::getSourceReceiverPair ( ) const
{
SourceReceiverPair pair;
......
......@@ -164,4 +164,14 @@ TEST ( C3DObject, uniqueptr )
EXPECT_EQ ( VistaQuaternion ( 1, 0, 0, 0 ), ptr->getOrientation ( ) );
EXPECT_EQ ( simsched::C3DObject::Type::receiver, ptr->getType ( ) );
EXPECT_EQ ( 1, ptr->getID ( ) );
}
TEST ( C3DObject, copyConstructor)
{
auto ptr = std::make_unique<simsched::C3DObject> (
VistaVector3D ( 1, 2, 3 ), VistaQuaternion ( 1, 0, 0, 0 ), simsched::C3DObject::Type::receiver, 1 );
const auto copy = std::make_unique<simsched::C3DObject> ( *ptr );
EXPECT_EQ ( *ptr, *copy );
}
\ No newline at end of file
......@@ -44,4 +44,13 @@ TEST_F ( UpdateConfigTest, serialization )
EXPECT_EQ ( update.getType ( ), newUpdate.getType ( ) );
EXPECT_EQ ( update.getPayload ( ), newUpdate.getPayload ( ) );
}
TEST_F (UpdateConfigTest, copyConstructor)
{
const auto copy = std::make_unique<simsched::CUpdateConfig> ( update );
EXPECT_EQ ( update.getType ( ), copy->getType ( ) );
EXPECT_EQ ( update.getPayload ( ), copy->getPayload ( ) );
}
\ No newline at end of file
......@@ -85,4 +85,11 @@ TEST_F ( UpdateSceneTest, serialization )
deserializer.ReadSerializable ( newUpdate );
EXPECT_EQ ( *update, newUpdate );
}
TEST_F( UpdateSceneTest , copyConstructor)
{
auto copy = std::make_unique<simsched::CUpdateScene> ( *update );
EXPECT_EQ ( *update, *copy );
}
\ 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