libzypp 17.31.23
zypp::ProgressData Class Reference

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

#include <ui/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.
 

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, because a progress receiver may return false to indicate the desire to abort the pending action. The incident is logged, but it's finally up to the caller to honor this.

bool set (value_type val_r)
 Set new counter value.
 
bool set (const ProgressData &rhs)
 Set range and counter from an other ProgressData.
 
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).
 
- Public Member Functions inherited from zypp::base::ProvideNumericId< ProgressData, unsigned >
unsigned numericId () const
 

Private Types

enum  State { INIT , RUN , END }
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &str, const ProgressData &obj)
 Stream output.
 
ProgressData makeProgressData (const InputStream &input_r)
 Setup from InputStream.
 

Progress receiving.

RWCOW_pointer< Data_d
 Pointer to data.
 
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
 
bool report ()
 Send report if necessary.
 

Additional Inherited Members

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

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( const ProgressData & ticks_r )
{
DBG << "got ->" << ticks_r.reportValue() << " (" << ticks_r.val() << ")" << endl;
return( ticks_r.val() <= 100 ); // Abort if ( val > 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:
ProgressData::ReceiverFnc _fnc;
};
Maintain [min,max] and counter (value) for progress counting.
Definition: progressdata.h:132
value_type reportValue() const
Definition: progressdata.h:322
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: progressdata.h:140
value_type val() const
Definition: progressdata.h:298
#define DBG
Definition: Logger.h:95
Example t( exampleReceiver );
DBG << "Reporting %:" << endl;
t.action();
DBG << "Reporting 'still alive':" << endl;
t.action2();
Reporting %:
got ->0 (0)
got ->10 (1)
got ->20 (2)
got ->30 (3)
got ->40 (4)
got ->50 (5)
got ->60 (6)
got ->70 (7)
got ->80 (8)
got ->90 (9)
got ->100 (10)
got ->100 (10)
Reporting 'still alive':
got ->-1 (0)
got ->-1 (9)

The different ammount of triggers is due to different rules for sending percent or 'still alive' messages.

Definition at line 131 of file progressdata.h.

Member Typedef Documentation

◆ value_type

typedef long long zypp::ProgressData::value_type

Definition at line 134 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 140 of file progressdata.h.

Member Enumeration Documentation

◆ State

Enumerator
INIT 
RUN 
END 

Definition at line 143 of file progressdata.h.

Constructor & Destructor Documentation

◆ ProgressData() [1/4]

zypp::ProgressData::ProgressData ( )
inline

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

Definition at line 174 of file progressdata.h.

◆ ProgressData() [2/4]

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

Ctor [0,max](0).

Definition at line 179 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 184 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 189 of file progressdata.h.

◆ ~ProgressData()

zypp::ProgressData::~ProgressData ( )
inline

Definition at line 193 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 204 of file progressdata.h.

◆ max() [1/2]

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

Set new max value.

Definition at line 208 of file progressdata.h.

◆ noRange()

void zypp::ProgressData::noRange ( )
inline

Set no range [0,0].

Definition at line 212 of file progressdata.h.

◆ range() [1/2]

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

Set new [0,max].

Definition at line 216 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 220 of file progressdata.h.

◆ name() [1/2]

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

Set counter name.

Definition at line 225 of file progressdata.h.

◆ sendTo()

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

Set ReceiverFnc.

Definition at line 229 of file progressdata.h.

◆ noSend()

void zypp::ProgressData::noSend ( )
inline

Set no ReceiverFnc.

Definition at line 233 of file progressdata.h.

◆ set() [1/2]

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

Set new counter value.

Definition at line 249 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 256 of file progressdata.h.

◆ incr()

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

Increment counter value (default by 1).

Definition at line 264 of file progressdata.h.

◆ decr()

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

Decrement counter value (default by 1).

Definition at line 268 of file progressdata.h.

◆ toMin()

bool zypp::ProgressData::toMin ( )
inline

Set counter value to current min value.

Definition at line 272 of file progressdata.h.

◆ toMax()

bool zypp::ProgressData::toMax ( )
inline

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

Definition at line 276 of file progressdata.h.

◆ tick()

bool zypp::ProgressData::tick ( )
inline

Leave counter value unchanged (still alive).

Definition at line 280 of file progressdata.h.

◆ min() [2/2]

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

Definition at line 290 of file progressdata.h.

◆ max() [2/2]

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

Definition at line 294 of file progressdata.h.

◆ val()

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

Definition at line 298 of file progressdata.h.

◆ hasRange()

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

Definition at line 302 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 309 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 316 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 322 of file progressdata.h.

◆ name() [2/2]

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

Definition at line 326 of file progressdata.h.

◆ receiver()

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

Definition at line 330 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 336 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 105 of file progressdata.cc.

◆ makeProgressData()

ProgressData makeProgressData ( const InputStream input_r)
related

Setup from InputStream.

Definition at line 123 of file progressdata.cc.

Member Data Documentation

◆ _d

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

Pointer to data.

Definition at line 346 of file progressdata.h.


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