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
11namespace 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 */
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
54namespace 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
ScopedStopWatch(std::function< void(IceUtil::Time)> callback, armarx::TimeMode timeMode=armarx::TimeMode::SystemTime)
StopWatch(armarx::TimeMode timeMode=armarx::TimeMode::SystemTime)
Definition StopWatch.cpp:89
Represents a duration.
Definition Duration.h:17
ScopedStopWatch(std::function< void(const Duration &)> callback, ClockType clockType=ClockType::Virtual)
Constructs a ScopedStopWatch.
virtual ~ScopedStopWatch() override
Destructs the ScopedStopWatch.
StopWatch(ClockType clockType=ClockType::Virtual)
Constructs a StopWatch and starts it immediately.
Definition StopWatch.cpp:19
TimeMode
Time mode to be used.
Definition TimeUtil.h:124
ClockType
Describes the type of clock.
Definition ClockType.h:10
@ Virtual
Time given by time server if configured, realtime otherwise.
Definition ClockType.h:16
This file offers overloads of toIce() and fromIce() functions for STL container types.