Ignition Math

API Reference

5.1.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 
67  public: virtual ~Stopwatch();
68 
73  public: bool Start(const bool _reset = false);
74 
79  public: clock::time_point StartTime() const;
80 
84  public: bool Stop();
85 
90  public: clock::time_point StopTime() const;
91 
94  public: bool Running() const;
95 
98  public: void Reset();
99 
105  public: clock::duration ElapsedRunTime() const;
106 
112  public: clock::duration ElapsedStopTime() const;
113 
114 #ifdef _WIN32
115 // Disable warning C4251 which is triggered by
116 // std::unique_ptr
117 #pragma warning(push)
118 #pragma warning(disable: 4251)
119 #endif
120  private: std::unique_ptr<StopwatchPrivate> dataPtr;
122 #ifdef _WIN32
123 #pragma warning(pop)
124 #endif
125  };
126  }
127  }
128 }
129 #endif
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:39