LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst::ap::TimeSpec Class Reference

Wraps the C library timespec struct. More...

#include <Time.h>

Inheritance diagram for lsst::ap::TimeSpec:

Public Member Functions

 TimeSpec ()
 
 TimeSpec (double const seconds)
 
TimeSpecoperator+= (TimeSpec const &ts)
 
TimeSpecoperator-= (TimeSpec const &ts)
 
TimeSpecoperator= (double const seconds)
 
TimeSpecoperator+= (double const seconds)
 
TimeSpecoperator-= (double const seconds)
 
double seconds () const
 
TimeSpecnow ()
 
TimeSpecsystemTime ()
 

Detailed Description

Wraps the C library timespec struct.

Definition at line 48 of file Time.h.

Constructor & Destructor Documentation

lsst::ap::TimeSpec::TimeSpec ( )
inline

Definition at line 52 of file Time.h.

52  {
53  tv_sec = 0;
54  tv_nsec = 0;
55  }
lsst::ap::TimeSpec::TimeSpec ( double const  seconds)

Definition at line 62 of file Time.cc.

62  {
63  time_t const sec = DoubleToTime::convert(seconds);
64  tv_sec = sec;
65  tv_nsec = static_cast<long>((seconds - static_cast<double>(sec))*1e9);
66 }
double seconds() const
Definition: Time.h:87

Member Function Documentation

TimeSpec & lsst::ap::TimeSpec::now ( )

Sets the TimeSpec to the number of seconds and nanoseconds that have elapsed since some arbitrary point in the past.

Definition at line 93 of file Time.cc.

93  {
94 #if LSST_AP_HAVE_CLOCK_GETTIME
95 # if defined(CLOCK_MONOTONIC)
96  clock_gettime(CLOCK_MONOTONIC, this);
97 # elif defined(CLOCK_HIGHRES)
98  clock_gettime(CLOCK_HIGHRES, this);
99 # else
100  clock_gettime(CLOCK_REALTIME, this); // Use system clock if nothing else is available
101 # endif
102  return *this;
103 #else
104  return systemTime();
105 #endif
106 }
TimeSpec & systemTime()
Definition: Time.cc:113
TimeSpec& lsst::ap::TimeSpec::operator+= ( TimeSpec const &  ts)
inline

Definition at line 59 of file Time.h.

59  {
60  tv_sec += ts.tv_sec;
61  tv_nsec += ts.tv_nsec;
62  if (tv_nsec >= 1000000000l) {
63  tv_nsec -= 1000000000l;
64  ++tv_sec;
65  }
66  return *this;
67  }
TimeSpec & lsst::ap::TimeSpec::operator+= ( double const  seconds)

Definition at line 77 of file Time.cc.

77  {
78  time_t const sec = DoubleToTime::convert(seconds);
79  tv_sec += sec;
80  tv_nsec += static_cast<long>((seconds - static_cast<double>(sec))*1e9);
81  if (tv_nsec >= 1000000000l) {
82  tv_nsec -= 1000000000l;
83  ++tv_sec;
84  }
85  return *this;
86 }
double seconds() const
Definition: Time.h:87
TimeSpec& lsst::ap::TimeSpec::operator-= ( TimeSpec const &  ts)
inline

Definition at line 69 of file Time.h.

69  {
70  tv_sec -= ts.tv_sec;
71  tv_nsec -= ts.tv_nsec;
72  if (tv_nsec < 0l) {
73  tv_nsec += 1000000000l;
74  --tv_sec;
75  }
76  return *this;
77  }
TimeSpec& lsst::ap::TimeSpec::operator-= ( double const  seconds)
inline

Definition at line 83 of file Time.h.

83  {
84  return operator+=(-seconds);
85  }
double seconds() const
Definition: Time.h:87
TimeSpec & operator+=(TimeSpec const &ts)
Definition: Time.h:59
TimeSpec & lsst::ap::TimeSpec::operator= ( double const  seconds)

Definition at line 69 of file Time.cc.

69  {
70  time_t const sec = DoubleToTime::convert(seconds);
71  tv_sec = sec;
72  tv_nsec = static_cast<long>((seconds - static_cast<double>(sec))*1e9);
73  return *this;
74 }
double seconds() const
Definition: Time.h:87
double lsst::ap::TimeSpec::seconds ( ) const
inline

Definition at line 87 of file Time.h.

87  {
88  return static_cast<double>(tv_sec) + static_cast<double>(tv_nsec)/1e9;
89  }
TimeSpec & lsst::ap::TimeSpec::systemTime ( )

Sets the TimeSpec to the number of seconds and nanoseconds that have elapsed since midnight (0 hour), January 1, 1970.

Definition at line 113 of file Time.cc.

113  {
114  ::timeval tv;
115  ::gettimeofday(&tv, 0);
116  tv_sec = tv.tv_sec;
117  tv_nsec = tv.tv_usec*1000l;
118  return *this;
119 }

The documentation for this class was generated from the following files: