aimsdata 6.0.0
Neuroimaging data handling
progress.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_UTILITY_PROGRESS_H
35#define AIMS_UTILITY_PROGRESS_H
36
37#include <iostream>
38#include <string>
39
40namespace aims {
41
46 #include <iostream>
47 #include <unistd.h>
48 #include <aims/utility/progress.h>
49
50 int main( int argc, const char* argv[] ) {
51 int start = 10, end = 1000;
52 aims::Progression progress(start, end);
53 std::cout << "Progress ";
54 for (int i = start; i <= end; ++i, ++progress)
55 {
56 usleep(1000);
57 std::cout << progress << std::flush;
58 }
59
60 std::cout << std::endl;
61 }
63 */
64 template <class T1 = double, class T2 = double>
66
67 public:
70
77 ProgressInfo( const T1 min,
78 const T1 max,
79 const T2 progressmin = (T2)0,
80 const T2 progressmax = (T2)100,
81 const std::string unit = "%",
82 const int width = 3,
83 std::ostream & stream = std::cout );
84
87 ProgressInfo( const T1 max,
88 std::ostream & stream = std::cout );
90
93
94 T1& current();
96 void reset();
99 const double& scale() const;
101 double rescale(const T1& value) const;
103 double progression() const;
105 virtual std::string erase() const;
107 virtual std::string endline() const;
110 virtual std::string render(const bool force = false);
112 virtual std::string toString() const;
114 virtual void print( const bool force = false );
115
117 ProgressInfo<T1, T2>& operator++(); // Prefix operator
119 ProgressInfo<T1, T2> operator++(int); // Postfix operator
121 ProgressInfo<T1, T2>& operator+= (const T1& r); // Compound assignment
123
124 protected:
126 double _scale;
129 std::string _unit;
130 std::ostream & _stream;
131 };
132
134
135 template <class T1, class T2>
136 inline std::ostream& operator<< (
137 std::ostream &out, aims::ProgressInfo<T1, T2> &progression)
138 {
139 std::string p = progression.render();
140
141 if ( !p.empty() )
142 out << p;
143
144 return out;
145 }
146
147}
148
149
150// Comparison operators
151template <class T1, class T2>
152inline bool operator< (const aims::ProgressInfo<T1, T2>& l, const T1& r){return (l.current() < r);}
153
154template <class T1, class T2>
155inline bool operator< (const T1& l, const aims::ProgressInfo<T1, T2>& r){return (l < r.current());}
156
157template <class T1, class T2>
158inline bool operator> (const aims::ProgressInfo<T1, T2>& l, const T1& r){return (r < l);}
159
160template <class T1, class T2>
161inline bool operator> (const T1& l, const aims::ProgressInfo<T1, T2>& r){return (r < l);}
162
163template <class T1, class T2>
164inline bool operator<=(const aims::ProgressInfo<T1, T2>& l, const T1& r){return !(l > r);}
165
166template <class T1, class T2>
167inline bool operator<=(const T1& l, const aims::ProgressInfo<T1, T2>& r){return !(l > r);}
168
169template <class T1, class T2>
170inline bool operator>=(const aims::ProgressInfo<T1, T2>& l, const T1& r){return !(l < r);}
171
172template <class T1, class T2>
173inline bool operator>=(const T1& l, const aims::ProgressInfo<T1, T2>& r){return !(l < r);}
174
175#endif
The template class used to display progression in text mode.
Definition progress.h:65
virtual std::string endline() const
End of line (none for stdout, "\\n" otherwise)
ProgressInfo< T1, T2 > & operator+=(const T1 &r)
Compound assignement operator to increment internal value.
virtual void print(const bool force=false)
Print to the output stream if value changed or forced.
ProgressInfo(const T1 min, const T1 max, const T2 progressmin=(T2) 0, const T2 progressmax=(T2) 100, const std::string unit="%", const int width=3, std::ostream &stream=std::cout)
Constructor of the class.
double rescale(const T1 &value) const
Rescale value to its progression value.
T1 & current()
Current value.
ProgressInfo(const T1 max, std::ostream &stream=std::cout)
Constructor of the class.
void reset()
Reset the progession to minimum value.
virtual std::string toString() const
Convert progression to the display string.
ProgressInfo< T1, T2 > operator++(int)
Postfix operator to increment internal value.
virtual std::string render(const bool force=false)
Render the current progression value if changed or forced.
ProgressInfo< T1, T2 > & operator++()
Prefix operator to increment internal value.
double progression() const
Current progression value.
const double & scale() const
Scale that is used between displayed progession range and values.
virtual std::string erase() const
Erase the last displayed value.
The class for EcatSino data write operation.
ProgressInfo< double, double > Progression
Definition progress.h:133
AIMSDATA_API PovWriter< D, T > & operator<<(PovWriter< D, T > &writer, const AimsTimeSurface< D, T > &thing)
Definition povW.h:72
T min(const Volume< T > &vol)
T max(const Volume< T > &vol)
bool operator>(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition progress.h:158
bool operator<=(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition progress.h:164
bool operator>=(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition progress.h:170
bool operator<(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition progress.h:152