libzypp  17.3.1
zypp::ProgressData Class Reference

Maintain [min,max] and counter (value) for progress counting. More...

#include <ProgressData.h>

Inheritance diagram for zypp::ProgressData:

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. More...
 

Public Member Functions

 ProgressData ()
 Ctor no range [0,0](0). More...
 
 ProgressData (value_type max_r)
 Ctor [0,max](0). More...
 
 ProgressData (value_type min_r, value_type max_r)
 Ctor [min,max](min). More...
 
 ProgressData (value_type min_r, value_type max_r, value_type val_r)
 Ctor [min,max](val). More...
 
 ~ProgressData ()
 
void min (value_type min_r)
 Set new min value. More...
 
void max (value_type max_r)
 Set new max value. More...
 
void noRange ()
 Set no range [0,0]. More...
 
void range (value_type max_r)
 Set new [0,max]. More...
 
void range (value_type min_r, value_type max_r)
 Set new [min,max]. More...
 
void name (const std::string &name_r)
 Set counter name. More...
 
void sendTo (const ReceiverFnc &fnc_r)
 Set ReceiverFnc. More...
 
void noSend ()
 Set no ReceiverFnc. More...
 
Progress reporting.

These methods may actually cause a progress report to be sent.

All methods return bool, because a progress receiver may return false to indicate the desire to abort the pending action. The incident is logged, but it's finaly up to the caller to honor this.

bool set (value_type val_r)
 Set new counter value. More...
 
bool set (const ProgressData &rhs)
 Set range and counter from an other ProgressData. More...
 
bool incr (value_type val_r=1)
 Increment counter value (default by 1). More...
 
bool decr (value_type val_r=1)
 Decrement counter value (default by 1). More...
 
bool toMin ()
 Set counter value to current min value. More...
 
bool toMax ()
 Set counter value to current max value (unless no range). More...
 
bool tick ()
 Leave counter value unchanged (still alive). More...
 
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 ReceiverFncreceiver () const
 
bool finalReport () const
 
- Public Member Functions inherited from zypp::base::ProvideNumericId< ProgressData, unsigned >
unsigned numericId () const
 

Private Types

enum  State { INIT, RUN, END }
 

Private Member Functions

bool report ()
 Send report if necessary. More...
 

Private Attributes

RWCOW_pointer< Data_d
 Pointer to data. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &str, const ProgressData &obj)
 
ProgressData makeProgressData (const InputStream &input_r)
 

Additional Inherited Members

- Protected Member Functions inherited from zypp::base::ProvideNumericId< ProgressData, unsigned >
 ProvideNumericId ()
 Default ctor. More...
 
 ProvideNumericId (const ProvideNumericId &)
 Copy ctor. More...
 
 ProvideNumericId (const void *const)
 No-Id ctor (0). More...
 
ProvideNumericIdoperator= (const ProvideNumericId &)
 Assign. More...
 
 ~ProvideNumericId ()
 Dtor. More...
 

Detailed Description

Maintain [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 whether 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:
: _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:
};
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.

Definition at line 130 of file ProgressData.h.

Member Typedef Documentation

◆ value_type

typedef long long zypp::ProgressData::value_type

Definition at line 133 of file ProgressData.h.

◆ ReceiverFnc

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 139 of file ProgressData.h.

Member Enumeration Documentation

◆ State

Enumerator
INIT 
RUN 
END 

Definition at line 142 of file ProgressData.h.

Constructor & Destructor Documentation

◆ ProgressData() [1/4]

zypp::ProgressData::ProgressData ( )
inline

Ctor no range [0,0](0).

Definition at line 171 of file ProgressData.h.

◆ ProgressData() [2/4]

zypp::ProgressData::ProgressData ( value_type  max_r)
inline

Ctor [0,max](0).

Definition at line 176 of file ProgressData.h.

◆ ProgressData() [3/4]

zypp::ProgressData::ProgressData ( value_type  min_r,
value_type  max_r 
)
inline

Ctor [min,max](min).

Definition at line 181 of file ProgressData.h.

◆ ProgressData() [4/4]

zypp::ProgressData::ProgressData ( value_type  min_r,
value_type  max_r,
value_type  val_r 
)
inline

Ctor [min,max](val).

Definition at line 186 of file ProgressData.h.

◆ ~ProgressData()

zypp::ProgressData::~ProgressData ( )
inline

Definition at line 190 of file ProgressData.h.

Member Function Documentation

◆ min() [1/2]

void zypp::ProgressData::min ( value_type  min_r)
inline

Set new min value.

Definition at line 201 of file ProgressData.h.

◆ max() [1/2]

void zypp::ProgressData::max ( value_type  max_r)
inline

Set new max value.

Definition at line 205 of file ProgressData.h.

