[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/libRTI CMakeLists.txt LogicalTimeDouble.c...
From: |
certi-cvs |
Subject: |
[certi-cvs] certi/libRTI CMakeLists.txt LogicalTimeDouble.c... |
Date: |
Mon, 31 May 2010 11:58:27 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 10/05/31 11:58:27
Modified files:
libRTI : CMakeLists.txt
Added files:
libRTI : LogicalTimeDouble.cpp LogicalTimeDouble.h
Log message:
Add LogicalTimeDouble as an alternate 1516 LogicalFedTime.
Fix COMPILE_FLAGS in CMakeLists.txt in order to make them
work with both MSVC and MinGW.
-DA,B should be -DA -DB
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/CMakeLists.txt?cvsroot=certi&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/LogicalTimeDouble.cpp?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/LogicalTimeDouble.h?cvsroot=certi&rev=1.1
Patches:
Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libRTI/CMakeLists.txt,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- CMakeLists.txt 28 Apr 2010 18:48:30 -0000 1.15
+++ CMakeLists.txt 31 May 2010 11:58:27 -0000 1.16
@@ -1,4 +1,3 @@
-
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libCERTI)
SET(RTI1516_LIB_SRCS
@@ -87,7 +86,7 @@
MESSAGE(STATUS "libRTI variant: HLA 1516")
SET_TARGET_PROPERTIES(RTI1516 PROPERTIES OUTPUT_NAME "RTI1516")
-SET_TARGET_PROPERTIES(RTI1516 PROPERTIES COMPILE_FLAGS
"-DHLA13NG_LIBRTI,RTI_DISABLE_WARNINGS,BUILDING_RTI")
+SET_TARGET_PROPERTIES(RTI1516 PROPERTIES COMPILE_FLAGS "-DHLA13NG_LIBRTI
-DRTI_DISABLE_WARNINGS -DBUILDING_RTI")
SET_TARGET_PROPERTIES(RTI1516 PROPERTIES VERSION 1.0.0 SOVERSION 1)
IF (MINGW)
SET_TARGET_PROPERTIES(RTI1516 PROPERTIES LINK_FLAGS
"-Wl,--output-def,${LIBRARY_OUTPUT_PATH}/libRTI1516.def")
@@ -95,7 +94,6 @@
DESTINATION lib)
ENDIF (MINGW)
-
##################################################################
# Lib FedTime
# A replacement lib FedTime may be provided by the user
@@ -135,11 +133,8 @@
SET(TestFedTime_SRCS
TestFedTime.cc
)
-
ADD_EXECUTABLE(TestFedTime ${TestFedTime_SRCS})
-
TARGET_LINK_LIBRARIES(TestFedTime FedTime RTI)
-
ADD_TEST(TestLibFedTime TestFedTime)
##########################################################
@@ -149,6 +144,8 @@
../include/RTI/certiLogicalTimeFactory.h
RTI1516fedTime.h
RTI1516fedTime.cpp
+ LogicalTimeDouble.h
+ LogicalTimeDouble.cpp
)
SOURCE_GROUP("Source Files\\FedTime" FILES ${FEDTIME1516_SRCS})
@@ -158,12 +155,13 @@
)
# Correct line
-TARGET_LINK_LIBRARIES(FedTime1516)
+#TARGET_LINK_LIBRARIES(FedTime1516)
# Incorrect line
#TARGET_LINK_LIBRARIES(FedTime1516 RTI1516)
SET_TARGET_PROPERTIES(FedTime1516 PROPERTIES PROJECT_LABEL LibFedTime1516)
-SET_TARGET_PROPERTIES(FedTime1516 PROPERTIES COMPILE_FLAGS
"-DBUILDING_FEDTIME,RTI_DISABLE_WARNINGS")
+SET_TARGET_PROPERTIES(FedTime1516 PROPERTIES COMPILE_FLAGS "-DBUILDING_FEDTIME
-DRTI_DISABLE_WARNINGS")
+
IF (MINGW)
SET_TARGET_PROPERTIES(FedTime1516 PROPERTIES LINK_FLAGS
"-Wl,--output-def,${LIBRARY_OUTPUT_PATH}/libFedTime1516.def")
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/libFedTime1516.def
@@ -184,7 +182,6 @@
#ADD_TEST(TestLibFedTime1516 TestFedTime1516)
-
# Install rules for both libRTI-NG and libFedTime
INSTALL(TARGETS RTI FedTime RTI1516 FedTime1516
RUNTIME DESTINATION bin
Index: LogicalTimeDouble.cpp
===================================================================
RCS file: LogicalTimeDouble.cpp
diff -N LogicalTimeDouble.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LogicalTimeDouble.cpp 31 May 2010 11:58:27 -0000 1.1
@@ -0,0 +1,723 @@
+#ifdef _WIN32
+#pragma warning(disable : 4786)
+#pragma warning(disable:4290)
+#endif
+
+#include "RTI/certiRTI1516.h"
+//#include "RTI/EncodedLogicalTime.h"
+//#include "RTI/EncodedLogicalTimeInterval.h"
+
+#include "LogicalTimeDouble.h"
+
+#include <cmath>
+#include <climits>
+#include <typeinfo>
+
+/*
+namespace
+{
+ class MyEncodedLogicalTime : public rti1516::EncodedLogicalTime
+ {
+ private:
+ rti1516::VariableLengthValueClass _value;
+ void* _data;
+ size_t _size;
+ public:
+ MyEncodedLogicalTime(const void* data, size_t size) :
+ _value(data, size)
+ {
+ }
+ virtual ~MyEncodedLogicalTime() throw () {}
+
+ virtual void const * data() const
+ {
+ return _value.data();
+ }
+ virtual size_t size() const
+ {
+ return _value.size();
+ }
+ };
+
+ class MyEncodedLogicalTimeInterval : public
rti1516::EncodedLogicalTimeInterval
+ {
+ private:
+ rti1516::VariableLengthValueClass _value;
+ void* _data;
+ size_t _size;
+ public:
+ MyEncodedLogicalTimeInterval(const void* data, size_t size) :
+ _value(data, size)
+ {
+ }
+ virtual ~MyEncodedLogicalTimeInterval() throw () {}
+
+ virtual void const * data() const
+ {
+ return _value.data();
+ }
+ virtual size_t size() const
+ {
+ return _value.size();
+ }
+ };
+}
+*/
+
+#ifdef __GNUC__
+const int64_t MAX_VALUE = LONG_LONG_MAX;
+#else
+const int64_t MAX_VALUE = 9223372036854775807;
+#endif
+const int64_t MULTIPLIER = 1000000;
+
+LogicalTimeDouble::LogicalTimeDouble(double value)
+{
+ int64_t seconds = (long)floor(value);
+ int64_t micros = (long)fmod(value * MULTIPLIER, (double)MULTIPLIER);
+
+ _value = seconds * MULTIPLIER + micros;
+}
+
+LogicalTimeDouble::LogicalTimeDouble(int64_t value) :
+ _value(value)
+{
+}
+
+LogicalTimeDouble::~LogicalTimeDouble()
+ throw ()
+{
+}
+
+void LogicalTimeDouble::setInitial()
+{
+ _value = 0;
+}
+
+bool LogicalTimeDouble::isInitial() const
+{
+ return _value == 0;
+}
+
+void LogicalTimeDouble::setFinal()
+{
+ _value = MAX_VALUE;
+}
+
+bool LogicalTimeDouble::isFinal() const
+{
+ return _value == MAX_VALUE;
+}
+
+void LogicalTimeDouble::setTo(rti1516::LogicalTime const & value)
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ _value = p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+rti1516::LogicalTime &
+LogicalTimeDouble::operator=(rti1516::LogicalTime const & value)
+throw (rti1516::InvalidLogicalTime)
+{
+ setTo(value);
+ return *this;
+}
+
+LogicalTimeDouble &
+LogicalTimeDouble::operator=(LogicalTimeDouble const & value)
+throw (rti1516::InvalidLogicalTime)
+{
+ setTo(value);
+ return *this;
+}
+
+
+
+
+
+void LogicalTimeDouble::increaseBy(rti1516::LogicalTimeInterval const & addend)
+throw (rti1516::IllegalTimeArithmetic, rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(addend);
+ _value += p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTimeInterval(L"Invalid
LogicalTimeDouble");
+ }
+}
+
+void LogicalTimeDouble::decreaseBy(rti1516::LogicalTimeInterval const &
subtrahend)
+throw (rti1516::IllegalTimeArithmetic, rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(subtrahend);
+ _value -= p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTimeInterval(L"Invalid
LogicalTimeDouble");
+ }
+
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeDouble::subtract(rti1516::LogicalTime const & subtrahend) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(subtrahend);
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble(_value - p._value));
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeDouble::isGreaterThan(rti1516::LogicalTime const & value) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ return _value > p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeDouble::isLessThan(rti1516::LogicalTime const & value) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ return _value < p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeDouble::isEqualTo(rti1516::LogicalTime const & value) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ return _value == p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeDouble::isGreaterThanOrEqualTo(rti1516::LogicalTime const &
value) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ return _value >= p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeDouble::isLessThanOrEqualTo(rti1516::LogicalTime const &
value) const
+throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& p = dynamic_cast<const
LogicalTimeDouble&>(value);
+ return _value <= p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+long LogicalTimeDouble::getSeconds() const
+{
+ return (long)(_value / MULTIPLIER);
+}
+
+int LogicalTimeDouble::getMicros() const
+{
+ return (int)(_value % MULTIPLIER);
+}
+
+std::wstring LogicalTimeDouble::toString() const
+{
+ wchar_t buf[128];
+ if (_value == MAX_VALUE) {
+ swprintf(buf, 128, L"LogicalTimeDouble<INF>");
+ } else {
+ swprintf(buf, 128, L"LogicalTimeDouble<%d.%06d>", getSeconds(),
getMicros());
+ }
+ return buf;
+}
+
+bool LogicalTimeDouble::operator==(LogicalTime const & lt_left) const
+ throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& left = dynamic_cast<const
LogicalTimeDouble&>(lt_left);
+ return (((left._value - 1000) < _value) && ((left._value +
1000) > _value));
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+int64_t LogicalTimeDouble::toMilliseconds() const
+{
+ return _value/1000;
+}
+
+rti1516::VariableLengthData LogicalTimeDouble::encode() const
+{
+ unsigned char buf[sizeof(_value)];
+ int pos = 0;
+ buf[pos++] = (unsigned char)((_value >> 56) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 48) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 40) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 32) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 24) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 16) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 8) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 0) & 0xFF);
+
+ rti1516::VariableLengthData varData(buf, pos);
+
+ return varData;
+}
+
+unsigned long LogicalTimeDouble::encodedLength() const
+{
+ return 8L;
+}
+
+unsigned long LogicalTimeDouble::encode(void* buffer, unsigned long
bufferSize) const
+ throw (rti1516::CouldNotEncode)
+{
+ unsigned char *buf = (unsigned char*)buffer;
+ int pos = 0;
+ buf[pos++] = (unsigned char)((_value >> 56) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 48) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 40) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 32) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 24) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 16) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 8) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 0) & 0xFF);
+
+ return 8L;
+}
+
+void LogicalTimeDouble::decode(rti1516::VariableLengthData const &
encodedLogicalTime)
+ throw (rti1516::InternalError, rti1516::CouldNotDecode)
+{
+ int64_t value = 0;
+ unsigned char* buf = (unsigned char*)encodedLogicalTime.data();
+ int pos = 0;
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+
+ _value = value;
+}
+
+void LogicalTimeDouble::decode(void* buffer, unsigned long bufferSize)
+ throw (rti1516::InternalError,
+ rti1516::CouldNotDecode)
+{
+ int64_t value = 0;
+ unsigned char* buf = (unsigned char*)buffer;
+ int pos = 0;
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+
+ _value = value;
+}
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+
+LogicalTimeDoubleFactory::~LogicalTimeDoubleFactory()
+throw ()
+{
+}
+
+std::auto_ptr< rti1516::LogicalTime > LogicalTimeDoubleFactory::makeInitial()
+ throw (rti1516::InternalError)
+{
+ return std::auto_ptr< rti1516::LogicalTime >(new
LogicalTimeDouble((int64_t)0));
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeDoubleFactory::makeZero()
+ throw (rti1516::InternalError)
+{
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble((int64_t)0));
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeDoubleFactory::epsilon()
+ throw (rti1516::InternalError)
+{
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble((int64_t)1));
+}
+
+
+LogicalTimeFactoryDouble::~LogicalTimeFactoryDouble()
+throw ()
+{
+}
+
+
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+LogicalTimeIntervalDouble::LogicalTimeIntervalDouble(double value)
+{
+ int64_t seconds = (long)floor(value);
+ int64_t micros = (long)fmod(value * MULTIPLIER, (double)MULTIPLIER);
+
+ _value = seconds * MULTIPLIER + micros;
+}
+
+LogicalTimeIntervalDouble::LogicalTimeIntervalDouble(int64_t value) :
+ _value(value)
+{
+}
+
+LogicalTimeIntervalDouble::~LogicalTimeIntervalDouble()
+ throw ()
+{
+}
+
+void LogicalTimeIntervalDouble::setZero()
+{
+ _value = 0;
+}
+
+bool LogicalTimeIntervalDouble::isZero() const
+{
+ return _value == 0;
+}
+
+void LogicalTimeIntervalDouble::setEpsilon()
+{
+ _value = 1;
+}
+
+bool LogicalTimeIntervalDouble::isEpsilon() const
+{
+ return _value == 1;
+}
+
+long LogicalTimeIntervalDouble::getSeconds() const
+{
+ return (long)(_value / MULTIPLIER);
+}
+
+int LogicalTimeIntervalDouble::getMicros() const
+{
+ return (int)(_value % MULTIPLIER);
+}
+
+void LogicalTimeIntervalDouble::setTo(rti1516::LogicalTimeInterval const &
value)
+ throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ _value = p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
+LogicalTimeIntervalDouble::subtract(rti1516::LogicalTimeInterval const &
subtrahend) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+{
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(subtrahend);
+
+ int64_t d = _value - p._value;
+ if (d < 0) {
+ d = -d;
+ }
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble(d));
+}
+
+bool LogicalTimeIntervalDouble::isGreaterThan(rti1516::LogicalTimeInterval
const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ return _value > p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeIntervalDouble::isLessThan(rti1516::LogicalTimeInterval const
& value) const
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ return _value < p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool LogicalTimeIntervalDouble::isEqualTo(rti1516::LogicalTimeInterval const &
value) const
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ return _value == p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool
LogicalTimeIntervalDouble::isGreaterThanOrEqualTo(rti1516::LogicalTimeInterval
const & value) const
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ return _value >= p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+bool
LogicalTimeIntervalDouble::isLessThanOrEqualTo(rti1516::LogicalTimeInterval
const & value) const
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ try {
+ const LogicalTimeIntervalDouble& p = dynamic_cast<const
LogicalTimeIntervalDouble&>(value);
+ return _value <= p._value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+}
+
+rti1516::VariableLengthData LogicalTimeIntervalDouble::encode() const
+{
+ unsigned char buf[sizeof(_value)];
+ int pos = 0;
+ buf[pos++] = (unsigned char)((_value >> 56) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 48) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 40) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 32) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 24) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 16) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 8) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 0) & 0xFF);
+
+ rti1516::VariableLengthData varData(buf, pos);
+
+ return varData;
+}
+
+unsigned long
+LogicalTimeIntervalDouble::encodedLength() const
+{
+ return 8L;
+}
+unsigned long
+LogicalTimeIntervalDouble::encode(void* buffer, unsigned long bufferSize)
const
+throw (rti1516::CouldNotEncode)
+{
+ if (bufferSize < 8L)
+ {
+ throw rti1516::CouldNotEncode(L"Not enough space to encode
LogicalTimeIntervalDouble");
+ }
+
+ unsigned char *buf = (unsigned char *) buffer;
+ int pos = 0;
+ buf[pos++] = (unsigned char)((_value >> 56) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 48) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 40) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 32) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 24) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 16) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 8) & 0xFF);
+ buf[pos++] = (unsigned char)((_value >> 0) & 0xFF);
+
+ return 8L;
+}
+
+void LogicalTimeIntervalDouble::decode(rti1516::VariableLengthData const &
encodedLogicalTimeInterval)
+throw (rti1516::InternalError, rti1516::CouldNotDecode)
+{
+ if (encodedLogicalTimeInterval.size() < 8L)
+ {
+ throw rti1516::CouldNotDecode(L"Not enough data in
VariableLengthData to decode LogicalTimeIntervalDouble. (Needs 8 bytes)");
+ }
+
+ int64_t value = 0;
+ unsigned char* buf = (unsigned char*)encodedLogicalTimeInterval.data();
+ int pos = 0;
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+
+ _value = value;
+}
+
+
+void
+LogicalTimeIntervalDouble::decode(void* buffer, unsigned long bufferSize)
+throw (rti1516::InternalError,
+ rti1516::CouldNotDecode)
+{
+ if (bufferSize < 8L)
+ {
+ throw rti1516::CouldNotDecode(L"Not enough data in
VariableLengthData to decode LogicalTimeIntervalDouble. (Needs 8 bytes)");
+ }
+ int64_t value = 0;
+ unsigned char* buf = (unsigned char*)buffer;
+ int pos = 0;
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+
+ _value = value;
+}
+
+
+std::wstring LogicalTimeIntervalDouble::toString() const
+{
+ wchar_t buf[128];
+ swprintf(buf, 128, L"LogicalTimeIntervalDouble<%d.%06d>", getSeconds(),
getMicros());
+ return buf;
+}
+
+
+void
+LogicalTimeIntervalDouble::setToDifference(rti1516::LogicalTime const &
minuend,
+
rti1516::LogicalTime const& subtrahend)
+
throw (rti1516::InvalidLogicalTime)
+{
+ try {
+ const LogicalTimeDouble& d_minuend = dynamic_cast<const
LogicalTimeDouble&>(minuend);
+ const LogicalTimeDouble& d_subtrahend = dynamic_cast<const
LogicalTimeDouble&>(subtrahend);
+
+ int64_t value = d_minuend.toMilliseconds() -
d_subtrahend.toMilliseconds();
+ if (value < 0) {
+ value = -value;
+ }
+ _value = value;
+ } catch (std::bad_cast)
+ {
+ throw rti1516::InvalidLogicalTime(L"Invalid LogicalTimeDouble");
+ }
+
+}
+
+rti1516::LogicalTimeInterval &
+LogicalTimeIntervalDouble::operator+=(rti1516::LogicalTimeInterval const &
addend)
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ return *this;
+}
+
+rti1516::LogicalTimeInterval &
+LogicalTimeIntervalDouble::operator-=(rti1516::LogicalTimeInterval const &
subtrahend)
+throw (rti1516::InvalidLogicalTimeInterval)
+{
+ return *this;
+}
+
+
+
+
+
+
+
+LogicalTimeIntervalDoubleFactory::~LogicalTimeIntervalDoubleFactory()
+ throw ()
+{
+}
+
+
+
+/*
+LogicalTimeIntervalFactoryDouble::~LogicalTimeIntervalFactoryDouble()
+ throw ()
+{
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeIntervalFactoryDouble::makeZero()
+ throw (rti1516::InternalError)
+{
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble((int64_t)0));
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeIntervalFactoryDouble::epsilon()
+ throw (rti1516::InternalError)
+{
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble((int64_t)1));
+}
+
+std::auto_ptr< rti1516::LogicalTimeInterval >
LogicalTimeIntervalFactoryDouble::decode(rti1516::EncodedLogicalTimeInterval
const & encodedLogicalTimeInterval)
+ // throw (InternalError, CouldNotDecode)
+ throw ()
+{
+ int64_t value = 0;
+ unsigned char* buf = (unsigned char*)encodedLogicalTimeInterval.data();
+ int pos = 0;
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ value = (value << 8) | buf[pos++];
+ return std::auto_ptr< rti1516::LogicalTimeInterval >(new
LogicalTimeIntervalDouble(value));
+}
+*/
Index: LogicalTimeDouble.h
===================================================================
RCS file: LogicalTimeDouble.h
diff -N LogicalTimeDouble.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LogicalTimeDouble.h 31 May 2010 11:58:27 -0000 1.1
@@ -0,0 +1,415 @@
+#ifndef LogicalTimeDouble_INCLUDED
+#define LogicalTimeDouble_INCLUDED
+
+#ifdef _WIN32
+#pragma warning(disable:4290)
+#endif
+
+// Standard integer types.
+#ifdef _MSC_VER
+#ifndef FAKED_INTTYPES_DEFINED
+#define FAKED_INTTYPES_DEFINED
+typedef unsigned __int64 uint64_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int8 int8_t;
+typedef short int int_least16_t;
+#endif
+#else
+#include <inttypes.h>
+#endif
+
+#include "RTI/certiLogicalTime.h"
+#include "RTI/certiLogicalTimeInterval.h"
+#include "RTI/certiLogicalTimeFactory.h"
+
+// Microsoft has not implemented the swprintf function according
+// to the ISO C standard. However, they have a function _snwprintf
+// that matches the standardized prototype for swprintf.
+#ifdef _WIN32
+#define swprintf _snwprintf
+#endif
+
+class RTI_EXPORT_FEDTIME LogicalTimeDouble : public rti1516::LogicalTime
+{
+public:
+ LogicalTimeDouble(double value);
+
+ virtual ~LogicalTimeDouble()
+ throw ();
+
+ virtual void setInitial();
+
+ virtual bool isInitial() const;
+
+ virtual void setFinal();
+
+ virtual bool isFinal() const;
+
+ virtual long getSeconds() const;
+ virtual int getMicros() const;
+
+ virtual void setTo(rti1516::LogicalTime const & value)
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual void increaseBy(rti1516::LogicalTimeInterval const & addend)
+ throw (rti1516::IllegalTimeArithmetic,
rti1516::InvalidLogicalTimeInterval);
+
+ virtual void decreaseBy(rti1516::LogicalTimeInterval const & subtrahend)
+ throw (rti1516::IllegalTimeArithmetic,
rti1516::InvalidLogicalTimeInterval);
+
+ virtual std::auto_ptr< rti1516::LogicalTimeInterval >
subtract(rti1516::LogicalTime const & subtrahend) const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual bool isGreaterThan(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual bool isLessThan(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual bool isEqualTo(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual bool isGreaterThanOrEqualTo(rti1516::LogicalTime const & value)
const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual bool isLessThanOrEqualTo(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime);
+
+ // JvY Begin
+ virtual
+ rti1516::LogicalTime &
+ operator=(rti1516::LogicalTime const & value)
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual
+ LogicalTimeDouble &
+ operator=(LogicalTimeDouble const & value)
+ throw (rti1516::InvalidLogicalTime);
+
+
+ virtual
+ rti1516::LogicalTime &
+ operator+=(rti1516::LogicalTimeInterval const & addend)
+ throw (rti1516::IllegalTimeArithmetic,
rti1516::InvalidLogicalTimeInterval)
+ {
+ increaseBy(addend);
+ return *this;
+ }
+
+ virtual
+ rti1516::LogicalTime &
+ operator-=(rti1516::LogicalTimeInterval const & subtrahend)
+ throw (rti1516::IllegalTimeArithmetic,
rti1516::InvalidLogicalTimeInterval)
+ {
+ decreaseBy(subtrahend);
+ return *this;
+ }
+
+ virtual
+ bool
+ operator>(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime)
+ {
+ return isGreaterThan(value);
+ }
+
+ virtual
+ bool
+ operator<(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime)
+ {
+ return isLessThan(value);
+ }
+
+ virtual
+ bool
+ operator>=(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime)
+ {
+ return isGreaterThanOrEqualTo(value);
+ }
+
+ virtual
+ bool
+ operator<=(rti1516::LogicalTime const & value) const
+ throw (rti1516::InvalidLogicalTime)
+ {
+ return isLessThanOrEqualTo(value);
+ }
+
+ // Generates an encoded value that can be used to send
+ // LogicalTimes to other federates in updates or interactions
+ virtual rti1516::VariableLengthData encode() const;
+
+ // Alternate encode for directly filling a buffer
+ virtual unsigned long encodedLength() const;
+ virtual unsigned long encode(void* buffer, unsigned long bufferSize) const
+ throw (rti1516::CouldNotEncode);
+
+ // Decode encodedLogicalTime into self
+ virtual void decode(rti1516::VariableLengthData const & encodedLogicalTime)
+ throw (rti1516::InternalError,
+ rti1516::CouldNotDecode);
+
+ // Alternate decode that reads directly from a buffer
+ virtual void decode(void* buffer, unsigned long bufferSize)
+ throw (rti1516::InternalError,
+ rti1516::CouldNotDecode);
+
+ // Returns the name of the implementation, as needed by
+ // createFederationExecution.
+ virtual std::wstring implementationName() const
+ {
+ return L"BITS_LogicalTimeDouble";
+ }
+
+ // JvY End
+
+ //virtual std::auto_ptr< rti1516::EncodedLogicalTime > encode() const;
+
+ virtual std::wstring toString() const;
+
+ virtual bool operator==(LogicalTime const & left) const
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual int64_t toMilliseconds() const;
+
+private:
+ explicit LogicalTimeDouble(int64_t value);
+
+ int64_t _value;
+
+ friend class LogicalTimeDoubleFactory;
+ friend class LogicalTimeFactoryDouble;
+};
+
+class RTI_EXPORT_FEDTIME LogicalTimeIntervalDouble : public
rti1516::LogicalTimeInterval
+{
+public:
+ LogicalTimeIntervalDouble(double value);
+
+ virtual ~LogicalTimeIntervalDouble()
+ throw ();
+
+ virtual void setZero();
+
+ virtual bool isZero() const;
+
+ virtual void setEpsilon();
+
+ virtual bool isEpsilon() const;
+
+ virtual long getSeconds() const;
+ virtual int getMicros() const;
+
+ virtual void setTo(rti1516::LogicalTimeInterval const & value)
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual std::auto_ptr< rti1516::LogicalTimeInterval >
subtract(rti1516::LogicalTimeInterval const & subtrahend) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual bool isGreaterThan(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual bool isLessThan(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual bool isEqualTo(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual bool isGreaterThanOrEqualTo(rti1516::LogicalTimeInterval const &
value) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual bool isLessThanOrEqualTo(rti1516::LogicalTimeInterval const &
value) const
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ //virtual std::auto_ptr< rti1516::EncodedLogicalTimeInterval > encode()
const;
+
+ virtual std::wstring toString() const;
+
+ // JvY Begin
+ virtual
+ LogicalTimeInterval &
+ operator=(rti1516::LogicalTimeInterval const & value)
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ setTo(value);
+ return *this;
+ }
+
+
+ // Set self to the difference between two LogicalTimes
+ virtual
+ void
+ setToDifference(rti1516::LogicalTime const & minuend,
+ rti1516::LogicalTime const& subtrahend)
+ throw (rti1516::InvalidLogicalTime);
+
+ virtual
+ rti1516::LogicalTimeInterval &
+ operator+=(rti1516::LogicalTimeInterval const & addend)
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual
+ rti1516::LogicalTimeInterval &
+ operator-=(rti1516::LogicalTimeInterval const & subtrahend)
+ throw (rti1516::InvalidLogicalTimeInterval);
+
+ virtual
+ bool
+ operator>(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ return isGreaterThan(value);
+ }
+
+ virtual
+ bool
+ operator<(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ return isLessThan(value);
+ }
+
+ virtual
+ bool
+ operator==(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ return isEqualTo(value);
+ }
+
+ virtual
+ bool
+ operator>=(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ return isGreaterThanOrEqualTo(value);
+ }
+
+ virtual
+ bool
+ operator<=(rti1516::LogicalTimeInterval const & value) const
+ throw (rti1516::InvalidLogicalTimeInterval)
+ {
+ return isLessThanOrEqualTo(value);
+ }
+
+ // Generates an encoded value that can be used to send
+ // LogicalTimeIntervals to other federates in updates or interactions
+ virtual rti1516::VariableLengthData encode() const;
+
+ // Alternate encode for directly filling a buffer
+ virtual unsigned long encodedLength() const;
+ virtual unsigned long encode(void* buffer, unsigned long bufferSize) const
+ throw (rti1516::CouldNotEncode);
+
+ // Decode encodedValue into self
+ virtual void decode(rti1516::VariableLengthData const & encodedValue)
+ throw (rti1516::InternalError,
+ rti1516::CouldNotDecode);
+
+ // Alternate decode that reads directly from a buffer
+ virtual void decode(void* buffer, unsigned long bufferSize)
+ throw (rti1516::InternalError,
+ rti1516::CouldNotDecode);
+
+ // Returns the name of the implementation, as needed by
+ // createFederationExecution.
+ virtual std::wstring implementationName() const
+ {
+ return L"BITS_LogicalTimeIntervalDouble";
+ }
+
+ // JvY End
+
+private:
+ explicit LogicalTimeIntervalDouble(int64_t value);
+
+ int64_t _value;
+
+ friend class LogicalTimeDouble;
+ friend class LogicalTimeDoubleFactory;
+ friend class LogicalTimeFactoryDouble;
+ friend class LogicalTimeIntervalDoubleFactory;
+ friend class LogicalTimeIntervalFactoryDouble;
+};
+
+
+class RTI_EXPORT_FEDTIME LogicalTimeDoubleFactory : public
rti1516::LogicalTimeFactory
+{
+public:
+ virtual ~LogicalTimeDoubleFactory()
+ throw ();
+
+ virtual std::auto_ptr< rti1516::LogicalTime > makeInitial()
+ throw (rti1516::InternalError);
+
+ // Returns a LogicalTime with a value of "initial"
+ virtual
+ std::auto_ptr< rti1516::LogicalTime >
+ makeLogicalTime()
+ throw (rti1516::InternalError)
+ {
+ return makeInitial();
+ }
+
+ // Returns a LogicalTimeInterval with a value of "zero"
+ virtual
+ std::auto_ptr< rti1516::LogicalTimeInterval >
+ makeLogicalTimeInterval()
+ throw (rti1516::InternalError)
+ {
+ return makeZero();
+ }
+
+ virtual std::auto_ptr< rti1516::LogicalTimeInterval > makeZero()
+ throw (rti1516::InternalError);
+
+ virtual std::auto_ptr< rti1516::LogicalTimeInterval > epsilon()
+ throw (rti1516::InternalError);
+
+ //virtual std::auto_ptr< rti1516::LogicalTime >
decode(rti1516::EncodedLogicalTime const & encodedLogicalTime)
+ // throw (rti1516::InternalError, rti1516::CouldNotDecode);
+};
+
+class RTI_EXPORT_FEDTIME LogicalTimeFactoryDouble : public
LogicalTimeDoubleFactory
+{
+public:
+ virtual ~LogicalTimeFactoryDouble()
+ throw ();
+
+};
+
+class RTI_EXPORT_FEDTIME LogicalTimeIntervalDoubleFactory : public
LogicalTimeDoubleFactory
+{
+public:
+ virtual ~LogicalTimeIntervalDoubleFactory()
+ throw ();
+
+};
+
+class RTI_EXPORT_FEDTIME LogicalTimeIntervalFactoryDouble : public
LogicalTimeDoubleFactory
+{
+public:
+ virtual ~LogicalTimeIntervalFactoryDouble()
+ throw ()
+ {
+ }
+
+};
+
+class RTI_EXPORT_FEDTIME LogicalTimeDoubleFactoryFactory : public
rti1516::LogicalTimeFactoryFactory
+{
+public:
+ static std::auto_ptr< rti1516::LogicalTimeFactory >
+ makeLogicalTimeFactory(std::wstring const & implementationName);
+
+};
+
+#endif // LogicalTimeDouble_INCLUDED
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi/libRTI CMakeLists.txt LogicalTimeDouble.c...,
certi-cvs <=