Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <ecl/config.hpp>
00013 #if defined(ECL_IS_POSIX)
00014
00015
00016
00017
00018
00019 #include <sstream>
00020 #include <errno.h>
00021 #include <sys/time.h>
00022 #include <ecl/config/ecl.hpp>
00023 #include <ecl/time_lite/functions.hpp>
00024 #include "../../include/ecl/time/timestamp_pos.hpp"
00025 #include <ecl/exceptions/macros.hpp>
00026
00027
00028
00029
00030
00031 namespace ecl {
00032
00033
00034
00035
00036
00037 TimeStamp::TimeStamp() ecl_debug_throw_decl(StandardException) {
00038 stamp();
00039 }
00040
00041 TimeStamp::TimeStamp (const double& decimal_time_value) ecl_assert_throw_decl(StandardException) :
00042 TimeStampBase(decimal_time_value)
00043 {}
00044
00045 TimeStamp::TimeStamp (const time_t& seconds, const long& nanoseconds) ecl_assert_throw_decl(StandardException) :
00046 TimeStampBase(seconds, nanoseconds)
00047 {}
00048
00049 TimeStamp::TimeStamp(const TimeStampBase& base) : TimeStampBase(base) {}
00050
00051
00052
00053
00054
00055 const TimeStamp& TimeStamp::stamp() ecl_debug_throw_decl(StandardException) {
00056 if ( epoch_time(time).flag() != NoError ) {
00057 ecl_debug_throw(time::throwTimeStampException(LOC));
00058 }
00059 return (*this);
00060 }
00061
00062 #if defined(ECL_HAS_RT_TIMERS)
00063 TimeStamp TimeStamp::realtime_now() ecl_debug_throw_decl(StandardException) {
00064 TimeStructure time;
00065 if ( realtime_epoch_time(time).flag() != NoError ) {
00066 ecl_debug_throw(time::throwTimeStampException(LOC));
00067 }
00068 return TimeStamp(time.tv_sec, time.tv_nsec);
00069 }
00070 #endif
00071 };
00072
00073
00074
00075
00076
00077 #ifdef ECL_HAS_EXCEPTIONS
00078 namespace ecl {
00079 namespace time {
00080
00081 StandardException throwTimeStampException(const char* loc) {
00082 int error_result = errno;
00083 switch (error_result) {
00084 case ( EINVAL ) : return ecl::StandardException(loc, ecl::NotSupportedError, "The requested clock is not supported on this system.");
00085 case ( EFAULT ) : return ecl::StandardException(loc, ecl::OutOfRangeError, "The timespec pointer points outside the address space.");
00086 default :
00087 {
00088 std::ostringstream ostream;
00089 ostream << "Unknown posix error " << error_result << ": " << strerror(error_result) << ".";
00090 return StandardException(loc, ecl::UnknownError, ostream.str());
00091 }
00092 }
00093 }
00094
00095 };
00096 };
00097
00098 #endif
00099 #endif