HoverRace  2.0
Stopwatch.h
Go to the documentation of this file.
1 
2 // Stopwatch.h
3 //
4 // Copyright (c) 2013, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "Clock.h"
25 #include "Duration.h"
26 #include "OS.h"
27 
28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
29 # ifdef MR_ENGINE
30 # define MR_DllDeclare __declspec( dllexport )
31 # else
32 # define MR_DllDeclare __declspec( dllimport )
33 # endif
34 #else
35 # define MR_DllDeclare
36 #endif
37 
38 namespace HoverRace {
39 namespace Util {
40 
46 {
47 public:
48  struct Lap
49  {
50  Lap(const std::string &name, const Duration &elapsed) :
51  name(name), elapsed(elapsed) { }
52  Lap(const Lap &o) = default;
53  Lap(Lap &&o) noexcept = default;
54 
55  Lap &operator=(const Lap &o) = default;
56  Lap &operator=(Lap &&lap) = default;
57 
58  std::string name;
60  };
61 
62 public:
63  Stopwatch(std::shared_ptr<Clock> clock);
64  Stopwatch(std::shared_ptr<Clock> clock, const Duration &start);
65 
66 public:
67  template<typename Fn>
68  void ForEachLap(Fn fn)
69  {
70  std::for_each(laps.cbegin(), laps.cend(), fn);
71  }
72 
73 public:
74  Duration NextLap(const std::string &name);
75 
76 private:
77  std::shared_ptr<Clock> clock;
79  std::vector<Lap> laps;
80 };
81 
82 } // namespace Util
83 } // namespace HoverRace
84 
85 #undef MR_DllDeclare
Definition: Stopwatch.h:48
Duration elapsed
Definition: Stopwatch.h:59
std::shared_ptr< Clock > clock
Definition: Stopwatch.h:77
Duration lastLap
Definition: Stopwatch.h:78
void ForEachLap(Fn fn)
Definition: Stopwatch.h:68
std::vector< Lap > laps
Definition: Stopwatch.h:79
std::string name
Definition: Stopwatch.h:58
Records lap times.
Definition: Stopwatch.h:45
Definition: Announcement.h:24
#define MR_DllDeclare
Definition: Stopwatch.h:35
Lap(const std::string &name, const Duration &elapsed)
Definition: Stopwatch.h:50
The relative time between two timestamps.
Definition: Duration.h:49