Time.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031
00032 #include "Time.hpp"
00033
00034 #include <string>
00035 #include <sstream>
00036
00037 using namespace mermaid::support::system;
00038
00039
00040 #ifdef ACE_SYSTEM
00041 #include <ace/Date_Time.h>
00042
00043 Time::Time() : ACE_Time_Value()
00044 {
00045
00046 };
00047
00048 Time::Time (long sec, long usec) : ACE_Time_Value (sec, usec)
00049 {
00050
00051 };
00052
00053 Time::Time (const ACE_Time_Value &time_value) : ACE_Time_Value (time_value)
00054 {
00055
00056 };
00057
00058 Time Time::operator() (const ACE_Time_Value &time_value)
00059 {
00060 return Time (time_value);
00061 };
00062
00063 const Time Time::operator- (Time& otherTime)
00064 {
00065 ACE_Time_Value delta = ( (ACE_Time_Value) * this) - ( (ACE_Time_Value) otherTime);
00066 return Time (delta);
00067 };
00068
00069 const std::string Time::toString()
00070 {
00071 std::stringstream ss;
00072 ss.fill ('0');
00073
00074 ss << this->sec();
00075 ss << ":";
00076 ss.fill ('0');
00077 ss.width (6);
00078 ss << this->usec();
00079 return ss.str();
00080 };
00081
00082 Time Time::getCurrentTime()
00083 {
00084 return Time (ACE_OS::gettimeofday());
00085 };
00086
00087 Time Time::getTimeFromString (std::string timeString)
00088 {
00089 std::stringstream ss (timeString);
00090
00091 long sec = 0;
00092 long usec = 0;
00093
00094 ss >> sec;
00095 ss.get();
00096 ss >> usec;
00097
00098 return Time (sec, usec);
00099 };
00100
00101 #endif // ACE_SYSTEM