LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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 ( void  )

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: