Warning, file /include/boost/progress.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_PROGRESS_HPP
0020 #define BOOST_PROGRESS_HPP
0021
0022 #if !defined(BOOST_TIMER_ENABLE_DEPRECATED)
0023 # error This header is deprecated and will be removed. (You can define BOOST_TIMER_ENABLE_DEPRECATED to suppress this error.)
0024 #endif
0025
0026 #include <boost/config/header_deprecated.hpp>
0027 BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp> or <boost/timer/progress_display.hpp>" )
0028
0029 #include <boost/timer.hpp>
0030 #include <boost/cstdint.hpp> // for uintmax_t
0031 #include <iostream> // for ostream, cout, etc
0032 #include <string> // for string
0033
0034 namespace boost {
0035
0036
0037
0038
0039
0040
0041 class progress_timer : public timer
0042 {
0043 private:
0044
0045 progress_timer( progress_timer const& );
0046 progress_timer& operator=( progress_timer const& );
0047
0048 public:
0049 explicit progress_timer( std::ostream & os = std::cout )
0050
0051 : timer(), m_os(os) {}
0052 ~progress_timer()
0053 {
0054
0055
0056
0057
0058 try
0059 {
0060
0061 std::istream::fmtflags old_flags = m_os.setf( std::istream::fixed,
0062 std::istream::floatfield );
0063 std::streamsize old_prec = m_os.precision( 2 );
0064 m_os << elapsed() << " s\n"
0065 << std::endl;
0066 m_os.flags( old_flags );
0067 m_os.precision( old_prec );
0068 }
0069
0070 catch (...) {}
0071 }
0072
0073 private:
0074 std::ostream & m_os;
0075 };
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 class progress_display
0088 {
0089 private:
0090
0091 progress_display( progress_display const& );
0092 progress_display& operator=( progress_display const& );
0093
0094 public:
0095 explicit progress_display( unsigned long expected_count_,
0096 std::ostream & os = std::cout,
0097 const std::string & s1 = "\n",
0098 const std::string & s2 = "",
0099 const std::string & s3 = "" )
0100
0101 : m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count_); }
0102
0103 void restart( unsigned long expected_count_ )
0104
0105
0106 {
0107 _count = _next_tic_count = _tic = 0;
0108 _expected_count = expected_count_;
0109
0110 m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n"
0111 << m_s2 << "|----|----|----|----|----|----|----|----|----|----|"
0112 << std::endl
0113 << m_s3;
0114 if ( !_expected_count ) _expected_count = 1;
0115 }
0116
0117 unsigned long operator+=( unsigned long increment )
0118
0119
0120
0121 {
0122 if ( (_count += increment) >= _next_tic_count ) { display_tic(); }
0123 return _count;
0124 }
0125
0126 unsigned long operator++() { return operator+=( 1 ); }
0127 unsigned long count() const { return _count; }
0128 unsigned long expected_count() const { return _expected_count; }
0129
0130 private:
0131 std::ostream & m_os;
0132 const std::string m_s1;
0133 const std::string m_s2;
0134 const std::string m_s3;
0135
0136 unsigned long _count, _expected_count, _next_tic_count;
0137 unsigned int _tic;
0138 void display_tic()
0139 {
0140
0141
0142
0143 unsigned int tics_needed = static_cast<unsigned int>((static_cast<double>(_count)
0144 / static_cast<double>(_expected_count)) * 50.0);
0145 do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed );
0146 _next_tic_count =
0147 static_cast<unsigned long>((_tic/50.0) * static_cast<double>(_expected_count));
0148 if ( _count == _expected_count ) {
0149 if ( _tic < 51 ) m_os << '*';
0150 m_os << std::endl;
0151 }
0152 }
0153 };
0154
0155 }
0156
0157 #endif