Fraxinus  16.5.0-fx-rc8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTimedAlgorithm.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXTIMEDALGORITHM_H_
34 #define CXTIMEDALGORITHM_H_
35 
36 #include "cxResourceExport.h"
37 
38 //#include <QtWidgets>
39 
40 
41 #include <QObject>
42 #include <QDateTime>
43 #include <QTimer>
44 #include <boost/function.hpp>
45 #include <vector>
46 #include <iostream>
47 #include "boost/shared_ptr.hpp"
48 
49 namespace cx
50 {
51 
52 
53 
61 class cxResource_EXPORT TimedBaseAlgorithm : public QObject
62 {
63  Q_OBJECT
64 
65 public:
66  TimedBaseAlgorithm(QString product, int secondsBetweenAnnounce);
67  virtual ~TimedBaseAlgorithm();
68 
69  virtual QString getProduct() const { return mProduct; }
76  virtual void execute() = 0;
80  virtual bool isFinished() const = 0;
85  virtual bool isRunning() const = 0;
86 
87 signals:
88  void aboutToStart();
89  void started(int maxSteps);
90  void finished();
91  void productChanged();
92 // void progress();
93 
94 protected:
95  void startTiming();
96  void stopTiming();
98 
99  QString getSecondsPassedAsString() const;
100 
101 protected slots:
102  virtual void finishedSlot() {}
103  virtual void postProcessingSlot() {}
104 
105 private slots:
106  void timeoutSlot();
107 
108 private:
109  QTime getTimePassed();
110 
111  QTimer* mTimer;
112  QDateTime mStartTime;
113  QString mProduct;
114 };
115 typedef boost::shared_ptr<TimedBaseAlgorithm> TimedAlgorithmPtr;
116 
117 }//namespace
118 
119 #endif /* CXTIMEDALGORITHM_H_ */
Base class for algorithms that wants to time their execution.
virtual void finishedSlot()
boost::shared_ptr< class TimedBaseAlgorithm > TimedAlgorithmPtr
virtual QString getProduct() const
virtual void postProcessingSlot()