Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / include / simgrid / chrono.hpp
1 /* Copyright (c) 2016. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_CHRONO_HPP
7 #define SIMGRID_CHRONO_HPP
8
9 /** @file chrono.hpp Time support
10  *
11  *  Define clock, duration types, time point types compatible with the standard
12  *  C++ library API.
13  */
14
15 #include <chrono>
16 #include <ratio>
17
18 #include <simgrid/simix.h>
19
20 namespace simgrid {
21
22 /** A C++ compatible TrivialClock working with simulated-time */
23 struct SimulationClock {
24   using rep        = double;
25   using period     = std::ratio<1>;
26   using duration   = std::chrono::duration<rep, period>;
27   using time_point = std::chrono::time_point<SimulationClock, duration>;
28   static constexpr bool is_steady = true;
29   static time_point now()
30   {
31     return time_point(duration(SIMIX_get_clock()));
32   }
33 };
34
35 /** Default duration for simulated time */
36 using SimulationClockDuration  = SimulationClock::duration;
37
38 /** Default time point for simulated time */
39 using SimulationClockTimePoint = SimulationClock::time_point;
40
41 // Durations based on doubles:
42 using nanoseconds = std::chrono::duration<double, std::nano>;
43 using microseconds = std::chrono::duration<double, std::micro>;
44 using milliseconds = std::chrono::duration<double, std::milli>;
45 using seconds = std::chrono::duration<double>;
46 using minutes = std::chrono::duration<double, std::ratio<60>>;
47 using hours = std::chrono::duration<double, std::ratio<3600>>;
48
49 /** A time point in the simulated time */
50 template<class Duration>
51 using SimulationTimePoint = std::chrono::time_point<SimulationClock, Duration>;
52
53 }
54
55 #endif