timestamp_pos.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Platform Check
00010 *****************************************************************************/
00011 
00012 #include <ecl/config.hpp>
00013 #if defined(ECL_IS_POSIX)
00014 
00015 /*****************************************************************************
00016 ** Includes
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 ** Namespaces
00029 *****************************************************************************/
00030 
00031 namespace ecl {
00032 
00033 /*****************************************************************************
00034 ** Implementation [TimeStamp]
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 ** Implementation [Stamps]
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 }; // namespace ecl
00062 
00063 /*****************************************************************************
00064 ** Implementation [Exceptions]
00065 *****************************************************************************/
00066 
00067 #ifdef ECL_HAS_EXCEPTIONS
00068 namespace ecl {
00069 namespace time {
00070 
00071 StandardException throwTimeStampException(const char* loc) {
00072         int error_result = errno;
00073     switch (error_result) {
00074         case ( EINVAL ) : return ecl::StandardException(loc, ecl::NotSupportedError, "The requested clock is not supported on this system.");
00075         case ( EFAULT ) : return ecl::StandardException(loc, ecl::OutOfRangeError, "The timespec pointer points outside the address space.");
00076         default         :
00077         {
00078                         std::ostringstream ostream;
00079                         ostream << "Unknown posix error " << error_result << ": " << strerror(error_result) << ".";
00080                         return StandardException(loc, ecl::UnknownError, ostream.str());
00081                 }
00082     }
00083 }
00084 
00085 }; // namespace time
00086 }; // namespace ecl
00087 
00088 #endif /* ECL_HAS_EXCEPTIONS */
00089 #endif /* ECL_IS_POSIX */


ecl_time
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:43