latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 /*---------------------------------------------------------------- 00024 * project ....: LTI Digital Image/Signal Processing Library 00025 * file .......: ltiProgressInfo.h 00026 * authors ....: Pablo Alvarado, Peter Doerfler 00027 * organization: LTI, RWTH Aachen 00028 * creation ...: 10.8.2000 00029 * revisions ..: $Id: ltiProgressInfo.h,v 1.5 2007/01/10 02:25:46 alvarado Exp $ 00030 */ 00031 00032 #ifndef _LTI_PROGRESSINFO_H_ 00033 #define _LTI_PROGRESSINFO_H_ 00034 00035 #include <string> 00036 #include <iostream> 00037 00038 #include "ltiObject.h" 00039 00040 namespace lti { 00041 00042 /** 00043 * Progress information interface 00044 * 00045 * This virtual class is the parent of all classes that can be used 00046 * to display the progress of processes that may take long times, which 00047 * include classifiers, evaluation methods, etc. 00048 * 00049 * The interface is simple and involves a concept where you have: 00050 * - \b steps, with a know maximum value that has to be known from 00051 * the beginning to make possible the computation of the progress 00052 * percentage. 00053 * - \b substeps, which allow to display additional information about each 00054 * step and which detail can be controlled by a "detail level" value. The 00055 * higher the value, the more information is shown. 00056 * 00057 * A simple example class that only redirects the information to the 00058 * std::cout (or other std::ostream) is streamProgressInfo. 00059 */ 00060 class progressInfo : public object { 00061 public: 00062 /** 00063 * Default constructor 00064 * @param title the name of the progressInfo object 00065 * @param maximumSteps the maximum number of steps of the process 00066 */ 00067 progressInfo(const std::string& title = "", 00068 const int& maximumSteps = 100); 00069 00070 /** 00071 * Copy constructor 00072 */ 00073 progressInfo(const progressInfo& other); 00074 00075 /** 00076 * Destructor 00077 */ 00078 virtual ~progressInfo(); 00079 00080 /** 00081 * Set the title of the progress info block 00082 */ 00083 virtual void setTitle(const std::string& theTitle)=0; 00084 00085 /** 00086 * Maximal number of steps 00087 */ 00088 virtual void setMaxSteps(const int& maximalSteps)=0; 00089 00090 /** 00091 * Detail level of substep information 00092 */ 00093 virtual void setDetailLevel(const int level); 00094 00095 /** 00096 * Return the used detail level of substep information 00097 */ 00098 virtual int getDetailLevel() const; 00099 00100 /** 00101 * Report one step done 00102 * @param progressInfo string with some text information for the step 00103 */ 00104 virtual void step(const std::string& progressInfo)=0; 00105 00106 /** 00107 * Report additional information for a step, with the given detail 00108 * level. 00109 * 00110 * The given information will be displayed only if the current detail level 00111 * is higher or equal than the detail specified in this method. 00112 * 00113 * The default implementation is void. 00114 */ 00115 virtual void substep(const int detail, 00116 const std::string& info); 00117 00118 /** 00119 * Reset progress information 00120 */ 00121 virtual void reset()=0; 00122 00123 /** 00124 * Returns true if someone wants the caller of this progress info 00125 * object to terminate. 00126 */ 00127 virtual bool breakRequested() const=0; 00128 00129 /** 00130 * The copy member 00131 */ 00132 progressInfo& copy(const progressInfo& other); 00133 00134 /** 00135 * The clone member 00136 */ 00137 virtual progressInfo* clone() const=0; 00138 00139 protected: 00140 /** 00141 * Detail level used for the substeps 00142 */ 00143 int detailLevel; 00144 }; 00145 00146 00147 /** 00148 * Progress Information to stream 00149 * 00150 * This is a simple implementation of the progressInfo concept. 00151 * It dumps the progress information to a std::ostream, or std::cout 00152 * if you do not give one. 00153 */ 00154 class streamProgressInfo : public progressInfo { 00155 public: 00156 /** 00157 * Default constructor. 00158 * 00159 * Redirect all information to the std::cout stream. 00160 * 00161 * @param title the name of the progressInfo object 00162 * @param maximumSteps the maximum number of steps of the process 00163 */ 00164 streamProgressInfo(const std::string& title = "", 00165 const int& maximumSteps = 100); 00166 00167 /** 00168 * Constructor. 00169 * 00170 * @param outStream output stream, where the progress information will 00171 * be written. 00172 * @param title the name of the progressInfo object 00173 * @param maximumSteps the maximum number of steps of the process 00174 */ 00175 streamProgressInfo(std::ostream& outStream, 00176 const std::string& title = "", 00177 const int& maximumSteps = 100); 00178 00179 /** 00180 * Copy constructor 00181 */ 00182 streamProgressInfo(const streamProgressInfo& other); 00183 00184 /** 00185 * Destructor 00186 */ 00187 virtual ~streamProgressInfo(); 00188 00189 /** 00190 * Set the title of the progress info block 00191 */ 00192 virtual void setTitle(const std::string& theTitle); 00193 00194 /** 00195 * Maximal number of steps 00196 */ 00197 virtual void setMaxSteps(const int& maximalSteps); 00198 00199 /** 00200 * Report one step done 00201 * @param progressInfo string with some text information for the step 00202 */ 00203 virtual void step(const std::string& progressInfo); 00204 00205 /** 00206 * Report additional information for a step, with the given detail 00207 * level. 00208 * 00209 * The given information will be displayed only if the current detail level 00210 * is higher or equal than the detail specified in this method. 00211 */ 00212 virtual void substep(const int detail, 00213 const std::string& info); 00214 00215 /** 00216 * Reset progress information 00217 */ 00218 virtual void reset(); 00219 00220 /** 00221 * The copy member 00222 */ 00223 virtual streamProgressInfo& copy(const streamProgressInfo& other); 00224 00225 /** 00226 * The clone member 00227 */ 00228 virtual progressInfo* clone() const; 00229 00230 /** 00231 * Returns true if someone wants the caller of this progress info 00232 * object to terminate. 00233 */ 00234 virtual bool breakRequested() const; 00235 00236 virtual void useLineFeed(bool uself); 00237 00238 protected: 00239 /** 00240 * Maximum number of steps expected 00241 */ 00242 int maxSteps; 00243 00244 /** 00245 * Last processed step 00246 */ 00247 int lastStep; 00248 00249 /** 00250 * Text specified for the last step 00251 */ 00252 std::string lastStepText; 00253 00254 /** 00255 * Title for this progress info 00256 */ 00257 std::string title; 00258 00259 /** 00260 * Stream being used 00261 */ 00262 std::ostream *out; 00263 00264 /** 00265 * The sequence that is used for end-of-line when emitting 00266 * steps. 00267 */ 00268 std::string endline; 00269 }; 00270 00271 } 00272 00273 #endif