STIR 6.4.0
Timer.inl
Go to the documentation of this file.
1//
2//
14/*
15 Copyright (C) 2000 PARAPET partners
16 Copyright (C) 2000- 2009, Hammersmith Imanet Ltd
17 Copyright (C) 2023, University College London
18 This file is part of STIR.
19
20 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
21
22 See STIR/LICENSE.txt for details
23*/
24#include "stir/error.h"
25
26START_NAMESPACE_STIR
27
28Timer::Timer()
29{
30 running = false;
31 previous_total_value = 0.;
32}
33
34Timer::~Timer()
35{}
36
37void
38Timer::start(bool do_reset)
39{
40 if (!running)
41 {
42 if (do_reset)
43 reset();
44 running = true;
45 previous_value = get_current_value();
46 }
47 else if (do_reset)
48 error("Timer::start called requesting reset, but the timer is running");
49}
50
51void
53{
54 if (running)
55 {
56 previous_total_value += get_current_value() - previous_value;
57 running = false;
58 }
59}
60
61#ifdef OLDDESIGN
62void
63Timer::restart()
64{
65 previous_total_value = 0.;
66 running = false;
67 start();
68}
69#endif
70
71void
73{
74 assert(running == false);
75 previous_total_value = 0.;
76}
77
78double
80{
81 double tmp = previous_total_value;
82 if (running)
83 tmp += get_current_value() - previous_value;
84 return tmp;
85}
86
87END_NAMESPACE_STIR
void reset()
reset stopwatch
Definition Timer.inl:72
void start(bool do_reset=false)
start stopwatch, optionally resetting first
Definition Timer.inl:38
void stop()
stop stopwatch
Definition Timer.inl:52
double value() const
return value is undefined when start() is not called first.
Definition Timer.inl:79
Declaration of stir::error()
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42