CARLA
LibCarla
source
carla
StopWatch.h
Go to the documentation of this file.
1
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include <chrono>
10
#include <cstdint>
11
12
namespace
carla
{
13
namespace
detail {
14
15
template
<
typename
CLOCK>
16
class
StopWatchTmpl
{
17
static_assert(CLOCK::is_steady,
"The StopWatch's clock must be steady"
);
18
public
:
19
20
using
clock
= CLOCK;
21
22
StopWatchTmpl
() :
_start
(
clock
::now()),
_end
(),
_is_running
(true) {}
23
24
void
Restart
() {
25
_is_running
=
true
;
26
_start
= clock::now();
27
}
28
29
void
Stop
() {
30
_end
= clock::now();
31
_is_running
=
false
;
32
}
33
34
typename
clock::duration
GetDuration
()
const
{
35
return
_is_running
? clock::now() -
_start
:
_end
-
_start
;
36
}
37
38
template
<
class
RESOLUTION=std::chrono::milliseconds>
39
size_t
GetElapsedTime
()
const
{
40
return
static_cast<
size_t
>
(std::chrono::duration_cast<RESOLUTION>(
GetDuration
()).count());
41
}
42
43
bool
IsRunning
()
const
{
44
return
_is_running
;
45
}
46
47
private
:
48
49
typename
clock::time_point
_start
;
50
51
typename
clock::time_point
_end
;
52
53
bool
_is_running
;
54
};
55
56
}
// namespace detail
57
58
using
StopWatch
=
detail::StopWatchTmpl<std::chrono::steady_clock>
;
59
60
}
// namespace carla
carla::detail::StopWatchTmpl::_is_running
bool _is_running
Definition:
StopWatch.h:53
carla::detail::StopWatchTmpl::_end
clock::time_point _end
Definition:
StopWatch.h:51
carla::detail::StopWatchTmpl::_start
clock::time_point _start
Definition:
StopWatch.h:49
carla
This file contains definitions of common data structures used in traffic manager. ...
Definition:
Carla.cpp:133
carla::detail::StopWatchTmpl::Stop
void Stop()
Definition:
StopWatch.h:29
carla::detail::StopWatchTmpl::IsRunning
bool IsRunning() const
Definition:
StopWatch.h:43
carla::detail::StopWatchTmpl::clock
CLOCK clock
Definition:
StopWatch.h:20
carla::detail::StopWatchTmpl
Definition:
StopWatch.h:16
carla::detail::StopWatchTmpl::Restart
void Restart()
Definition:
StopWatch.h:24
carla::detail::StopWatchTmpl::GetDuration
clock::duration GetDuration() const
Definition:
StopWatch.h:34
carla::detail::StopWatchTmpl::GetElapsedTime
size_t GetElapsedTime() const
Definition:
StopWatch.h:39
carla::detail::StopWatchTmpl::StopWatchTmpl
StopWatchTmpl()
Definition:
StopWatch.h:22
Generated by
1.8.13