iRoCS Toolbox  1.1.0
ProgressReporterStream.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program 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  * This program 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 this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 #ifndef IROCSPROGRESSREPORTERSTREAM_HH
24 #define IROCSPROGRESSREPORTERSTREAM_HH
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.hh>
28 #endif
29 
30 #include "ProgressReporter.hh"
31 #include <iostream>
32 #include <sstream>
33 
34 namespace iRoCS
35 {
36 
38  {
39 
40  public:
41 
43  std::ostream& os = std::cout,
44  int progress = 0, int progressMin = 0, int progressMax = 100,
45  std::string const &headerMessage = std::string(),
46  std::string const &progressMessage = std::string());
47 
49 
50  void setProgressMin(int progressMin);
51 
52  int progressMin() const;
53 
54  void setProgressMax(int progressMax);
55 
56  int progressMax() const;
57 
58  void setHeaderMessage(std::string const &message);
59 
60  std::string headerMessage() const;
61 
62  void setProgressMessage(std::string const &message);
63 
64  std::string progressMessage() const;
65 
66  void setProgress(int progress);
67 
68  int progress() const;
69 
70  void setAborted(bool abort);
71 
72  void abort();
73 
74  void abortWithError(std::string const &msg);
75 
76  bool isAborted() const;
77 
78  bool updateProgress(int progress);
79 
80  bool updateProgressMessage(std::string const &message);
81 
82 /*======================================================================*/
88 /*======================================================================*/
89  template<typename DataT>
90  ProgressReporterStream &operator<<(DataT const &msg);
91 
92  private:
93 
94  std::ostream& _os;
95 
96  int _progress, _progressMin, _progressMax;
97  std::string _headerMessage, _progressMessage;
98  bool _aborted;
99 
100  };
101 
102  template<typename DataT>
104  {
105 #ifdef _OPENMP
106 #pragma omp critical (_PROGRESSMESSAGE_IS_CURRENTLY_UPDATING_)
107 #endif
108  {
109  std::ostringstream os;
110  os << msg;
111  _progressMessage += os.str();
112  _os << msg << std::flush;
113  }
114  return *this;
115  }
116 
117 }
118 
119 #endif
std::ostream & operator<<(std::ostream &os, BasicTreeNode< KeyT, ContentT > const &n)
#define PROGRESSREPORTERDLL_API
ProgressReporterStream & operator<<(DataT const &msg)
Appends the given message to the selected output stream.