TimeSpan.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 #ifndef ICL_CORE_TIME_SPAN_H_INCLUDED
25 #define ICL_CORE_TIME_SPAN_H_INCLUDED
26 
27 #include <iostream>
28 
29 #include "icl_core/ImportExport.h"
30 #include "icl_core/TimeBase.h"
31 
32 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
33 # include "icl_core/Deprecate.h"
34 #endif
35 
36 namespace icl_core {
37 
38 #ifdef _IC_BUILDER_OPENSPLICEDDS_
39 struct iTimeSpan;
40 #endif
41 
43 
47 {
48  friend class TimeStamp;
49 public:
50 
55  explicit TimeSpan(int64_t sec=0, int32_t nsec=0);
56 
58  TimeSpan(const struct timespec& time_span);
59 
60 #ifdef _IC_BUILDER_OPENSPLICEDDS_
61  TimeSpan(const iTimeSpan& time_span);
64  TimeSpan& operator = (const iTimeSpan& time_span);
66  operator iTimeSpan ();
67 #endif
68 
70  TimeSpan& fromSec(int64_t sec);
72  TimeSpan& fromMSec(int64_t msec);
74  TimeSpan& fromUSec(int64_t usec);
75 
77  static TimeSpan createFromSec(int64_t sec);
79  static TimeSpan createFromMSec(int64_t msec);
81  static TimeSpan createFromUSec(int64_t usec);
82 
84  TimeSpan& operator += (const TimeSpan& span);
85 
87  TimeSpan& operator -= (const TimeSpan& span);
88 
92  bool operator != (const TimeSpan& other) const;
93 
97  bool operator == (const TimeSpan& other) const;
98 
103  bool operator < (const TimeSpan& other) const;
104 
108  bool operator > (const TimeSpan& other) const;
109 
114  bool operator <= (const TimeSpan& other) const;
115 
120  bool operator >= (const TimeSpan& other) const;
121 
122  int64_t tsSec() const;
123  int32_t tsNSec() const;
124  int32_t tsUSec() const;
125 
127  int64_t toMSec() const;
128 
130  int64_t toUSec() const;
131 
135  int64_t toNSec() const;
136 
137  using TimeBase::days;
138  using TimeBase::hours;
139  using TimeBase::minutes;
140  using TimeBase::seconds;
143  using TimeBase::nanoSeconds;
144 
145  using TimeBase::timespec;
146 
147  /* Remark: TimeBase has a systemTimespec() function, which is also
148  * available in TimeStamp. However, TimeSpan does not need this
149  * function because it represents a relative time. Therefore the
150  * systemTimespec() function, which performs a transformation
151  * between two "absolute zero points" (system and global time), does
152  * not make any sense with the relative TimeSpan!
153  */
154 
155 #ifdef _SYSTEM_DARWIN_
156  using TimeBase::machTimespec;
157 #endif
158 
159  static const TimeSpan cZERO;
160 
162 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
163 
165 
167 
169 
170  ICL_CORE_VC_DEPRECATE_STYLE int64_t TsSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
171  ICL_CORE_VC_DEPRECATE_STYLE int32_t TsNSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
172  ICL_CORE_VC_DEPRECATE_STYLE int32_t TsUSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
173 
174  ICL_CORE_VC_DEPRECATE_STYLE int64_t ToMSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
175 
176  ICL_CORE_VC_DEPRECATE_STYLE int64_t ToUSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
177 
178  ICL_CORE_VC_DEPRECATE_STYLE int64_t ToNSec() const ICL_CORE_GCC_DEPRECATE_STYLE;
179 
180  using TimeBase::Days;
181  using TimeBase::Hours;
182  using TimeBase::Minutes;
183  using TimeBase::Seconds;
184  using TimeBase::MilliSeconds;
185  using TimeBase::MicroSeconds;
186  using TimeBase::NanoSeconds;
187 
188  using TimeBase::Timespec;
189 
190 #ifdef _SYSTEM_DARWIN_
191  using TimeBase::MachTimespec;
192 #endif
193 
194 #endif
195 };
197 
198 inline TimeSpan operator + (const TimeSpan& left, const TimeSpan& right)
199 {
200  TimeSpan a(left.tsSec() + right.tsSec(), left.tsNSec() + right.tsNSec());
201  return a;
202 }
203 
204 inline TimeSpan operator - (const TimeSpan& left, const TimeSpan& right)
205 {
206  TimeSpan a(left.tsSec() - right.tsSec(), left.tsNSec() - right.tsNSec());
207  return a;
208 }
209 
210 inline TimeSpan operator / (const TimeSpan& span, double divisor)
211 {
212  TimeSpan a(int64_t(span.tsSec() / divisor), int32_t(span.tsNSec() / divisor));
213  return a;
214 }
215 
216 inline TimeSpan operator * (const TimeSpan& span, double divisor)
217 {
218  TimeSpan a(int64_t(span.tsSec() * divisor), int32_t(span.tsNSec() * divisor));
219  return a;
220 }
221 
222 inline TimeSpan abs(const TimeSpan& span)
223 {
224  if (span < TimeSpan::cZERO)
225  {
226  return TimeSpan::cZERO - span;
227  }
228  else
229  {
230  return span;
231  }
232 }
233 
235 ICL_CORE_IMPORT_EXPORT std::ostream& operator << (std::ostream& stream, const TimeSpan& time_span);
236 
238 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
239 
240 inline TimeSpan Abs(const TimeSpan& span) ICL_CORE_GCC_DEPRECATE_STYLE;
241 ICL_CORE_VC_DEPRECATE_STYLE inline TimeSpan Abs(const TimeSpan& span)
242 {
243  return abs(span);
244 }
245 
246 #endif
247 
249 }
250 
251 #endif
TimeSpan operator+(const TimeSpan &left, const TimeSpan &right)
Definition: TimeSpan.h:198
signed int int32_t
Definition: msvc_stdint.h:90
Represents absolute times.
Definition: TimeStamp.h:61
int32_t nanoSeconds() const
Definition: TimeBase.h:155
std::ostream & operator<<(std::ostream &os, StampedBase const &stamped)
Definition: DataHeader.cpp:27
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
int32_t milliSeconds() const
Definition: TimeBase.h:139
int64_t minutes() const
Definition: TimeBase.h:123
int64_t days() const
Use this function if you want to express the time in days.
Definition: TimeBase.h:107
TimeSpan abs(const TimeSpan &span)
Definition: TimeSpan.h:222
Contains macros to deprecate classes, types, functions and variables.
static const TimeSpan cZERO
Definition: TimeSpan.h:159
Contains TimeBase.
#define ICL_CORE_IMPORT_EXPORT
Definition: ImportExport.h:42
signed __int64 int64_t
Definition: msvc_stdint.h:102
int32_t tsNSec() const
Definition: TimeSpan.cpp:153
TimeSpan operator/(const TimeSpan &span, double divisor)
Definition: TimeSpan.h:210
struct timespec timespec() const
Definition: TimeBase.cpp:113
Repesents time values.
Definition: TimeBase.h:59
bool operator==(const ThreadId &left, const ThreadId &right)
TimeSpan operator-(const TimeSpan &left, const TimeSpan &right)
Definition: TimeSpan.h:204
int32_t microSeconds() const
Definition: TimeBase.h:147
Contains import/export definitions for the Win32 plattform.
Repesents absolute times.
Definition: TimeSpan.h:46
int64_t tsSec() const
Definition: TimeSpan.cpp:148
int64_t hours() const
Definition: TimeBase.h:115
TimeSpan operator*(const TimeSpan &span, double divisor)
Definition: TimeSpan.h:216
int64_t seconds() const
Definition: TimeBase.h:131
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58