TimeSpan.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 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00023 //----------------------------------------------------------------------
00024 #ifndef ICL_CORE_TIME_SPAN_H_INCLUDED
00025 #define ICL_CORE_TIME_SPAN_H_INCLUDED
00026 
00027 #include <iostream>
00028 
00029 #include "icl_core/ImportExport.h"
00030 #include "icl_core/TimeBase.h"
00031 
00032 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00033 # include "icl_core/Deprecate.h"
00034 #endif
00035 
00036 namespace icl_core {
00037 
00038 #ifdef _IC_BUILDER_OPENSPLICEDDS_
00039 struct iTimeSpan;
00040 #endif
00041 
00043 
00046 class ICL_CORE_IMPORT_EXPORT TimeSpan : protected TimeBase
00047 {
00048   friend class TimeStamp;
00049 public:
00050 
00055   explicit TimeSpan(int64_t sec=0, int32_t nsec=0);
00056 
00058   TimeSpan(const struct timespec& time_span);
00059 
00060 #ifdef _IC_BUILDER_OPENSPLICEDDS_
00061 
00062   TimeSpan(const iTimeSpan& time_span);
00064   TimeSpan& operator = (const iTimeSpan& time_span);
00066   operator iTimeSpan ();
00067 #endif
00068 
00070   TimeSpan& fromSec(int64_t sec);
00072   TimeSpan& fromMSec(int64_t msec);
00074   TimeSpan& fromUSec(int64_t usec);
00075 
00077   static TimeSpan createFromSec(int64_t sec);
00079   static TimeSpan createFromMSec(int64_t msec);
00081   static TimeSpan createFromUSec(int64_t usec);
00082 
00084   TimeSpan& operator += (const TimeSpan& span);
00085 
00087   TimeSpan& operator -= (const TimeSpan& span);
00088 
00092   bool operator != (const TimeSpan& other) const;
00093 
00097   bool operator == (const TimeSpan& other) const;
00098 
00103   bool operator < (const TimeSpan& other) const;
00104 
00108   bool operator > (const TimeSpan& other) const;
00109 
00114   bool operator <= (const TimeSpan& other) const;
00115 
00120   bool operator >= (const TimeSpan& other) const;
00121 
00122   int64_t tsSec() const;
00123   int32_t tsNSec() const;
00124   int32_t tsUSec() const;
00125 
00127   int64_t toMSec() const;
00128 
00130   int64_t toUSec() const;
00131 
00135   int64_t toNSec() const;
00136 
00137   using TimeBase::days;
00138   using TimeBase::hours;
00139   using TimeBase::minutes;
00140   using TimeBase::seconds;
00141   using TimeBase::milliSeconds;
00142   using TimeBase::microSeconds;
00143   using TimeBase::nanoSeconds;
00144 
00145   using TimeBase::timespec;
00146 
00147   /* Remark: TimeBase has a systemTimespec() function, which is also
00148    * available in TimeStamp.  However, TimeSpan does not need this
00149    * function because it represents a relative time.  Therefore the
00150    * systemTimespec() function, which performs a transformation
00151    * between two "absolute zero points" (system and global time), does
00152    * not make any sense with the relative TimeSpan!
00153    */
00154 
00155 #ifdef _SYSTEM_DARWIN_
00156   using TimeBase::machTimespec;
00157 #endif
00158 
00159   static const TimeSpan cZERO;
00160 
00162 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00163 
00164   ICL_CORE_VC_DEPRECATE_STYLE TimeSpan& FromSec(int64_t sec) ICL_CORE_GCC_DEPRECATE_STYLE;
00165 
00166   ICL_CORE_VC_DEPRECATE_STYLE TimeSpan& FromMSec(int64_t msec) ICL_CORE_GCC_DEPRECATE_STYLE;
00167 
00168   ICL_CORE_VC_DEPRECATE_STYLE TimeSpan& FromUSec(int64_t usec) ICL_CORE_GCC_DEPRECATE_STYLE;
00169 
00170   ICL_CORE_VC_DEPRECATE_STYLE int64_t TsSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00171   ICL_CORE_VC_DEPRECATE_STYLE int32_t TsNSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00172   ICL_CORE_VC_DEPRECATE_STYLE int32_t TsUSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00173 
00174   ICL_CORE_VC_DEPRECATE_STYLE int64_t ToMSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00175 
00176   ICL_CORE_VC_DEPRECATE_STYLE int64_t ToUSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00177 
00178   ICL_CORE_VC_DEPRECATE_STYLE int64_t ToNSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
00179 
00180   using TimeBase::Days;
00181   using TimeBase::Hours;
00182   using TimeBase::Minutes;
00183   using TimeBase::Seconds;
00184   using TimeBase::MilliSeconds;
00185   using TimeBase::MicroSeconds;
00186   using TimeBase::NanoSeconds;
00187 
00188   using TimeBase::Timespec;
00189 
00190 #ifdef _SYSTEM_DARWIN_
00191   using TimeBase::MachTimespec;
00192 #endif
00193 
00194 #endif
00195 
00196 };
00197 
00198 inline TimeSpan operator + (const TimeSpan& left, const TimeSpan& right)
00199 {
00200   TimeSpan a(left.tsSec() + right.tsSec(), left.tsNSec() + right.tsNSec());
00201   return a;
00202 }
00203 
00204 inline TimeSpan operator - (const TimeSpan& left, const TimeSpan& right)
00205 {
00206   TimeSpan a(left.tsSec() - right.tsSec(), left.tsNSec() - right.tsNSec());
00207   return a;
00208 }
00209 
00210 inline TimeSpan operator / (const TimeSpan& span, double divisor)
00211 {
00212   TimeSpan a(int64_t(span.tsSec() / divisor), int32_t(span.tsNSec() / divisor));
00213   return a;
00214 }
00215 
00216 inline TimeSpan operator * (const TimeSpan& span, double divisor)
00217 {
00218   TimeSpan a(int64_t(span.tsSec() * divisor), int32_t(span.tsNSec() * divisor));
00219   return a;
00220 }
00221 
00222 inline TimeSpan abs(const TimeSpan& span)
00223 {
00224   if (span < TimeSpan::cZERO)
00225   {
00226     return TimeSpan::cZERO - span;
00227   }
00228   else
00229   {
00230     return span;
00231   }
00232 }
00233 
00235 ICL_CORE_IMPORT_EXPORT std::ostream& operator << (std::ostream& stream, const TimeSpan& time_span);
00236 
00238 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00239 
00240 inline TimeSpan Abs(const TimeSpan& span) ICL_CORE_GCC_DEPRECATE_STYLE;
00241 ICL_CORE_VC_DEPRECATE_STYLE inline TimeSpan Abs(const TimeSpan& span)
00242 {
00243   return abs(span);
00244 }
00245 
00246 #endif
00247 
00248 
00249 }
00250 
00251 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19