ModErn Text Analysis
META Enumerates Textual Applications
Public Member Functions | Private Attributes | List of all members
meta::printing::progress Class Reference

Simple class for reporting progress of lengthy operations. More...

#include <progress.h>

Public Member Functions

 progress (const std::string &prefix, uint64_t length, int interval=500, uint64_t min_iters=10)
 Constructs a progress reporter with the given prefix and iteration length. More...
 
void print_endline (bool endline)
 Sets whether or not an endline should be printed at completion. More...
 
 ~progress ()
 Destroys this progress reporter. More...
 
void operator() (uint64_t iter)
 Updates the progress indicator. More...
 
void end ()
 Marks the progress indicator as having finished.
 
void clear () const
 Clears the last line the progress bar wrote.
 

Private Attributes

std::string prefix_
 The prefix for the progress report message.
 
std::chrono::steady_clock::time_point start_
 The start time of the job.
 
std::chrono::steady_clock::time_point last_update_
 The time of the last update.
 
uint64_t last_iter_
 The last iteration number.
 
uint64_t length_
 The total number of iterations.
 
int interval_
 The length of time, in milliseconds, to wait between updates.
 
uint64_t min_iters_
 The minimum number of iterations that must pass before progress reporting will be considered.
 
uint64_t str_len_
 The length of the last progress output message.
 
bool finished_
 Whether or not we have finished the job.
 
bool endline_
 Whether or not we should print an endline when done.
 

Detailed Description

Simple class for reporting progress of lengthy operations.

Inspired by noamraph/tqdm.

See also
https://github.com/noamraph/tqdm/

Constructor & Destructor Documentation

meta::printing::progress::progress ( const std::string &  prefix,
uint64_t  length,
int  interval = 500,
uint64_t  min_iters = 10 
)

Constructs a progress reporter with the given prefix and iteration length.

Parameters
prefixThe string to be printed right before the progress output
lengthThe number of iterations
intervalThe length of time, in milliseconds, to wait between updates. Default = 500ms.
min_itersThe minimum number of iterations that must pass before progress reporting will be considered
meta::printing::progress::~progress ( )

Destroys this progress reporter.

It will call end() if it has not already been called.

Member Function Documentation

void meta::printing::progress::print_endline ( bool  endline)

Sets whether or not an endline should be printed at completion.

Parameters
endlineWhether or not an endline should be printed at completion
void meta::printing::progress::operator() ( uint64_t  iter)

Updates the progress indicator.

Parameters
iterThe current iteration number to update to

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