[min,max]
and counter (value)
for progress counting.
More...
#include <ProgressData.h>
Classes | |
class | Data |
Public Types | |
typedef long long | value_type |
typedef function< bool(const ProgressData &)> | ReceiverFnc |
Most simple version of progress reporting The percentage in most cases. | |
Public Member Functions | |
ProgressData () | |
Ctor no range [0,0](0) . | |
ProgressData (value_type max_r) | |
Ctor [0,max](0) . | |
ProgressData (value_type min_r, value_type max_r) | |
Ctor [min,max](min) . | |
ProgressData (value_type min_r, value_type max_r, value_type val_r) | |
Ctor [min,max](val) . | |
~ProgressData () | |
void | min (value_type min_r) |
Set new min value. | |
void | max (value_type max_r) |
Set new max value. | |
void | noRange () |
Set no range [0,0] . | |
void | range (value_type max_r) |
Set new [0,max] . | |
void | range (value_type min_r, value_type max_r) |
Set new [min,max] . | |
void | name (const std::string &name_r) |
Set counter name. | |
void | sendTo (const ReceiverFnc &fnc_r) |
Set ReceiverFnc. | |
void | noSend () |
Set no ReceiverFnc. | |
Progress reporting. | |
These methods may actually cause a progress report to be sent.
All methods return | |
bool | set (value_type val_r) |
Set new counter value . | |
bool | incr (value_type val_r=1) |
Increment counter value (default by 1). | |
bool | decr (value_type val_r=1) |
Decrement counter value (default by 1). | |
bool | toMin () |
Set counter value to current min value. | |
bool | toMax () |
Set counter value to current max value (unless no range). | |
bool | tick () |
Leave counter value unchanged (still alive). | |
Progress receiving. | |
value_type | min () const |
value_type | max () const |
value_type | val () const |
bool | hasRange () const |
bool | reportPercent () const |
bool | reportAlive () const |
value_type | reportValue () const |
const std::string & | name () const |
const ReceiverFnc & | receiver () const |
bool | finalReport () const |
Private Types | |
enum | State { INIT, RUN, END } |
Private Member Functions | |
bool | report () |
Send report if necessary. | |
Private Attributes | |
RWCOW_pointer< Data > | _d |
Pointer to data. | |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &str, const ProgressData &obj) |
ProgressData | makeProgressData (const InputStream &input_r) |
[min,max]
and counter (value)
for progress counting.
This class should provide everything the producer of progress data needs. As a convention, a zero sizes range indicates that you are just able to send 'still alive' triggers.
The counter should be updated in reasonable intervals. Don't mind wheter the counter value actually increased or not. ProgressData will recognize your triggers and knows when to actually send notification to a consumer.
Each ProgressData object provides a unique numeric id and you may assign it a name.
bool exampleReceiver( ProgressData::value_type v ) { DBG << "got ->" << v << endl; return( v <= 100 ); // Abort if ( v > 100 ) } class Example { public: Example( const ProgressData::ReceiverFnc & fnc_r = ProgressData::ReceiverFnc() ) : _fnc( fnc_r ) {} void SendTo( const ProgressData::ReceiverFnc & fnc_r ) { _fnc = fnc_r; } public: void action() { ProgressData tics( 10 ); // Expect range 0 -> 10 tics.name( "test ticks" ); // Some arbitrary name tics.sendTo( _fnc ); // Send reports to _fnc tics.toMin(); // start sending min (0) for ( int i = 0; i < 10; ++i ) { if ( ! tics.set( i ) ) return; // user requested abort } tics.toMax(); // take care 100% are reported on success } void action2() { ProgressData tics; // Just send 'still alive' messages tics.name( "test ticks" ); // Some arbitrary name tics.sendTo( _fnc ); // Send reports to _fnc tics.toMin(); // start sending min (0) for ( int i = 0; i < 10; ++i ) { if ( ! tics.set( i ) ) return; // user requested abort } tics.toMax(); // } private: ProgressData::ReceiverFnc _fnc; };
Example t( exampleReceiver ); DBG << "Reporting %:" << endl; t.action(); DBG << "Reporting 'still alive':" << endl; t.action2();
Reporting %:
got ->0
got ->10
got ->20
got ->30
got ->40
got ->50
got ->60
got ->70
got ->80
got ->90
got ->100
got ->100
Reporting 'still alive':
got ->0
got ->9
The different ammount of triggers is due to different rules for sending percent or 'still alive' messages.
Tell recipient whether percentage or keepalive is sent, the id and name might be helpfull, and maybe tell whether task is abortable or not; i.e extend the ReceiverFnc signature.
Definition at line 135 of file ProgressData.h.
typedef long long zypp::ProgressData::value_type |
Definition at line 138 of file ProgressData.h.
typedef function<bool( const ProgressData & )> zypp::ProgressData::ReceiverFnc |
Most simple version of progress reporting The percentage in most cases.
Sometimes just keepalive. sender
ProgressData object who sends the progress info
Definition at line 144 of file ProgressData.h.
enum zypp::ProgressData::State [private] |
zypp::ProgressData::ProgressData | ( | ) | [inline] |
zypp::ProgressData::ProgressData | ( | value_type | max_r | ) | [inline] |
zypp::ProgressData::ProgressData | ( | value_type | min_r, | |
value_type | max_r | |||
) | [inline] |
zypp::ProgressData::ProgressData | ( | value_type | min_r, | |
value_type | max_r, | |||
value_type | val_r | |||
) | [inline] |
zypp::ProgressData::~ProgressData | ( | ) | [inline] |
void zypp::ProgressData::min | ( | value_type | min_r | ) | [inline] |
Set new min
value.
Definition at line 206 of file ProgressData.h.
References _d.
Referenced by zypp::CombinedProgressData::operator()(), and zypp::operator<<().
void zypp::ProgressData::max | ( | value_type | max_r | ) | [inline] |
Set new max
value.
Definition at line 210 of file ProgressData.h.
References _d.
Referenced by zypp::CombinedProgressData::operator()(), and zypp::operator<<().
void zypp::ProgressData::noRange | ( | ) | [inline] |
void zypp::ProgressData::range | ( | value_type | max_r | ) | [inline] |
Set new [0,max]
.
Definition at line 218 of file ProgressData.h.
References range().
Referenced by zypp::makeProgressData(), noRange(), and range().
void zypp::ProgressData::range | ( | value_type | min_r, | |
value_type | max_r | |||
) | [inline] |
void zypp::ProgressData::name | ( | const std::string & | name_r | ) | [inline] |
Set counter name.
Definition at line 227 of file ProgressData.h.
References _d.
Referenced by zypp::RepoManager::addRepository(), zypp::RepoManager::buildCache(), zypp::makeProgressData(), zypp::operator<<(), and zypp::RepoManager::removeRepository().
void zypp::ProgressData::sendTo | ( | const ReceiverFnc & | fnc_r | ) | [inline] |
Set ReceiverFnc.
Definition at line 231 of file ProgressData.h.
References _d.
Referenced by zypp::RepoManager::addRepository(), zypp::RepoManager::buildCache(), zypp::RepoManager::cleanCache(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::RepoManager::cleanMetadata(), zypp::RepoManager::cleanPackages(), zypp::repo::yum::Downloader::download(), zypp::parser::susetags::ContentFileReader::parse(), zypp::parser::IniParser::parse(), zypp::parser::HistoryLogReader::Impl::readAll(), zypp::parser::HistoryLogReader::Impl::readFrom(), zypp::parser::HistoryLogReader::Impl::readFromTo(), and zypp::RepoManager::removeRepository().
void zypp::ProgressData::noSend | ( | ) | [inline] |
bool zypp::ProgressData::set | ( | value_type | val_r | ) | [inline] |
Set new counter value
.
Definition at line 251 of file ProgressData.h.
Referenced by zypp::RepoManager::addRepository(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::parser::susetags::ContentFileReader::parse(), and zypp::parser::IniParser::parse().
bool zypp::ProgressData::incr | ( | value_type | val_r = 1 |
) | [inline] |
Increment counter value
(default by 1).
Definition at line 258 of file ProgressData.h.
References val().
Referenced by zypp::CombinedProgressData::operator()().
bool zypp::ProgressData::decr | ( | value_type | val_r = 1 |
) | [inline] |
Decrement counter value
(default by 1).
Definition at line 262 of file ProgressData.h.
References val().
bool zypp::ProgressData::toMin | ( | ) | [inline] |
Set counter value to current min
value.
Definition at line 266 of file ProgressData.h.
References min().
Referenced by zypp::RepoManager::addRepository(), zypp::RepoManager::buildCache(), zypp::RepoManager::cleanCache(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::repo::yum::Downloader::download(), zypp::parser::susetags::ContentFileReader::parse(), zypp::parser::IniParser::parse(), zypp::parser::HistoryLogReader::Impl::readAll(), zypp::parser::HistoryLogReader::Impl::readFrom(), and zypp::parser::HistoryLogReader::Impl::readFromTo().
bool zypp::ProgressData::toMax | ( | ) | [inline] |
Set counter value to current max
value (unless no range).
Definition at line 270 of file ProgressData.h.
References hasRange(), max(), and val().
Referenced by zypp::RepoManager::addRepository(), zypp::RepoManager::buildCache(), zypp::RepoManager::cleanCache(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::RepoManager::cleanMetadata(), zypp::RepoManager::cleanPackages(), zypp::repo::yum::Downloader::download(), zypp::parser::susetags::ContentFileReader::parse(), zypp::parser::IniParser::parse(), zypp::parser::HistoryLogReader::Impl::readAll(), zypp::parser::HistoryLogReader::Impl::readFrom(), and zypp::parser::HistoryLogReader::Impl::readFromTo().
bool zypp::ProgressData::tick | ( | ) | [inline] |
Leave counter value unchanged (still alive).
Definition at line 274 of file ProgressData.h.
References val().
Referenced by zypp::repo::yum::Downloader::download(), zypp::CombinedProgressData::operator()(), zypp::parser::HistoryLogReader::Impl::readAll(), zypp::parser::HistoryLogReader::Impl::readFrom(), and zypp::parser::HistoryLogReader::Impl::readFromTo().
value_type zypp::ProgressData::min | ( | ) | const [inline] |
min
value. Definition at line 284 of file ProgressData.h.
References _d.
Referenced by hasRange(), range(), reportValue(), and toMin().
value_type zypp::ProgressData::max | ( | ) | const [inline] |
max
value. Definition at line 288 of file ProgressData.h.
References _d.
Referenced by hasRange(), range(), reportValue(), and toMax().
value_type zypp::ProgressData::val | ( | ) | const [inline] |
value
. Definition at line 292 of file ProgressData.h.
References _d.
Referenced by zypp::RepoManager::cleanCacheDirGarbage(), decr(), incr(), zypp::CombinedProgressData::operator()(), zypp::operator<<(), reportValue(), tick(), and toMax().
bool zypp::ProgressData::hasRange | ( | ) | const [inline] |
[min,max]
defines a nonempty range. Definition at line 296 of file ProgressData.h.
Referenced by zypp::operator<<(), report(), reportAlive(), reportPercent(), reportValue(), and toMax().
bool zypp::ProgressData::reportPercent | ( | ) | const [inline] |
Definition at line 303 of file ProgressData.h.
References hasRange().
bool zypp::ProgressData::reportAlive | ( | ) | const [inline] |
false
. Definition at line 310 of file ProgressData.h.
References hasRange().
Referenced by zypp::CombinedProgressData::operator()().
value_type zypp::ProgressData::reportValue | ( | ) | const [inline] |
Definition at line 316 of file ProgressData.h.
References hasRange(), max(), min(), and val().
Referenced by zypp::operator<<().
const std::string& zypp::ProgressData::name | ( | ) | const [inline] |
Definition at line 320 of file ProgressData.h.
References _d.
Referenced by report().
const ReceiverFnc& zypp::ProgressData::receiver | ( | ) | const [inline] |
bool zypp::ProgressData::finalReport | ( | ) | const [inline] |
true
if this the final report sent by the ProgressData dtor. Definition at line 330 of file ProgressData.h.
Referenced by zypp::ProgressReportAdaptor::operator()().
bool zypp::ProgressData::report | ( | ) | [private] |
Send report if necessary.
Definition at line 33 of file ProgressData.cc.
References _d, DBG, END, zypp::str::form(), hasRange(), INIT, name(), zypp::Date::now(), zypp::base::ProvideNumericId< ProgressData, unsigned >::numericId(), RUN, WAR, and XXX.
Referenced by set(), and ~ProgressData().
std::ostream & operator<< | ( | std::ostream & | str, | |
const ProgressData & | obj | |||
) | [related] |
Stream output
Definition at line 107 of file ProgressData.cc.
ProgressData makeProgressData | ( | const InputStream & | input_r | ) | [related] |
Setup from InputStream.
Definition at line 125 of file ProgressData.cc.
RWCOW_pointer<Data> zypp::ProgressData::_d [private] |
Pointer to data.
Definition at line 340 of file ProgressData.h.
Referenced by finalReport(), max(), min(), name(), noSend(), receiver(), report(), sendTo(), set(), val(), and ~ProgressData().