Ignition Math

API Reference

6.10.0
Stopwatch.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef IGNITION_MATH_STOPWATCH_HH_
19 #define IGNITION_MATH_STOPWATCH_HH_
20 
21 #include <chrono>
22 #include <memory>
23 #include <ignition/math/Export.hh>
24 #include <ignition/math/config.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
30  // Use a steady clock
32 
33  // Inline bracket to help doxygen filtering.
34  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
35  //
36  // Forward declarations.
37  class StopwatchPrivate;
38 
39  //
61  class IGNITION_MATH_VISIBLE Stopwatch
62  {
64  public: Stopwatch();
65 
68  public: Stopwatch(const Stopwatch &_watch);
69 
72  public: Stopwatch(Stopwatch &&_watch) noexcept;
73 
75  public: virtual ~Stopwatch();
76 
81  public: bool Start(const bool _reset = false);
82 
87  public: clock::time_point StartTime() const;
88 
92  public: bool Stop();
93 
98  public: clock::time_point StopTime() const;
99 
102  public: bool Running() const;
103 
106  public: void Reset();
107 
113  public: clock::duration ElapsedRunTime() const;
114 
120  public: clock::duration ElapsedStopTime() const;
121 
125  public: bool operator==(const Stopwatch &_watch) const;
126 
130  public: bool operator!=(const Stopwatch &_watch) const;
131 
135  public: Stopwatch &operator=(const Stopwatch &_watch);
136 
140  public: Stopwatch &operator=(Stopwatch &&_watch);
141 
142 #ifdef _WIN32
143 // Disable warning C4251 which is triggered by
144 // std::unique_ptr
145 #pragma warning(push)
146 #pragma warning(disable: 4251)
147 #endif
148  private: std::unique_ptr<StopwatchPrivate> dataPtr;
150 #ifdef _WIN32
151 #pragma warning(pop)
152 #endif
153  };
154  }
155  }
156 }
157 #endif
std::chrono::steady_clock clock
Definition: DiffDriveOdometry.hh:31
The Stopwatch keeps track of time spent in the run state, accessed through ElapsedRunTime(), and time spent in the stop state, accessed through ElapsedStopTime(). Elapsed run time starts accumulating after the first call to Start(). Elapsed stop time starts accumulation after Start() has been called followed by Stop(). The stopwatch can be reset with the Reset() function.
Definition: Stopwatch.hh:61
Definition: Angle.hh:42