◆ noRange()

void zypp::ProgressData::noRange ( )
inline

Set no range [0,0].

Definition at line 209 of file ProgressData.h.

◆ range() [1/2]

void zypp::ProgressData::range ( value_type  max_r)
inline

Set new [0,max].

Definition at line 213 of file ProgressData.h.

◆ range() [2/2]

void zypp::ProgressData::range ( value_type  min_r,
value_type  max_r 
)
inline

Set new [min,max].

Definition at line 217 of file ProgressData.h.

◆ name() [1/2]

void zypp::ProgressData::name ( const std::string &  name_r)
inline

Set counter name.

Definition at line 222 of file ProgressData.h.

◆ sendTo()

void zypp::ProgressData::sendTo ( const ReceiverFnc fnc_r)
inline

Set ReceiverFnc.

Definition at line 226 of file ProgressData.h.

◆ noSend()

void zypp::ProgressData::noSend ( )
inline

Set no ReceiverFnc.

Definition at line 230 of file ProgressData.h.

◆ set() [1/2]

bool zypp::ProgressData::set ( value_type  val_r)
inline

Set new counter value.

Definition at line 246 of file ProgressData.h.

◆ set() [2/2]

bool zypp::ProgressData::set ( const ProgressData rhs)
inline

Set range and counter from an other ProgressData.

Definition at line 253 of file ProgressData.h.

◆ incr()

bool zypp::ProgressData::incr ( value_type  val_r = 1)
inline

Increment counter value (default by 1).

Definition at line 261 of file ProgressData.h.

◆ decr()

bool zypp::ProgressData::decr ( value_type  val_r = 1)
inline

Decrement counter value (default by 1).

Definition at line 265 of file ProgressData.h.

◆ toMin()

bool zypp::ProgressData::toMin ( )
inline

Set counter value to current min value.

Definition at line 269 of file ProgressData.h.

◆ toMax()

bool zypp::ProgressData::toMax ( )
inline

Set counter value to current max value (unless no range).

Definition at line 273 of file ProgressData.h.

◆ tick()

bool zypp::ProgressData::tick ( )
inline

Leave counter value unchanged (still alive).

Definition at line 277 of file ProgressData.h.

◆ min() [2/2]

value_type zypp::ProgressData::min ( ) const
inline
Returns
Current min value.

Definition at line 287 of file ProgressData.h.

◆ max() [2/2]

value_type zypp::ProgressData::max ( ) const
inline
Returns
Current max value.

Definition at line 291 of file ProgressData.h.

◆ val()

value_type zypp::ProgressData::val ( ) const
inline
Returns
Current counter value.

Definition at line 295 of file ProgressData.h.

◆ hasRange()

bool zypp::ProgressData::hasRange ( ) const
inline
Returns
Whether [min,max] defines a nonempty range.

Definition at line 299 of file ProgressData.h.

◆ reportPercent()

bool zypp::ProgressData::reportPercent ( ) const
inline
Returns
Whether reportValue will return a percent value. Same as hasRange.
See also
reportAlive

Definition at line 306 of file ProgressData.h.

◆ reportAlive()

bool zypp::ProgressData::reportAlive ( ) const
inline
Returns
Whether reportValue always returns -1, because we trigger 'still alive' messages. I.e. hasrange is false.
See also
reportPercent

Definition at line 313 of file ProgressData.h.

◆ reportValue()

value_type zypp::ProgressData::reportValue ( ) const
inline
Returns
Either a a percent value or -1.
See also
reportPercent and reportAlive.

Definition at line 319 of file ProgressData.h.

◆ name() [2/2]

const std::string& zypp::ProgressData::name ( ) const
inline
Returns
The counters name.

Definition at line 323 of file ProgressData.h.

◆ receiver()

const ReceiverFnc& zypp::ProgressData::receiver ( ) const
inline
Returns
The ReceiverFnc.

Definition at line 327 of file ProgressData.h.

◆ finalReport()

bool zypp::ProgressData::finalReport ( ) const
inline
Returns
Return true if this is the final report sent by the ProgressData dtor.

Definition at line 333 of file ProgressData.h.

◆ report()

bool zypp::ProgressData::report ( )
private

Send report if necessary.

Definition at line 33 of file ProgressData.cc.

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  str,
const ProgressData obj 
)
related

Stream output

Definition at line 99 of file ProgressData.cc.

◆ makeProgressData()

ProgressData makeProgressData ( const InputStream input_r)
related

Setup from InputStream.

Definition at line 117 of file ProgressData.cc.

Member Data Documentation

◆ _d

RWCOW_pointer<Data> zypp::ProgressData::_d
private

Pointer to data.

Definition at line 343 of file ProgressData.h.


The documentation for this class was generated from the following files: