ScopedStopWatch.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include <functional>
5 
6 #include <IceUtil/Time.h>
7 
10 
11 
12 namespace armarx::core::time
13 {
14 
15  /**
16  * @brief Measures the time this stop watch was inside the current scope. Takes a lambda as
17  * construction parameter (taking an `IceUtil::Time` as parameter), which will be called at
18  * destruction (i.e., when the scope was left).
19  *
20  * Code example:
21  *
22  * @code
23  * {
24  * ScopedStopWatch sw{[](const Duration& duration) {
25  * std::cout << "Operation took " << duration << ".";
26  * }};
27  *
28  * long_operation();
29  * }
30  * @endcode
31  */
32  class ScopedStopWatch : public StopWatch
33  {
34 
35  public:
36  /**
37  * @brief Constructs a `ScopedStopWatch`.
38  * @param callback Callback lambda which will be called at destruction with measured time.
39  * @param clockType Clock type.
40  */
41  ScopedStopWatch(std::function<void(const Duration&)> callback,
42  ClockType clockType = ClockType::Virtual);
43 
44  /**
45  * @brief Destructs the `ScopedStopWatch`.
46  */
47  virtual ~ScopedStopWatch() override;
48 
49  private:
50  std::function<void(const Duration&)> _callback;
51  };
52 
53 } // namespace armarx::core::time
54 
55 
56 namespace armarx
57 {
58 
59  class [[deprecated("Use armarx::core::time::ScopedStopWatch instead")]] ScopedStopWatch :
60  public StopWatch
61  {
62 
63  public:
64  ScopedStopWatch(std::function<void(IceUtil::Time)> callback,
66  virtual ~ScopedStopWatch() override;
67 
68  private:
69  std::function<void(IceUtil::Time)> m_callback;
70  };
71 
72 } // namespace armarx
armarx::core::time::ScopedStopWatch::~ScopedStopWatch
virtual ~ScopedStopWatch() override
Destructs the ScopedStopWatch.
Definition: ScopedStopWatch.cpp:21
StopWatch.h
armarx::core::time
Definition: Clock.cpp:13
armarx::ScopedStopWatch
Definition: ScopedStopWatch.h:59
armarx::core::time::ScopedStopWatch::ScopedStopWatch
ScopedStopWatch(std::function< void(const Duration &)> callback, ClockType clockType=ClockType::Virtual)
Constructs a ScopedStopWatch.
Definition: ScopedStopWatch.cpp:13
armarx::TimeMode::SystemTime
@ SystemTime
armarx::core::time::ClockType
ClockType
Describes the type of clock.
Definition: ClockType.h:10
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::core::time::ClockType::Virtual
@ Virtual
Time given by time server if configured, realtime otherwise.
armarx::TimeMode
TimeMode
Time mode to be used.
Definition: TimeUtil.h:119
TimeUtil.h
armarx::core::time::ScopedStopWatch
Measures the time this stop watch was inside the current scope.
Definition: ScopedStopWatch.h:32
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::core::time::StopWatch
Measures the passed time between the construction or calling reset() and stop().
Definition: StopWatch.h:42
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StopWatch
Definition: StopWatch.h:120