Program Listing for File timeStamp.h¶
↰ Return to documentation for file (src/property/pv/timeStamp.h)
/* timeStamp.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef TIMESTAMP_H
#define TIMESTAMP_H
#include <ctime>
#include <epicsTime.h>
#include <shareLib.h>
#include <pv/pvType.h>
namespace epics { namespace pvData {
epicsShareExtern const int32 milliSecPerSec;
epicsShareExtern const int32 microSecPerSec;
epicsShareExtern const int32 nanoSecPerSec;
epicsShareExtern const int64 posixEpochAtEpicsEpoch;
class epicsShareClass TimeStamp {
public:
TimeStamp()
:secondsPastEpoch(0), nanoseconds(0), userTag(0) {}
TimeStamp(int64 secondsPastEpoch,int32 nanoseconds = 0,int64 userTag = 0);
//default constructors and destructor are OK
//This class should not be extended
void normalize();
void fromTime_t(const time_t & time);
void toTime_t(time_t &time) const;
int64 getSecondsPastEpoch() const {return secondsPastEpoch;}
int64 getEpicsSecondsPastEpoch() const {
return secondsPastEpoch - posixEpochAtEpicsEpoch;
}
int32 getNanoseconds() const {return nanoseconds;}
int64 getUserTag() const {return userTag;}
void setUserTag(int64 userTag) {this->userTag = userTag;}
void put(int64 secondsPastEpoch,int32 nanoseconds = 0) {
this->secondsPastEpoch = secondsPastEpoch;
this->nanoseconds = nanoseconds;
normalize();
}
void put(int64 milliseconds);
void getCurrent();
double toSeconds() const ;
bool operator==(TimeStamp const &) const;
bool operator!=(TimeStamp const &) const;
bool operator<=(TimeStamp const &) const;
bool operator< (TimeStamp const &) const;
bool operator>=(TimeStamp const &) const;
bool operator> (TimeStamp const &) const;
static double diff(TimeStamp const & a,TimeStamp const & b);
TimeStamp & operator+=(int64 seconds);
TimeStamp & operator-=(int64 seconds);
TimeStamp & operator+=(double seconds);
TimeStamp & operator-=(double seconds);
int64 getMilliseconds();
private:
static int64 diffInt(TimeStamp const &left,TimeStamp const &right );
int64 secondsPastEpoch;
int32 nanoseconds;
int64 userTag;
};
}}
#endif /* TIMESTAMP_H */