simpletime.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 SCHUNK GmbH & Co. KG
00003  * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *   http://www.apache.org/licenses/LICENSE-2.0
00010 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 //======================================================================
00045 //======================================================================
00046 
00047 #ifndef SIMPLETIME_H_
00048 #define SIMPLETIME_H_
00049 
00050 #include "sdhlibrary_settings.h"
00051 
00052 //----------------------------------------------------------------------
00053 // System Includes - include with <>
00054 //----------------------------------------------------------------------
00055 
00056 #if SDH_USE_VCC
00057 #include <sys/timeb.h>
00058 #include <time.h>
00059 #else
00060 # include <sys/time.h>
00061 #endif
00062 
00063 //----------------------------------------------------------------------
00064 // Project Includes - include with ""
00065 //----------------------------------------------------------------------
00066 
00067 #include "sdhexception.h"
00068 
00069 //----------------------------------------------------------------------
00070 // Defines, enums, unions, structs,
00071 //----------------------------------------------------------------------
00072 
00073 NAMESPACE_SDH_START
00074 
00075 
00076 //----------------------------------------------------------------------
00077 // Global variables
00078 //----------------------------------------------------------------------
00079 
00080 
00081 //----------------------------------------------------------------------
00082 // Function declarations
00083 //----------------------------------------------------------------------
00084 
00085 
00086 //----------------------------------------------------------------------
00087 // Class declarations
00088 //----------------------------------------------------------------------
00089 
00090 #if SDH_USE_VCC
00091 typedef long        tTimevalSec;
00092 typedef long        tTimevalUSec;
00093 #else
00094 typedef time_t      tTimevalSec;
00095 typedef suseconds_t tTimevalUSec;
00096 #endif
00097 
00101 class VCC_EXPORT cSimpleTime
00102 {
00103 protected:
00104 #if SDH_USE_VCC
00105   struct _timeb timebuffer;
00106 #else
00107   struct timeval a_time;
00108 #endif
00109 
00110 public:
00112   cSimpleTime()
00113   {
00114     StoreNow();
00115   }
00116   //----------------------------------------------------------------------
00117 
00118 
00120   void StoreNow(void)
00121   {
00122 #if SDH_USE_VCC
00123     _ftime64_s(&timebuffer);
00124 
00125 #else
00126     gettimeofday(&a_time, NULL);
00127 #endif
00128   }
00129   //----------------------------------------------------------------------
00130 
00132   double Elapsed(void) const
00133   {
00134     cSimpleTime now;
00135 
00136     return Elapsed(now);
00137   }
00138   //----------------------------------------------------------------------
00139 
00140 
00142   long Elapsed_us(void) const
00143   {
00144     cSimpleTime now;
00145 
00146     return Elapsed_us(now);
00147   }
00148   //----------------------------------------------------------------------
00149 
00150 
00151 #if SDH_USE_VCC
00152 
00153   double Elapsed(cSimpleTime const& other) const
00154   {
00155     double seconds = double(other.timebuffer.time - timebuffer.time);
00156     double msec = double(other.timebuffer.millitm - timebuffer.millitm);
00157 
00158     return seconds + msec / 1000.0;
00159   }
00160   //----------------------------------------------------------------------
00161 
00163   long Elapsed_us(cSimpleTime const& other) const
00164   {
00165     long seconds = long(other.timebuffer.time - timebuffer.time);
00166     long msec    = long(other.timebuffer.millitm - timebuffer.millitm);
00167 
00168     return seconds * 1000000 + msec * 1000;
00169   }
00170   //----------------------------------------------------------------------
00171 #else
00172 
00173   double Elapsed(cSimpleTime const& other) const
00174   {
00175     double seconds = double(other.a_time.tv_sec - a_time.tv_sec);
00176     double usec = double(other.a_time.tv_usec - a_time.tv_usec);
00177 
00178     return seconds + usec / 1000000.0;
00179   }
00180   //----------------------------------------------------------------------
00181 
00183   long Elapsed_us(cSimpleTime const& other) const
00184   {
00185     long seconds = other.a_time.tv_sec - a_time.tv_sec;
00186     long usec    = other.a_time.tv_usec - a_time.tv_usec;
00187 
00188     return seconds * 1000000 + usec;
00189   }
00190   //----------------------------------------------------------------------
00191 
00192 
00194   timeval Timeval(void)
00195   {
00196     return a_time;
00197   }
00198 #endif
00199 };
00200 
00201 
00202 NAMESPACE_SDH_END
00203 
00204 #endif
00205 
00206 
00207 //======================================================================
00208 /*
00209   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00210   (e.g. to explicitely set C++ mode for *.h header files)
00211 
00212   Local Variables:
00213   mode:C++
00214   mode:ELSE
00215   End:
00216 */
00217 //======================================================================


schunk_sdh
Author(s): Mathias Luedtke , Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:21