casacore
Loading...
Searching...
No Matches
ProgressMeter.h
Go to the documentation of this file.
1// # ProgressMeter.h: Visual indication of a tasks progress.
2// # Copyright (C) 1997,2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_PROGRESSMETER_H
27#define CASA_PROGRESSMETER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <time.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// # Forward Declarations
36class String;
37
38// <summary>
39// Visual indication of a tasks progress.
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45// </reviewed>
46
47// <synopsis>
48// This class is used to provide a visual indication to the user of the progress
49// of his task. If the process is not connected to the DO system, calls to the
50// progress meter are NO-OP's, so you can safely use this class in general
51// library code and it won't cause problems for processes which are not
52// attached to the distributed object system. It also won't cause any extra
53// stuff to be linked in to your executable in this case.
54//
55// The progress meter will usually be removed from the screen once the maximum
56// value is set, so you should not reuse the ProgressMeter after that has
57// happened. It is harmless, but it will not result in any visual feedback for
58// the user.
59//
60// While the "min" is usually less than "max", if in fact it is greater than
61// "max" the progress meter will count down correctly.
62// </synopsis>
63//
64// <example>
65// <srcblock>
66// void calculate(uInt n) {
67// Int skip = n / 200;
68// ProgressMeter meter(0, n, "Title", "Subtitle", "", "", True, skip);
69// for (uInt i=0; i<n; i++) {
70// ... calculate ...
71// meter.update(i);
72// }
73// }
74// </srcblock>
75// </example>
76//
77// <motivation>
78// Give the user visual indication of a long-running tasks progress.
79// </motivation>
80//
81// <todo asof="1997/03/03">
82// <li> When the upper bound isn't known, it might be useful to have a busy
83// bar that just moves back and forth to show that activity is happening.
84// <li> We should probably have some way to suppress progress bars for tasks
85// that are only going to take a few seconds.
86// </todo>
87
89 public:
90 // Makes a null progress meter, i.e. no updates to the screen are
91 // generated.
93
94 // Create a progress meter with the given min and max values and labels.
95 // if <src>estimateTime</src> is <src>True</src>, an estimate of the
96 // time remaining will be made for the user. This estimate assumes that
97 // the remaining portion will compute at the same rate as the portion
98 // completed so far, so the time should not be estimated for processes
99 // which are non-linear.
100 //
101 // Any labels which are set to the empty string will have sensible defaults
102 // supplied. In particular, <src>minlabel</src> and <src>maxlabel</src>
103 // will be set to the display the minimum and maximum values.
104 //
105 // Normally the progress bar will be updated with every call to
106 // <src>update()</src>. If however you will be sending many events
107 // then you might want to update the GUI every <src>updateEvery</src>'th
108 // event for efficiency. Generally there's no point updating more than
109 // a couple of hundred times since the eye can't distinguish differences
110 // in the progress bar position at that level. If updateEvery is <=0, it
111 // is set to 1 for you.
112 ProgressMeter(Double min, Double max, const String &title, const String &subtitle,
113 const String &minlabel, const String &maxlabel, Bool estimateTime = True,
114 Int updateEvery = 1);
115
117 // The destruction of the meter will cause an update to be sent with the
118 // maximum value. This will usually cause the GUI window to be removed
119 // from the screen. Thus the progress meter should generally live as long
120 // as the calculation it is tracking.
122
123 void update(Double value, Bool force = False);
124 void _update(Double value, Bool force = False);
125 void busy();
126 void done();
127
128 // Display the min and max values of the progress meter.
129 // <group>
130 Double min() const;
131 Double max() const;
132 // </group>
133
134 friend class ObjectController;
135 static const char *PROGRESSFILE;
136
137 private:
141 // Time the progress meter began
142 time_t startTime;
144
145 // These are set by ObjectController for executables that have the tasking
146 // system in them, otherwise they are null and this class just does no-ops.
147 static Int (*creation_function_p)(Double, Double, const String &, const String &, const String &,
148 const String &, Bool);
149 static void (*update_function_p)(Int, Double);
150 static void (*show_function_p)(Int, Double);
151 static void (*busy_function_p)(Int);
152 static void (*done_function_p)(Int);
153
154 // Undefined and inaccessible
157};
158
159} // namespace casacore
160
161#endif
ProgressMeter()
Makes a null progress meter, i.e.
friend class ObjectController
ProgressMeter(Double min, Double max, const String &title)
static Int(* creation_function_p)(Double, Double, const String &, const String &, const String &, const String &, Bool)
These are set by ObjectController for executables that have the tasking system in them,...
ProgressMeter(const ProgressMeter &)
Undefined and inaccessible.
ProgressMeter(Double min, Double max, const String &title, const String &subtitle, const String &minlabel, const String &maxlabel, Bool estimateTime=True, Int updateEvery=1)
Create a progress meter with the given min and max values and labels.
static void(* done_function_p)(Int)
Double min() const
Display the min and max values of the progress meter.
void update(Double value, Bool force=False)
static void(* show_function_p)(Int, Double)
ProgressMeter & operator=(const ProgressMeter &)
~ProgressMeter()
The destruction of the meter will cause an update to be sent with the maximum value.
static void(* update_function_p)(Int, Double)
void _update(Double value, Bool force=False)
time_t startTime
Time the progress meter began.
static const char * PROGRESSFILE
static void(* busy_function_p)(Int)
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53