2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
27#include "data_management/GraphTreeObject.h"
28#include "logging/SimLogger.h"
31#define NSEC_PER_SEC_D 1000000000.0
32#define MSEC_PER_SEC_I 1000
33#define NSEC_PER_MSEC_I 1000000
34#define NSEC_PER_SEC_I 1000000000
35#define NSEC_MAX 999999999
48 Time() {_tspec.tv_sec = 0; _tspec.tv_nsec = 0;
_loggable=
true;}
49 Time(
const struct timespec &t) {_tspec = t;
_loggable=
true;}
50 Time(
long unsigned int sec,
long unsigned int nsec=0) {_tspec.tv_sec=sec; _tspec.tv_nsec=nsec;
_loggable=
true;}
55 void setTime(
const struct timespec &t) {_tspec = t;}
59 void stepTime(
const unsigned long long &nsec);
62 const timespec&
asTimespec()
const {
return _tspec;}
63 double asDouble()
const {
return (
double)_tspec.tv_sec + ((
double)_tspec.tv_nsec)/
NSEC_PER_SEC_D;}
65 std::string asString()
const {
return std::to_string(_tspec.tv_sec) +
":" + std::to_string(_tspec.tv_nsec);}
77 int log(
void* logger) {
79 log_ptr->writeToBuffer(asDouble());
125 struct timespec _tspec;
#define NSEC_PER_SEC_D
Definition Time.h:31
#define MSEC_PER_SEC_I
Definition Time.h:32
#define NSEC_PER_MSEC_I
Definition Time.h:33
Base class for object organization.
Definition GraphTreeObject.h:87
bool _loggable
Variable to indicate whether the selected object is loggable. Set to false by default.
Definition GraphTreeObject.h:257
Class for logging data to a file.
Definition SimLogger.h:67
Wrapper to manage and convert time as timespce.
Definition Time.h:45
void setTime(const struct timespec &t)
Function to set the time in the time object.
Definition Time.h:55
bool operator<=(const Time &B) const
Overloaded operator to compare two time objects.
Definition Time.cpp:159
int divide(unsigned int d, Time &res) const
Function to get half of a struct timespec.
Definition Time.cpp:100
bool operator==(const Time &B) const
Overloaded operator to compare two time objects.
Definition Time.cpp:173
int add(const Time &a, Time &res) const
Function to add two times together a + b.
Definition Time.cpp:59
void stepTime(const unsigned long long &nsec)
Function to step time forward by a set amount of nanoseconds.
Definition Time.cpp:23
bool operator>(const Time &B) const
Overloaded operator to compare two time objects.
Definition Time.cpp:117
const timespec & asTimespec() const
Functions to return various time formats.
Definition Time.h:62
bool operator<(const Time &B) const
Overloaded operator to compare two time objects.
Definition Time.cpp:131
Time()
Default, copy constructors and default destructor.
Definition Time.h:48
void fromFrequency(unsigned int rate_hz)
Function to set a time object from a frequency, in Hz.
Definition Time.cpp:35
int subtract(const Time &b, Time &res) const
Function to subtract a - b = res.
Definition Time.cpp:74
bool operator>=(const Time &B) const
Overloaded operator to compare two time objects.
Definition Time.cpp:145
std::vector< std::string > header_info() const
Function to write header data from our Time class.
Definition Time.h:85
void fromDouble(double val)
Function to set a time object from double.
Definition Time.cpp:48
int log(void *logger)
Function to log data from our Time class.
Definition Time.h:77
#define NO_ERROR
Definition clockwerkerrors.h:31