Time.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename Time.cpp
00024  * @Description Time  implementation
00025  * @Status Work in Progress
00026  * @Version $Id: Time.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
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 //     ss.width(6);
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
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3