aimsdata  5.0.5
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 <ostream>
38 #include <string>
39 
40 namespace aims {
41 
46 
63 
64  template <class T1 = double, class T2 = double>
65  class ProgressInfo {
66 
67  public:
70  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 
86  ProgressInfo( const T1 max );
88 
91  T1& current();
94  void reset();
97  const double& scale() const;
99  double rescale(const T1& value) const;
101  double progression() const;
103  virtual std::string erase() const;
106  virtual std::string render(const bool force = false);
108  virtual std::string toString() const;
110  virtual void print( const bool force = false );
111 
113  ProgressInfo<T1, T2>& operator++(); // Prefix operator
115  ProgressInfo<T1, T2> operator++(int); // Postfix operator
117  ProgressInfo<T1, T2>& operator+= (const T1& r); // Compound assignment
119 
120  protected:
122  double _scale;
125  std::string _unit;
126  };
127 
129 
130  template <class T1, class T2>
131  inline std::ostream& operator<< (
132  std::ostream &out, aims::ProgressInfo<T1, T2> &progression)
133  {
134  std::string p = progression.render();
135 
136  if ( !p.empty() )
137  out << p;
138 
139  return out;
140  }
141 
142 }
143 
144 
145 // Comparison operators
146 template <class T1, class T2>
147 inline bool operator< (const aims::ProgressInfo<T1, T2>& l, const T1& r){return (l.current() < r);}
148 
149 template <class T1, class T2>
150 inline bool operator< (const T1& l, const aims::ProgressInfo<T1, T2>& r){return (l < r.current());}
151 
152 template <class T1, class T2>
153 inline bool operator> (const aims::ProgressInfo<T1, T2>& l, const T1& r){return (r < l);}
154 
155 template <class T1, class T2>
156 inline bool operator> (const T1& l, const aims::ProgressInfo<T1, T2>& r){return (r < l);}
157 
158 template <class T1, class T2>
159 inline bool operator<=(const aims::ProgressInfo<T1, T2>& l, const T1& r){return !(l > r);}
160 
161 template <class T1, class T2>
162 inline bool operator<=(const T1& l, const aims::ProgressInfo<T1, T2>& r){return !(l > r);}
163 
164 template <class T1, class T2>
165 inline bool operator>=(const aims::ProgressInfo<T1, T2>& l, const T1& r){return !(l < r);}
166 
167 template <class T1, class T2>
168 inline bool operator>=(const T1& l, const aims::ProgressInfo<T1, T2>& r){return !(l < r);}
169 
170 #endif
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)
Constructor of the class.
ProgressInfo< T1, T2 > & operator+=(const T1 &r)
Compound assignement operator to increment internal value.
ProgressInfo< T1, T2 > & operator++()
Prefix operator to increment internal value.
const double & scale() const
Scale that is used between displayed progession range and values.
void reset()
Reset the progession to minimum value.
double rescale(const T1 &value) const
Rescale value to its progression value.
virtual void print(const bool force=false)
Print to cout if value changed or forced.
ProgressInfo< double, double > Progression
Definition: progress.h:128
T max(const Volume< T > &vol)
std::string _unit
Definition: progress.h:125
virtual std::string render(const bool force=false)
Render the current progression value if changed or forced.
T1 & current()
Current value.
The class for EcatSino data write operation.
Definition: border.h:44
The template class used to display progression in text mode.
Definition: progress.h:65
T min(const Volume< T > &vol)
bool operator>=(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition: progress.h:165
virtual std::string erase() const
Erase the last displayed value.
double progression() const
Current progression value.
bool operator>(const aims::ProgressInfo< T1, T2 > &l, const T1 &r)
Definition: progress.h:153
virtual std::string toString() const
Convert progression to the display string.
MotionWriter & operator<<(MotionWriter &writer, const AffineTransformation3d &thing) __attribute__((__deprecated__("OBSOLETE")))
— OBSOLETE —
Definition: motionW.h:87