Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTimeVal.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cTimeVal_H
7 #define _INC_cTimeVal_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cTimeSys.h"
13 #ifdef _WIN32
14 #include <winsock2.h> // timeval
15 #endif
16 
17 namespace Gray
18 {
19  class GRAYCORE_LINK cTimeVal : public /* struct*/ timeval
20  {
26 
27  public:
28  cTimeVal() noexcept
29  {
30  this->tv_sec = 0;
31  this->tv_usec = 0;
32  }
33  cTimeVal(TIMESYS_t nMilliSeconds) noexcept
34  {
35  put_mSec(nMilliSeconds);
36  }
37  cTimeVal(TIMESECD_t nSeconds, int iMicroSecWait) noexcept
38  {
39  this->tv_sec = nSeconds;
40  this->tv_usec = iMicroSecWait;
41  }
42 
43  TIMESYS_t get_mSec() const noexcept
44  {
45  return (this->tv_sec * cTimeSys::k_FREQ) + (this->tv_usec / 1000);
46  }
47  void put_mSec(TIMESYS_t nMilliSeconds) noexcept
48  {
49  this->tv_sec = nMilliSeconds / cTimeSys::k_FREQ;
50  this->tv_usec = (nMilliSeconds % cTimeSys::k_FREQ) * 1000;
51  }
52  void put_Sec(int nSeconds) noexcept
53  {
54  this->tv_sec = nSeconds;
55  this->tv_usec = 0;
56  }
57  };
58 }
59 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
static const TIMESYS_t k_FREQ
milliSec per Sec
Definition: cTimeSys.h:100
Definition: cTimeVal.h:20
TIMESYS_t get_mSec() const noexcept
Definition: cTimeVal.h:43
cTimeVal() noexcept
Definition: cTimeVal.h:28
cTimeVal(TIMESECD_t nSeconds, int iMicroSecWait) noexcept
Definition: cTimeVal.h:37
cTimeVal(TIMESYS_t nMilliSeconds) noexcept
Definition: cTimeVal.h:33
void put_mSec(TIMESYS_t nMilliSeconds) noexcept
Definition: cTimeVal.h:47
void put_Sec(int nSeconds) noexcept
Definition: cTimeVal.h:52
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int TIMESECD_t
signed delta seconds. like TIMESEC_t. redefined in TimeUnits.h.
Definition: cTimeSys.h:19
UINT32 TIMESYS_t
TIMESYS_t = The normal system tick timer. milli-seconds since start of system/app ?
Definition: cTimeSys.h:27