TimeStamp.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00029 //----------------------------------------------------------------------
00030 #ifndef ICL_CORE_TIME_STAMP_H_INCLUDED
00031 #define ICL_CORE_TIME_STAMP_H_INCLUDED
00032 
00033 #include "icl_core/ImportExport.h"
00034 #include "icl_core/TimeSpan.h"
00035 
00036 #if defined(_IC_BUILDER_BOOST_DATE_TIME_)
00037 // Forward declaration
00038 namespace boost {
00039 namespace posix_time {
00040 class ptime;
00041 }
00042 }
00043 #endif
00044 
00045 #ifdef _IC_BUILDER_OPENSPLICEDDS_
00046 namespace DDS {
00047 struct Time_t;
00048 }
00049 #endif
00050 
00051 namespace icl_core {
00052 
00053 #ifdef _IC_BUILDER_OPENSPLICEDDS_
00054 struct iTimeStamp;
00055 #endif
00056 
00058 
00061 class ICL_CORE_IMPORT_EXPORT TimeStamp : protected TimeBase
00062 {
00063 public:
00065   TimeStamp()
00066     : TimeBase()
00067   { }
00068 
00070   //TimeStamp(timeval time) { secs = time.tv_sec; nsecs = time.tv_usec * 1000; }
00071 
00073   TimeStamp(uint64_t sec, uint32_t nsec)
00074     : TimeBase(sec, nsec)
00075   { }
00076 
00077   TimeStamp(const struct timespec& ts)
00078     : TimeBase(ts)
00079   { }
00080 
00081   explicit TimeStamp(time_t timestamp)
00082     : TimeBase(uint64_t(timestamp), 0)
00083   { }
00084 
00085 #ifdef _IC_BUILDER_OPENSPLICEDDS_
00086 
00087   TimeStamp(const DDS::Time_t& time_stamp);
00088 
00090   TimeStamp(const iTimeStamp& time_stamp);
00091 
00093   TimeStamp& operator = (const DDS::Time_t& time_stamp);
00094 
00096   TimeStamp& operator = (const iTimeStamp& time_stamp);
00097 
00099   operator DDS::Time_t ();
00100 
00102   operator iTimeStamp ();
00103 #endif
00104 
00105 #if defined(_IC_BUILDER_BOOST_DATE_TIME_)
00106 
00107   TimeStamp(const boost::posix_time::ptime& ptime_stamp);
00108 
00110   TimeStamp& operator = (const boost::posix_time::ptime& ptime_stamp);
00111 #endif
00112 
00116   static TimeStamp now();
00117 
00119   static TimeStamp futureMSec(uint64_t msec);
00120 
00124   static TimeStamp fromIso8601BasicUTC(const String& str);
00125 
00127   TimeStamp& fromNow();
00128 
00136   void strfTime(char* dest, size_t max_len, const char *format) const;
00144   void strfLocaltime(char* dest, size_t max_len, const char *format) const;
00153   String formatIso8601() const;
00161   String formatIso8601UTC() const;
00170   String formatIso8601Basic() const;
00179   String formatIso8601BasicUTC() const;
00180 
00182 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00183 
00188   static ICL_CORE_VC_DEPRECATE_STYLE TimeStamp Now() ICL_CORE_GCC_DEPRECATE_STYLE;
00189 
00193   static ICL_CORE_VC_DEPRECATE_STYLE TimeStamp FutureMSec(uint64_t msec) ICL_CORE_GCC_DEPRECATE_STYLE;
00194 
00198   ICL_CORE_VC_DEPRECATE_STYLE TimeStamp& FromNow() ICL_CORE_GCC_DEPRECATE_STYLE;
00199 
00200   ICL_CORE_VC_DEPRECATE_STYLE void Strftime(char* dest, size_t max_len, const char *format) const
00201     ICL_CORE_GCC_DEPRECATE_STYLE;
00202 
00203   ICL_CORE_VC_DEPRECATE_STYLE void StrfLocaltime(char* dest, size_t max_len, const char *format) const
00204     ICL_CORE_GCC_DEPRECATE_STYLE;
00205 
00206   ICL_CORE_VC_DEPRECATE_STYLE String FormatIso8601() const
00207     ICL_CORE_GCC_DEPRECATE_STYLE;
00208 
00209 #endif
00210 
00211 
00213   TimeStamp& operator += (const TimeSpan& span)
00214   {
00215     secs+=span.secs;
00216     nsecs+=span.nsecs;
00217     normalizeTime();
00218     return *this;
00219   }
00220 
00222   TimeStamp& operator -= (const TimeSpan& span)
00223   {
00224     secs-=span.secs;
00225     nsecs-=span.nsecs;
00226     normalizeTime();
00227     return *this;
00228   }
00229 
00233   bool operator != (const TimeStamp& other) const
00234   {
00235     return TimeBase::operator != (other);
00236   }
00237 
00241   bool operator == (const TimeStamp& other) const
00242   {
00243     return TimeBase::operator == (other);
00244   }
00245 
00250   bool operator < (const TimeStamp& other) const
00251   {
00252     return TimeBase::operator < (other);
00253   }
00254 
00258   bool operator > (const TimeStamp& other) const
00259   {
00260     return TimeBase::operator > (other);
00261   }
00262 
00267   bool operator <= (const TimeStamp& other) const
00268   {
00269     return TimeBase::operator <= (other);
00270   }
00271 
00276   bool operator >= (const TimeStamp& other) const
00277   {
00278     return TimeBase::operator >= (other);
00279   }
00280 
00281   uint64_t tsSec() const { return secs; }
00282   uint32_t tsUSec() const { return nsecs/1000; }
00283   uint32_t tsNSec() const { return nsecs; }
00284 
00285   static TimeStamp maxTime()
00286   {
00287     return TimeStamp(TimeBase::maxTime());
00288   }
00289 
00290   using TimeBase::days;
00291   using TimeBase::hours;
00292   using TimeBase::minutes;
00293   using TimeBase::seconds;
00294   using TimeBase::milliSeconds;
00295   using TimeBase::microSeconds;
00296   using TimeBase::nanoSeconds;
00297 
00298   using TimeBase::timespec;
00299   using TimeBase::systemTimespec;
00300 
00301 #ifdef _SYSTEM_DARWIN_
00302   using TimeBase::machTimespec;
00303 #endif
00304 
00306 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00307 
00308   ICL_CORE_VC_DEPRECATE_STYLE uint64_t TsSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00309   ICL_CORE_VC_DEPRECATE_STYLE uint32_t TsUSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00310   ICL_CORE_VC_DEPRECATE_STYLE uint32_t TsNSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00311 
00312   static ICL_CORE_VC_DEPRECATE_STYLE TimeStamp MaxTime() ICL_CORE_GCC_DEPRECATE_STYLE;
00313 
00314   using TimeBase::Days;
00315   using TimeBase::Hours;
00316   using TimeBase::Minutes;
00317   using TimeBase::Seconds;
00318   using TimeBase::MilliSeconds;
00319   using TimeBase::MicroSeconds;
00320   using TimeBase::NanoSeconds;
00321 
00322   using TimeBase::Timespec;
00323   using TimeBase::SystemTimespec;
00324 
00325 #ifdef _SYSTEM_DARWIN_
00326   using TimeBase::MachTimespec;
00327 #endif
00328 
00329 #endif
00330 
00331 
00332   static const TimeStamp cZERO;
00333 
00334 private:
00335   TimeStamp(const TimeBase &base)
00336     : TimeBase(base)
00337   { }
00338 
00339   TimeStamp& operator += (const TimeStamp& other);
00340 };
00341 
00342 
00343 inline TimeStamp operator + (const TimeSpan& span, const TimeStamp& time)
00344 {
00345   TimeStamp a(time);
00346   return a += span;
00347 }
00348 
00349 inline TimeStamp operator + (const TimeStamp& time, const TimeSpan& span)
00350 {
00351   TimeStamp a(time);
00352   return a += span;
00353 }
00354 
00355 inline TimeStamp operator - (const TimeStamp& time, const TimeSpan& span)
00356 {
00357   TimeStamp a(time);
00358   return a -= span;
00359 }
00360 
00361 inline TimeSpan operator - (const TimeStamp& time_1, const TimeStamp& time_2)
00362 {
00363   TimeSpan a(time_1.tsSec()-time_2.tsSec(), time_1.tsNSec()-time_2.tsNSec());
00364   return a;
00365 }
00366 
00367 }
00368 #endif


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24