25 #ifndef STTCLPOSIXTIME_H_
26 #define STTCLPOSIXTIME_H_
27 #if defined(STTCL_POSIX_TIME) or defined(STTCL_POSIX_IMPL)
42 class SttclPosixTimeDuration
45 typedef struct timespec NativeTimeDuration;
47 SttclPosixTimeDuration(
unsigned int argHours = 0,
unsigned int argMinutes = 0,
unsigned int argSeconds = 0,
unsigned int argMilliSeconds = 0,
unsigned long argMicroSeconds = 0,
unsigned long argNanoSeconds = 0)
49 setNative(argHours,argMinutes,argSeconds,argMilliSeconds,argMicroSeconds,argNanoSeconds);
51 SttclPosixTimeDuration(
const SttclPosixTimeDuration& rhs)
53 td.tv_sec = rhs.td.tv_sec;
54 td.tv_nsec = rhs.td.tv_nsec;
56 SttclPosixTimeDuration(
const NativeTimeDuration& nativeTimeDuration)
58 td.tv_sec = nativeTimeDuration.tv_sec;
59 td.tv_nsec = nativeTimeDuration.tv_nsec;
61 ~SttclPosixTimeDuration()
65 SttclPosixTimeDuration& operator=(
const SttclPosixTimeDuration& rhs)
67 td.tv_sec = rhs.td.tv_sec;
68 td.tv_nsec = rhs.td.tv_nsec;
72 bool operator==(
const SttclPosixTimeDuration& rhs)
const
74 return td.tv_sec == rhs.td.tv_sec &&
75 td.tv_nsec == rhs.td.tv_nsec;
78 bool operator!=(
const SttclPosixTimeDuration& rhs)
const
80 return !operator==(rhs);
83 bool operator<(
const SttclPosixTimeDuration& rhs)
const
85 return td.tv_sec < rhs.td.tv_sec ||
86 (td.tv_sec == rhs.td.tv_sec &&
87 td.tv_nsec < rhs.td.tv_nsec);
90 bool operator<=(
const SttclPosixTimeDuration& rhs)
const
92 return operator==(rhs) || operator<(rhs);
95 bool operator>(
const SttclPosixTimeDuration& rhs)
const
97 return td.tv_sec > rhs.td.tv_sec ||
98 (td.tv_sec == rhs.td.tv_sec &&
99 td.tv_nsec > rhs.td.tv_nsec);
101 bool operator>=(
const SttclPosixTimeDuration& rhs)
const
103 return operator==(rhs) || operator>(rhs);
106 SttclPosixTimeDuration& operator+=(
const SttclPosixTimeDuration& rhs)
112 SttclPosixTimeDuration& operator-=(
const SttclPosixTimeDuration& rhs)
118 SttclPosixTimeDuration& operator*=(
int factor)
124 SttclPosixTimeDuration& operator/=(
int divider)
133 return td.tv_sec / 3600;
138 return td.tv_sec / 60;
145 long milliseconds()
const
147 return total_milliseconds();
149 long microseconds()
const
151 return total_microseconds();
153 long nanoseconds()
const
155 return total_nanoseconds();
158 void hours(
int newHours)
160 SttclPosixTimeDuration result(*
this);
161 result -= SttclPosixTimeDuration(hours() + newHours);
164 void minutes(
int newMinutes)
166 SttclPosixTimeDuration result(*
this);
167 result -= SttclPosixTimeDuration(0,minutes() + newMinutes);
170 void seconds(
int newSeconds)
172 SttclPosixTimeDuration result(*
this);
173 result -= SttclPosixTimeDuration(0,0,seconds() + newSeconds);
188 const NativeTimeDuration& getNativeValue()
const
194 void setNative(
unsigned int argHours,
unsigned int argMinutes,
unsigned int argSeconds,
unsigned int argMilliSeconds,
unsigned long argMicroSeconds,
unsigned long argNanoSeconds);
195 void add(
const NativeTimeDuration& nativeTimeDuration);
196 void substract(
const NativeTimeDuration& nativeTimeDuration);
197 void multiply(
int factor);
198 void divide(
int divider);
199 void normalizeNative();
200 inline long total_milliseconds()
const
202 return td.tv_sec * 1000 + td.tv_nsec / 1000000;
204 inline long total_microseconds()
const
206 return td.tv_sec * 1000000 + td.tv_nsec / 1000;
208 inline long total_nanoseconds()
const
210 return td.tv_sec * 1000000 + td.tv_nsec / 1000;
213 NativeTimeDuration td;