time_functions.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <iostream>
16 #include <string>
17 #include <cstdlib>
18 #include <ecl/time_lite/config.hpp>
19 #include "../../include/ecl/time_lite/date.hpp"
20 #include "../../include/ecl/time_lite/functions.hpp"
21 #include "../../include/ecl/time_lite/cpu_time.hpp"
22 
23 
24 /*****************************************************************************
25 ** Main
26 *****************************************************************************/
27 
28 int main() {
29 
30 #if defined(ECL_HAS_POSIX_TIMERS) || defined(ECL_HAS_RT_TIMERS) || defined(ECL_HAS_WIN_TIMERS) || defined(ECL_HAS_MACH_TIMERS)
31  ecl::TimeError error;
32  ecl::TimeStructure duration, timestamp;
33 
34  std::cout << std::endl;
35  std::cout << "***********************************************************" << std::endl;
36  std::cout << " Sleep" << std::endl;
37  std::cout << "***********************************************************" << std::endl;
38  std::cout << std::endl;
39 
40 
41  std::cout << "Sleep: Duration 1.3s" << std::endl;
42  duration.tv_sec = 1;
43  duration.tv_nsec = 300000000;
44  error = ecl::sleep(duration);
45  if ( error.flag() != ecl::NoError ) {
46  abort();
47  }
48 
49 
50  std::cout << std::endl;
51  std::cout << "***********************************************************" << std::endl;
52  std::cout << " Epoch Time" << std::endl;
53  std::cout << "***********************************************************" << std::endl;
54  std::cout << std::endl;
55 
56  error = ecl::epoch_time(timestamp);
57  if ( error.flag() != ecl::NoError ) {
58  abort();
59  }
60  std::cout << "Epoch Time:" << std::endl;
61  std::cout << " sec : " << timestamp.tv_sec << std::endl;
62  std::cout << " nsec: " << timestamp.tv_nsec << std::endl;
63 
64  std::cout << std::endl;
65  std::cout << "***********************************************************" << std::endl;
66  std::cout << " Sleep Until" << std::endl;
67  std::cout << "***********************************************************" << std::endl;
68  std::cout << std::endl;
69 
70  timestamp.tv_sec += 2;
71  std::cout << "Sleeping until current_time + 2 seconds." << std::endl;
72  error = ecl::sleep_until(timestamp);
73  if ( error.flag() != ecl::NoError ) {
74  abort();
75  }
76 
77 #ifdef ECL_HAS_CPUTIME
78  std::cout << std::endl;
79  std::cout << "***********************************************************" << std::endl;
80  std::cout << " Cpu Time" << std::endl;
81  std::cout << "***********************************************************" << std::endl;
82  std::cout << std::endl;
83 
84  error = ecl::cpu_time(timestamp);
85  if ( error.flag() != ecl::NoError ) {
86  abort();
87  }
88  std::cout << "Cpu Time:" << std::endl;
89  std::cout << " sec : " << timestamp.tv_sec << std::endl;
90  std::cout << " nsec: " << timestamp.tv_nsec << std::endl;
91 #endif
92 
93  std::cout << std::endl;
94  std::cout << "***********************************************************" << std::endl;
95  std::cout << " Date String" << std::endl;
96  std::cout << "***********************************************************" << std::endl;
97  std::cout << std::endl;
98 
99  std::cout << "Date String: " << ecl::get_date_string() << std::endl;
100 
101  std::cout << std::endl;
102  std::cout << "***********************************************************" << std::endl;
103  std::cout << " Passed" << std::endl;
104  std::cout << "***********************************************************" << std::endl;
105  std::cout << std::endl;
106 
107  return 0;
108 #else
109  std::cout << std::endl;
110  std::cout << "***********************************************************" << std::endl;
111  std::cout << " This platform does not support timers. " << std::endl;
112  std::cout << "***********************************************************" << std::endl;
113  std::cout << std::endl;
114 #endif
115 
116 }
virtual ErrorFlag flag() const
Extends the generic ecl error handler with some time specific error strings.
Definition: errors.hpp:34
int main()


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:09:07