GEDLIB  1.0
timer.ipp
Go to the documentation of this file.
1 /***************************************************************************
2 * *
3 * Copyright (C) 2018 by David B. Blumenthal *
4 * *
5 * This file is part of GEDLIB. *
6 * *
7 * GEDLIB is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * GEDLIB is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21 
27 #ifndef SRC_ENV_TIMER_IPP_
28 #define SRC_ENV_TIMER_IPP_
29 
30 namespace ged {
31 
33 Timer(double time_limit_in_sec) :
34 time_limit_in_sec_(time_limit_in_sec),
35 start_time_{std::chrono::high_resolution_clock::now()} {}
36 
37 bool
39 expired() const {
40  if (time_limit_in_sec_ > 0) {
41  std::chrono::duration<double> runtime = std::chrono::high_resolution_clock::now() - start_time_;
42  return (runtime.count() >= time_limit_in_sec_);
43  }
44  return false;
45 }
46 
47 }
48 
49 #endif /* SRC_ENV_TIMER_IPP_ */
bool expired() const
Checks if the time limit has expired.
Definition: timer.ipp:39
Timer(double time_limit_in_sec)
Constructs a timer for a given time limit.
Definition: timer.ipp:33
Global namespace for GEDLIB.