Gazebo Math

API Reference

6.15.1
gz/math/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 GZ_MATH_STOPWATCH_HH_
19 #define GZ_MATH_STOPWATCH_HH_
20 
21 #include <chrono>
22 #include <memory>
23 #include <gz/math/Export.hh>
24 #include <gz/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
bool Stop()
Stop the stopwatch.
bool operator!=(const Stopwatch &_watch) const
Inequality operator.
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
bool Start(const bool _reset=false)
Start the stopwatch.
bool operator==(const Stopwatch &_watch) const
Equality operator.
clock::duration ElapsedRunTime() const
Get the amount of time that the stop watch has been running. This is the total amount of run time,...
void Reset()
Reset the stopwatch. This resets the start time, stop time, elapsed duration and elapsed stop duratio...
bool Running() const
Get whether the stopwatch is running.
The Stopwatch keeps track of time spent in the run state, accessed through ElapsedRunTime(),...
Definition: gz/math/Stopwatch.hh:61
Stopwatch & operator=(const Stopwatch &_watch)
Copy assignment operator.
std::chrono::steady_clock clock
Definition: gz/math/DiffDriveOdometry.hh:31
clock::duration ElapsedStopTime() const
Get the amount of time that the stop watch has been stopped. This is the total amount of stop time,...
virtual ~Stopwatch()
Destructor.
clock::time_point StopTime() const
Get the time when the stopwatch was last stopped.
clock::time_point StartTime() const
Get the time when the stopwatch was started.