* add the soleil pom.xml file
[diffractometer.git] / src / Duration.h
blob87fd709ff8fd78d39ce689552511c9dc78f9a968
1 // Duration.h: interface for the Duration class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_)
6 #define AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_
8 #if _MSC_VER > 1000
9 #pragma once
10 #endif // _MSC_VER > 1000
12 #ifdef WIN32
13 #pragma once
14 #include <windows.h>
15 #else
16 #include <sys/time.h>
17 #define TIMEVAL struct timeval
18 #define TIMEVAL struct timeval
20 #ifndef NULL
21 #define NULL 0
22 #endif
24 #define GET_TIME(T) gettimeofday(&T,NULL)
25 #define ELAPSED_TIME_SEC(B, A) \
26 static_cast<double>((A.tv_sec - B.tv_sec) + (1.E-6 * (A.tv_usec - B.tv_usec))) // B = start; A = end #endif
27 #endif
29 class Duration
31 public:
32 Duration();
33 virtual ~Duration() {};
35 void Start(void);
36 void Stop(void);
37 double GetDuration(void) const;
38 double GetDurationInMs(void) const;
40 protected:
42 #ifdef WIN32
43 LARGE_INTEGER m_liStart;
44 LARGE_INTEGER m_liStop;
46 LONGLONG m_llFrequency;
47 LONGLONG m_llCorrection;
48 #else
49 TIMEVAL m_liStart;
50 TIMEVAL m_liStop;
51 // LONGLONG m_llCorrection;
52 #endif
56 inline Duration::Duration(void)
58 #ifdef WIN32
59 LARGE_INTEGER liFrequency;
61 QueryPerformanceFrequency(&liFrequency);
62 m_llFrequency = liFrequency.QuadPart;
64 // Calibration
65 Start();
66 Stop();
68 m_llCorrection = m_liStop.QuadPart-m_liStart.QuadPart;
69 #else
70 // Calibration
71 // Start();
72 // Stop();
74 // m_llCorrection = GetDuration();
75 #endif
78 inline void Duration::Start(void)
81 #ifdef WIN32
82 // Ensure we will not be interrupted by any other thread for a while
83 Sleep(0);
84 QueryPerformanceCounter(&m_liStart);
85 #else
86 GET_TIME(m_liStart);
87 #endif
92 inline void Duration::Stop(void)
94 #ifdef WIN32
95 QueryPerformanceCounter(&m_liStop);
96 #else
97 GET_TIME(m_liStop);
98 #endif
102 inline double Duration::GetDuration(void) const
104 #ifdef WIN32
105 return (double)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency;
106 #else
107 return ELAPSED_TIME_SEC(m_liStart, m_liStop);
108 #endif
111 inline double Duration::GetDurationInMs(void) const
113 #ifdef WIN32
114 return (double)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency /1000.0;
115 #else
116 return ELAPSED_TIME_SEC(m_liStart, m_liStop)*1000.0; ///not sure !!!
117 #endif
121 #endif // !defined(AFX_DURATION_H__95A8A4BA_3CFB_4ABC_8C48_495328EA1336__INCLUDED_)