[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/libRTI RTI1516fedTime.cpp
From: |
certi-cvs |
Subject: |
[certi-cvs] certi/libRTI RTI1516fedTime.cpp |
Date: |
Wed, 16 Feb 2011 12:34:32 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 11/02/16 12:34:32
Modified files:
libRTI : RTI1516fedTime.cpp
Log message:
Implement some missing encode/decode methods:
Should fix part of
bug #32503 : federate callbacks are invoked with incorrect timestamp
value
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/RTI1516fedTime.cpp?cvsroot=certi&r1=1.3&r2=1.4
Patches:
Index: RTI1516fedTime.cpp
===================================================================
RCS file: /sources/certi/certi/libRTI/RTI1516fedTime.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RTI1516fedTime.cpp 31 May 2010 13:14:18 -0000 1.3
+++ RTI1516fedTime.cpp 16 Feb 2011 12:34:31 -0000 1.4
@@ -8,7 +8,6 @@
#include <cstring>
#include "RTI1516fedTime.h"
-
#include "certi.hh"
rti1516::LogicalTime &
@@ -96,7 +95,7 @@
if (this != &value)
{
const RTI1516fedTime * other = dynamic_cast<const
RTI1516fedTime *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime
implementation");
@@ -136,7 +135,7 @@
throw (rti1516::IllegalTimeArithmetic, rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -157,7 +156,7 @@
throw (rti1516::IllegalTimeArithmetic, rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -178,7 +177,7 @@
throw (rti1516::InvalidLogicalTime)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -189,6 +188,7 @@
{
return _fedTime > other->_fedTime;
}
+ return false;
}
@@ -197,7 +197,7 @@
throw (rti1516::InvalidLogicalTime)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -208,6 +208,7 @@
{
return _fedTime < other->_fedTime;
}
+ return false;
}
@@ -216,7 +217,7 @@
throw (rti1516::InvalidLogicalTime)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -228,6 +229,7 @@
// TODO Should use epsilon during comparison
return _fedTime == other->_fedTime;
}
+ return false;
}
@@ -236,7 +238,7 @@
throw (rti1516::InvalidLogicalTime)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -247,6 +249,7 @@
{
return _fedTime >= other->_fedTime;
}
+ return false;
}
@@ -255,7 +258,7 @@
throw (rti1516::InvalidLogicalTime)
{
const RTI1516fedTime * other = dynamic_cast<const RTI1516fedTime
*>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32)
throw std::wstring(L"Different LogicalTime implementation");
@@ -266,6 +269,7 @@
{
return _fedTime <= other->_fedTime;
}
+ return false;
}
// Generates an encoded value that can be used to send
@@ -274,7 +278,13 @@
rti1516::VariableLengthData
RTI1516fedTime::encode() const
{
- throw std::wstring(L"rti1516::VariableLengthData not supported");
+ uint64_t value;
+#ifdef HOST_IS_BIG_ENDIAN
+ memcpy(&value, &_fedTime, sizeof(double));
+#else
+ value = CERTI_ENCODE_DOUBLE_TO_UINT64BE(&_fedTime);
+#endif
+ return rti1516::VariableLengthData(&value,sizeof(uint64_t));
}
// Alternate encode for directly filling a buffer
@@ -305,6 +315,7 @@
#if defined(_WIN32)
throw std::wstring(L"Not enough space in buffer to encode
RTI1516fedTime");
#else
+ return 0;
//throw rti1516::CouldNotEncode(L"Not enough space in buffer to
encode RTI1516fedTime");
#endif
}
@@ -313,15 +324,20 @@
// Decode encodedLogicalTime into self
void
-RTI1516fedTime::decode(rti1516::VariableLengthData const &)
+RTI1516fedTime::decode(rti1516::VariableLengthData const & encodedLogicalTime)
throw (rti1516::InternalError,
rti1516::CouldNotDecode)
{
-#if defined(_WIN32) && defined(_MSC_VER)
- throw std::wstring(L"rti1516::VariableLengthData not supported");
+ union ud {
+ double dv;
+ uint64_t uv;
+ } value;
+#ifdef HOST_IS_BIG_ENDIAN
+ memcpy(&(value.uv), encodedLogicalTime.data(), sizeof(double));
#else
- //throw rti1516::CouldNotDecode(L"rti1516::VariableLengthData not
supported");
+ value.uv = CERTI_DECODE_DOUBLE_FROM_UINT64BE(encodedLogicalTime.data());
#endif
+ _fedTime = value.dv;
}
// Alternate decode that reads directly from a buffer
@@ -434,7 +450,7 @@
if (this != &value)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -511,8 +527,7 @@
// TODO Should handle infinity?
_fedInterval = val1->getFedTime() - val2->getFedTime();
}
-
-}
+} /* end of RTI1516fedTimeInterval::setToDifference */
rti1516::LogicalTimeInterval &
@@ -520,7 +535,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -540,7 +555,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -560,7 +575,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -571,7 +586,8 @@
{
return getInterval() > other->getInterval();
}
-}
+ return false;
+} /* end of RTI1516fedTimeInterval::operator> */
bool
@@ -579,7 +595,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -590,6 +606,7 @@
{
return getInterval() > other->getInterval();
}
+ return false;
}
@@ -598,7 +615,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -609,6 +626,7 @@
{
return getInterval() == other->getInterval();
}
+ return false;
}
@@ -617,7 +635,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -628,6 +646,7 @@
{
return getInterval() >= other->getInterval();
}
+ return false;
}
@@ -636,7 +655,7 @@
throw (rti1516::InvalidLogicalTimeInterval)
{
const RTI1516fedTimeInterval * other = dynamic_cast<const
RTI1516fedTimeInterval *>(&value);
- if (other == 0)
+ if (other == NULL)
{
#if defined(_WIN32) && defined(_MSC_VER)
throw std::wstring(L"Different LogicalTimeInterval
implementation");
@@ -647,6 +666,7 @@
{
return getInterval() <= other->getInterval();
}
+ return false;
}
// Generates an encoded value that can be used to send
@@ -655,7 +675,13 @@
rti1516::VariableLengthData
RTI1516fedTimeInterval::encode() const
{
- throw std::wstring(L"rti1516::VariableLengthData not supported");
+ uint64_t value;
+#ifdef HOST_IS_BIG_ENDIAN
+ memcpy(&value, &_fedTime, sizeof(double));
+#else
+ value = CERTI_ENCODE_DOUBLE_TO_UINT64BE(&_fedInterval);
+#endif
+ return rti1516::VariableLengthData(&value,sizeof(uint64_t));
}
// Alternate encode for directly filling a buffer
@@ -689,6 +715,7 @@
//throw rti1516::CouldNotEncode(L"Not enough space in buffer to
encode RTI1516fedTimeInterval");
#endif
}
+ return false;
}
// Decode encodedValue into self
@@ -697,11 +724,16 @@
RTI1516fedTimeInterval::decode(rti1516::VariableLengthData const &
encodedValue)
throw (rti1516::InternalError, rti1516::CouldNotDecode)
{
-#if defined(_WIN32) && defined(_MSC_VER)
- throw std::wstring(L"rti1516::VariableLengthData not supported");
+ union ud {
+ double dv;
+ uint64_t uv;
+ } value;
+#ifdef HOST_IS_BIG_ENDIAN
+ memcpy(&(value.uv), encodedValue.data(), sizeof(double));
#else
- //throw rti1516::CouldNotDecode(L"rti1516::VariableLengthData not
supported");
+ value.uv = CERTI_DECODE_DOUBLE_FROM_UINT64BE(encodedValue.data());
#endif
+ _fedInterval = value.dv;
}
// Alternate decode that reads directly from a buffer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi/libRTI RTI1516fedTime.cpp,
certi-cvs <=