VPTissue Reference Manual
ClockCLib.h
Go to the documentation of this file.
1 #ifndef UTIL_CLOCK_MAN_CLOCK_CLIB_H_INCLUDED
2 #define UTIL_CLOCK_MAN_CLOCK_CLIB_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <chrono>
23 #include <ctime>
24 #include <stdexcept>
25 
26 namespace SimPT_Sim {
27 namespace ClockMan {
28 
34 class ClockCLib
35 {
36 public:
37  typedef std::chrono::milliseconds duration;
38  typedef duration::rep rep;
39  typedef duration::period period;
40  typedef std::chrono::time_point<ClockCLib, duration> time_point;
41 
42  static time_point now()
43  {
44  std::clock_t t = std::clock();
45  if ( static_cast<std::clock_t>(-1) == t ) {
46  throw std::runtime_error("Error in ClockCLib");
47  }
48 
49  constexpr double conv = 1.0 / CLOCKS_PER_SEC;
50  constexpr double ratio = static_cast<double>(period::den)/static_cast<double>(period::num);
51  const duration d(static_cast<rep>(static_cast<double>(t) * conv * ratio));
52  return time_point(d);
53  }
54 };
55 
56 } // namespace
57 } // namespace
58 
59 #endif // end of include guard
Namespace for the core simulator.
Clock based on C library clock_t clock() which returns an approximate processor time in ticks...
Definition: ClockCLib.h:34