UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Timer.h
1 /***************************************************************************
2  * Copyright (C) 2014 by Jan Stückrath <jan.stueckrath@uni-due.de> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
18  ***************************************************************************/
19 
20 #ifndef TIMER_H_
21 #define TIMER_H_
22 
23 #include <time.h>
24 #include "InvalidStateException.h"
25 
26 namespace uncover {
27  namespace basic_types {
28 
34  class Timer {
35 
36  public:
37 
42  Timer(unsigned int timeout = 0);
43 
47  virtual ~Timer();
48 
53  unsigned int getTimeout() const;
54 
60  void setTimeout(unsigned int timeout);
61 
66  bool isTimeoutSet() const;
67 
73  time_t getStartTime() const;
74 
80  double getElapsedTime() const;
81 
86  void start();
87 
93  bool outOfTime() const;
94 
99  bool isRunning() const;
100 
101  private:
102 
106  unsigned int timeout;
107 
111  time_t startTime;
112 
116  bool running;
117  };
118 
122  typedef shared_ptr<Timer> Timer_sp;
123 
124  }
125 }
126 #endif /* TIMER_H_ */
Timer(unsigned int timeout=0)
Generates a new Timer with the given timeout.
Definition: Timer.cpp:26
void setTimeout(unsigned int timeout)
Sets the timeout for this Timer.
Definition: Timer.cpp:34
Provides a timer, which can be started and used to measure elapsed time.
Definition: Timer.h:34
unsigned int timeout
Stores the timeout for "out of time"-checks.
Definition: Timer.h:106
bool running
Stores whether this timer was started at least once.
Definition: Timer.h:116
bool isRunning() const
Returns true iff the Timers start-method was called.
Definition: Timer.cpp:72
time_t startTime
Stores the starting time of this Timer.
Definition: Timer.h:111
double getElapsedTime() const
Returns the time elapsed since the Timer was started (in seconds).
Definition: Timer.cpp:50
bool isTimeoutSet() const
Returns true iff the timeout has a positive value.
Definition: Timer.cpp:38
virtual ~Timer()
Destroys this instance of a Timer.
Definition: Timer.cpp:28
time_t getStartTime() const
Returns the time when this Timer was started.
Definition: Timer.cpp:42
unsigned int getTimeout() const
Returns the timeout stored in this Timer.
Definition: Timer.cpp:30
shared_ptr< Timer > Timer_sp
Alias for a shared pointer to a Timer.
Definition: Timer.h:122
bool outOfTime() const
Returns true, iff the elapsed time is larger than the set timeout.
Definition: Timer.cpp:65
void start()
Starts the timer.
Definition: Timer.cpp:60