compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / timer.h
blobfb88f53f2052405e3487118d52e61d397f8939f5
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid 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 General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #ifndef TIMER_H
23 #define TIMER_H
25 #include <iostream>
26 #include <qdatetime.h>
27 #include <typeinfo>
29 class Timer
32 private: // attributes
34 bool print;
36 protected: // attributes
38 QTime m_LastTimeout;
39 int m_Secs;
42 public: // attributes
44 static const char endl = '\n';
47 public:
49 Timer();
50 Timer(int secs);
51 void reset(int secs = 0);
52 bool timeout();
53 bool operator()() { return timeout(); }
55 template <class T> Timer& operator<<(T t);
59 template <class T>
60 Timer& Timer::operator<<(T t)
62 if (print) {
63 bool endl_received = false;
64 if (typeid(T) == typeid(const char)) {
65 endl_received = true;
67 if (print) {
68 if (endl_received) {
69 std::cout << std::endl;
70 print = false;
71 } else {
72 std::cout << t;
74 } else {
75 if (endl_received) {
76 if (timeout()) {
77 print = true;
82 return (*this);
85 #endif // TIMER_H