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