File: igtlTimeStamp.h

package info (click to toggle)
openigtlink 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 20,076; ansic: 6,704; sh: 227; perl: 74; makefile: 46
file content (121 lines) | stat: -rw-r--r-- 3,343 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*=========================================================================

  Program:   The OpenIGTLink Library
  Language:  C++
  Web page:  http://openigtlink.org/

  Copyright (c) Insight Software Consortium. All rights reserved.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#ifndef __igtlTimeStamp_h
#define __igtlTimeStamp_h

#include "igtlMacro.h"
#include "igtlObject.h"
#include "igtlObjectFactory.h"
#include "igtlTypes.h"

#if defined(WIN32) || defined(_WIN32)
#include <ctime>
#endif

namespace igtl
{

class IGTLCommon_EXPORT TimeStamp : public Object
{
public:
  typedef TimeStamp                  Self;
  typedef Object                     Superclass;
  typedef SmartPointer< Self >       Pointer;
  typedef SmartPointer< const Self > ConstPointer;

  igtlTypeMacro(TimeStamp, Object);
  igtlNewMacro(Self);

  /// Gets the frequency of a clock.
  igtlGetConstMacro(Frequency,  igtlUint32);

  /// Gets the second part of the time stamp.
  igtlGetConstMacro(Second,     igtlUint32);

  /// Gets the fraction of second part of the time stamp.
  igtlGetConstMacro(Nanosecond, igtlUint32);

  /// Gets the current time from the system's clock and save it as a time stamp.
  void   GetTime();

  /// Sets the time by double floating-point value.
  void   SetTime(double tm);

  /// Sets the time by second and nanosecond
  void   SetTime(igtlUint32 second, igtlUint32 nanosecond);

  /// Sets the time by using 64-bit fixed-point expression used in OpenIGTLink.
  void   SetTime(igtlUint64 tm);

  /// Sets the time using the total number of nano-seconds since the start of time (Unix Epoch = 1 Jan 1970).
  /// Note: This is deliberately different to SetTime();
  void SetTimeInNanoseconds(igtlUint64 tm);

  /// Gets the time stamp. Returns a double floating-point value.
  double GetTimeStamp();

  /// Gets the time stamp. The second and nanosecond parts are stored in 'second' and 'nanosecond'
  void   GetTimeStamp(igtlUint32* second, igtlUint32* nanosecond);

  /// Gets the time stamp. Returns a 64-bit fixed-point expression used in OpenIGTLink.
  igtlUint64 GetTimeStampUint64();

  /// Gets the time in nano-seconds since the start of time (Unix Epoch = 1 Jan 1970).
  /// Note: This is deliberately different to GetTimeStampUint64();
  igtlUint64 GetTimeStampInNanoseconds() const;

protected:

  /** constructor */
  TimeStamp();

  /** destructor */
  virtual ~TimeStamp();

  /** Print the object information in a stream. */
  virtual void PrintSelf( std::ostream& os) const;

private:

  /// Clock frequency (Hz)
  igtlInt32       m_Frequency;

  /// Second part of the time relative to 00:00:00 January 1, 1970 UTC
  igtlInt32       m_Second;

  /// Nano-second part of the time stamp
  igtlInt32       m_Nanosecond;


#if defined(WIN32) || defined(_WIN32)
  //typedef double        TimeStampType;
  //typedef double        FrequencyType;
  //
  //FrequencyType   m_WinFrequency;
  //TimeStampType   m_WinDifference;
  //TimeStampType   m_WinOrigin;

  time_t  m_WinTimeOrigin;
  clock_t m_WinClockOrigin;

#endif

};

} // end of namespace igtl

#endif  // __igtlTimeStamp_h