TimeStamp.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 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 #ifndef ICL_CORE_TIME_STAMP_H_INCLUDED
31 #define ICL_CORE_TIME_STAMP_H_INCLUDED
32 
33 #include "icl_core/ImportExport.h"
34 #include "icl_core/TimeSpan.h"
35 
36 #if defined(_IC_BUILDER_BOOST_DATE_TIME_)
37 // Forward declaration
38 namespace boost {
39 namespace posix_time {
40 class ptime;
41 }
42 }
43 #endif
44 
45 #ifdef _IC_BUILDER_OPENSPLICEDDS_
46 namespace DDS {
47 struct Time_t;
48 }
49 #endif
50 
51 namespace icl_core {
52 
53 #ifdef _IC_BUILDER_OPENSPLICEDDS_
54 struct iTimeStamp;
55 #endif
56 
58 
62 {
63 public:
66  : TimeBase()
67  { }
68 
70  //TimeStamp(timeval time) { secs = time.tv_sec; nsecs = time.tv_usec * 1000; }
71 
74  : TimeBase(sec, nsec)
75  { }
76 
77  TimeStamp(const struct timespec& ts)
78  : TimeBase(ts)
79  { }
80 
81  explicit TimeStamp(time_t timestamp)
82  : TimeBase(uint64_t(timestamp), 0)
83  { }
84 
85 #ifdef _IC_BUILDER_OPENSPLICEDDS_
86  TimeStamp(const DDS::Time_t& time_stamp);
88 
90  TimeStamp(const iTimeStamp& time_stamp);
91 
93  TimeStamp& operator = (const DDS::Time_t& time_stamp);
94 
96  TimeStamp& operator = (const iTimeStamp& time_stamp);
97 
99  operator DDS::Time_t ();
100 
102  operator iTimeStamp ();
103 #endif
104 
105 #if defined(_IC_BUILDER_BOOST_DATE_TIME_)
106  TimeStamp(const boost::posix_time::ptime& ptime_stamp);
108 
110  TimeStamp& operator = (const boost::posix_time::ptime& ptime_stamp);
111 #endif
112 
116  static TimeStamp now();
117 
119  static TimeStamp futureMSec(uint64_t msec);
120 
124  static TimeStamp fromIso8601BasicUTC(const String& str);
125 
127  TimeStamp& fromNow();
128 
136  void strfTime(char* dest, size_t max_len, const char *format) const;
144  void strfLocaltime(char* dest, size_t max_len, const char *format) const;
153  String formatIso8601() const;
161  String formatIso8601UTC() const;
170  String formatIso8601Basic() const;
179  String formatIso8601BasicUTC() const;
180 
182 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
183 
189 
194 
199 
200  ICL_CORE_VC_DEPRECATE_STYLE void Strftime(char* dest, size_t max_len, const char *format) const
202 
203  ICL_CORE_VC_DEPRECATE_STYLE void StrfLocaltime(char* dest, size_t max_len, const char *format) const
205 
206  ICL_CORE_VC_DEPRECATE_STYLE String FormatIso8601() const
208 
209 #endif
210 
213  TimeStamp& operator += (const TimeSpan& span)
214  {
215  secs+=span.secs;
216  nsecs+=span.nsecs;
217  normalizeTime();
218  return *this;
219  }
220 
222  TimeStamp& operator -= (const TimeSpan& span)
223  {
224  secs-=span.secs;
225  nsecs-=span.nsecs;
226  normalizeTime();
227  return *this;
228  }
229 
233  bool operator != (const TimeStamp& other) const
234  {
235  return TimeBase::operator != (other);
236  }
237 
241  bool operator == (const TimeStamp& other) const
242  {
243  return TimeBase::operator == (other);
244  }
245 
250  bool operator < (const TimeStamp& other) const
251  {
252  return TimeBase::operator < (other);
253  }
254 
258  bool operator > (const TimeStamp& other) const
259  {
260  return TimeBase::operator > (other);
261  }
262 
267  bool operator <= (const TimeStamp& other) const
268  {
269  return TimeBase::operator <= (other);
270  }
271 
276  bool operator >= (const TimeStamp& other) const
277  {
278  return TimeBase::operator >= (other);
279  }
280 
281  uint64_t tsSec() const { return secs; }
282  uint32_t tsUSec() const { return nsecs/1000; }
283  uint32_t tsNSec() const { return nsecs; }
284 
286  {
287  return TimeStamp(TimeBase::maxTime());
288  }
289 
290  using TimeBase::days;
291  using TimeBase::hours;
292  using TimeBase::minutes;
293  using TimeBase::seconds;
294  using TimeBase::milliSeconds;
295  using TimeBase::microSeconds;
296  using TimeBase::nanoSeconds;
297 
298  using TimeBase::timespec;
299  using TimeBase::systemTimespec;
300 
301 #ifdef _SYSTEM_DARWIN_
302  using TimeBase::machTimespec;
303 #endif
304 
306 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
307 
311 
313 
314  using TimeBase::Days;
315  using TimeBase::Hours;
316  using TimeBase::Minutes;
317  using TimeBase::Seconds;
318  using TimeBase::MilliSeconds;
319  using TimeBase::MicroSeconds;
320  using TimeBase::NanoSeconds;
321 
322  using TimeBase::Timespec;
323  using TimeBase::SystemTimespec;
324 
325 #ifdef _SYSTEM_DARWIN_
326  using TimeBase::MachTimespec;
327 #endif
328 
329 #endif
330 
332  static const TimeStamp cZERO;
333 
334 private:
335  TimeStamp(const TimeBase &base)
336  : TimeBase(base)
337  { }
338 
339  TimeStamp& operator += (const TimeStamp& other);
340 };
341 
342 
343 inline TimeStamp operator + (const TimeSpan& span, const TimeStamp& time)
344 {
345  TimeStamp a(time);
346  return a += span;
347 }
348 
349 inline TimeStamp operator + (const TimeStamp& time, const TimeSpan& span)
350 {
351  TimeStamp a(time);
352  return a += span;
353 }
354 
355 inline TimeStamp operator - (const TimeStamp& time, const TimeSpan& span)
356 {
357  TimeStamp a(time);
358  return a -= span;
359 }
360 
361 inline TimeSpan operator - (const TimeStamp& time_1, const TimeStamp& time_2)
362 {
363  TimeSpan a(time_1.tsSec()-time_2.tsSec(), time_1.tsNSec()-time_2.tsNSec());
364  return a;
365 }
366 
367 }
368 #endif
unsigned int uint32_t
Definition: msvc_stdint.h:93
Represents absolute times.
Definition: TimeStamp.h:61
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
uint32_t tsUSec() const
Definition: TimeStamp.h:282
TimeStamp operator+(const TimeStamp &time, const TimeSpan &span)
Definition: TimeStamp.h:349
TimeStamp(const TimeBase &base)
Definition: TimeStamp.h:335
uint32_t tsNSec() const
Definition: TimeStamp.h:283
#define ICL_CORE_IMPORT_EXPORT
Definition: ImportExport.h:42
unsigned __int64 uint64_t
Definition: msvc_stdint.h:103
Repesents time values.
Definition: TimeBase.h:59
bool operator==(const ThreadId &left, const ThreadId &right)
TimeSpan operator-(const TimeStamp &time_1, const TimeStamp &time_2)
Definition: TimeStamp.h:361
Contains import/export definitions for the Win32 plattform.
Repesents absolute times.
Definition: TimeSpan.h:46
std::string String
Definition: BaseTypes.h:43
static const TimeStamp cZERO
Definition: TimeStamp.h:332
uint64_t tsSec() const
Definition: TimeStamp.h:281
TimeStamp(const struct timespec &ts)
Definition: TimeStamp.h:77
TimeStamp()
Standard constructor, creates a null time.
Definition: TimeStamp.h:65
static TimeStamp maxTime()
Definition: TimeStamp.h:285
TimeStamp(uint64_t sec, uint32_t nsec)
Constructor, takes a timeval for creation.
Definition: TimeStamp.h:73
TimeStamp(time_t timestamp)
Definition: TimeStamp.h:81
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


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