ModErn Text Analysis
META Enumerates Textual Applications
Public Member Functions | Static Public Member Functions | Private 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)
 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.
 

Static Public Member Functions

static void clear ()
 Clears the last line the progress bar wrote.
 

Private Member Functions

void print ()
 
void progress_thread ()
 

Private Attributes

std::thread thread_
 The background thread for printing progress updates.
 
std::mutex mutex_
 The mutex for the condition variable.
 
std::condition_variable cond_var_
 The condition variable used by the background thread for sleeping.
 
std::string output_
 The output line.
 
const std::size_t prefix_len_
 The length of the prefix.
 
const std::chrono::steady_clock::time_point start_
 The start time of the job.
 
std::atomic< uint64_t > iter_
 The current iteration number.
 
const uint64_t length_
 The total number of iterations.
 
const int interval_
 The length of time, in milliseconds, to wait between updates.
 
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

§ progress()

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

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.

§ ~progress()

meta::printing::progress::~progress ( )

Destroys this progress reporter.

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

Member Function Documentation

§ print_endline()

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

§ operator()()

void meta::printing::progress::operator() ( uint64_t  iter)

Updates the progress indicator.

Since progress is printed asynchronously, you may not immediately see results after calling this function, but they will be reflected in the next update tick.

Parameters
iterThe current iteration number to update to

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