00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2010 00004 * 00005 * Fraunhofer Institute for Manufacturing Engineering 00006 * and Automation (IPA) 00007 * 00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: care-o-bot 00011 * ROS stack name: cob_driver 00012 * ROS package name: cob_powercube_chain 00013 * Description: 00014 * 00015 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00016 * 00017 * Author: Felix Geibel, email:Felix.Geibel@gmx.de 00018 * Supervised by: Alexander Bubeck, email:alexander.bubeck@ipa.fhg.de 00019 * 00020 * Date of creation: Aug 2007 00021 * ToDo: 00022 * 00023 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 * 00025 * Redistribution and use in source and binary forms, with or without 00026 * modification, are permitted provided that the following conditions are met: 00027 * 00028 * * Redistributions of source code must retain the above copyright 00029 * notice, this list of conditions and the following disclaimer. 00030 * * Redistributions in binary form must reproduce the above copyright 00031 * notice, this list of conditions and the following disclaimer in the 00032 * documentation and/or other materials provided with the distribution. 00033 * * Neither the name of the Fraunhofer Institute for Manufacturing 00034 * Engineering and Automation (IPA) nor the names of its 00035 * contributors may be used to endorse or promote products derived from 00036 * this software without specific prior written permission. 00037 * 00038 * This program is free software: you can redistribute it and/or modify 00039 * it under the terms of the GNU Lesser General Public License LGPL as 00040 * published by the Free Software Foundation, either version 3 of the 00041 * License, or (at your option) any later version. 00042 * 00043 * This program is distributed in the hope that it will be useful, 00044 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00045 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00046 * GNU Lesser General Public License LGPL for more details. 00047 * 00048 * You should have received a copy of the GNU Lesser General Public 00049 * License LGPL along with this program. 00050 * If not, see <http://www.gnu.org/licenses/>. 00051 * 00052 ****************************************************************/ 00053 00054 #ifndef _TimeStamp_H 00055 #define _TimeStamp_H 00056 00057 #ifdef __LINUX__ 00058 #include <time.h> 00059 #else 00060 #include <windows.h> 00061 #ifdef _DEBUG 00062 //#define new DEBUG_NEW 00063 #undef THIS_FILE 00064 static char THIS_FILE[] = __FILE__; 00065 #endif 00066 namespace RTB { 00067 00068 #endif 00069 00070 //------------------------------------------------------------------- 00071 00072 00078 class TimeStamp 00079 { 00080 public: 00082 TimeStamp(); 00083 00085 virtual ~TimeStamp() {}; 00086 00088 void SetNow(); 00089 00091 double operator-(const TimeStamp& EarlierTime) const; 00092 00094 00096 void operator+=(double TimeS); 00097 00099 00101 void operator-=(double TimeS); 00102 00104 bool operator>(const TimeStamp& Time); 00105 00107 bool operator<(const TimeStamp& Time); 00108 00112 void getTimeStamp(long& lSeconds, long& lNanoSeconds); 00113 00117 void setTimeStamp(const long& lSeconds, const long& lNanoSeconds); 00118 00119 00120 protected: 00121 00123 #ifdef __LINUX__ 00124 timespec m_TimeStamp; 00125 #else 00126 LARGE_INTEGER m_TimeStamp; 00127 #endif 00128 00129 private: 00130 00132 #ifdef __LINUX__ 00133 static double TimespecToDouble(const ::timespec& LargeInt); 00134 00136 static ::timespec DoubleToTimespec(double TimeS); 00137 #else 00138 static double LargeIntToDouble(const LARGE_INTEGER& LargeInt); 00139 00141 static LARGE_INTEGER DoubleToLargeInt(double TimeS); 00142 00144 static double m_DwordSize; 00145 00147 static double m_SecPerCount; 00148 #endif 00149 00150 }; 00151 00152 #ifdef __LINUX__ 00153 #else 00154 }//namespace 00155 #endif 00156 #endif 00157