Lagrange
ProgressCallback Class Reference

A simple thread-safe progress callback. More...

#include <lagrange/utils/ProgressCallback.h>

Public Member Functions

 ProgressCallback (std::function< void(const std::string &, float)> func=nullptr, std::string name="", size_t num_iterations=1)
 Constructs a new instance. More...
 
void set_callback (std::function< void(const std::string &, float)> func)
 Set notification callback. More...
 
void set_section (std::string name, size_t num_iterations=1)
 Starts a new section, reset current iteration counter to 0, and notify. More...
 
const std::string & get_section () const
 Retrieves current section name. More...
 
void set_num_iterations (size_t num_iterations)
 Sets the number iterations for this section. More...
 
void advance (size_t increment)
 Updates the current iteration number by a fixed amount, and sends a notification. More...
 
void update ()
 Updates the current iteration number by one, and sends a notification. More...
 
void update (float progress)
 Updates the current progress to a fixed percentage. More...
 
void set_verbose (bool verbose)
 Sets the verbosity. More...
 

Detailed Description

A simple thread-safe progress callback.

Constructor & Destructor Documentation

◆ ProgressCallback()

ProgressCallback ( std::function< void(const std::string &, float)>  func = nullptr,
std::string  name = "",
size_t  num_iterations = 1 
)

Constructs a new instance.

Parameters
[in]funcNotification callback. This callback function will be called in a thread-safe manner by the update() method.
[in]nameDefault section name.
[in]num_iterationsNumber of iterations for this section.

Member Function Documentation

◆ set_callback()

void set_callback ( std::function< void(const std::string &, float)>  func)

Set notification callback.

Parameters
[in]funcNotification callback. This callback function will be called in a thread-safe manner by the update() method.

◆ set_section()

void set_section ( std::string  name,
size_t  num_iterations = 1 
)

Starts a new section, reset current iteration counter to 0, and notify.

This method is not thread-safe.

Parameters
[in]nameSection name.
[in]num_iterationsNumber of iterations for this section.

◆ get_section()

const std::string & get_section ( ) const
inline

Retrieves current section name.

Returns
Name of the current section.

◆ set_num_iterations()

void set_num_iterations ( size_t  num_iterations)

Sets the number iterations for this section.

No notification is sent. This method is not thread-safe.

Parameters
[in]num_iterationsNumber of iterations for this section.

◆ advance()

void advance ( size_t  increment)

Updates the current iteration number by a fixed amount, and sends a notification.

It is safe to call this method from multiple threads.

◆ update() [1/2]

void update ( )

Updates the current iteration number by one, and sends a notification.

It is safe to call this method from multiple threads.

◆ update() [2/2]

void update ( float  progress)

Updates the current progress to a fixed percentage.

Parameters
[in]progressCurrent progress between 0 and 1.

◆ set_verbose()

void set_verbose ( bool  verbose)
inline

Sets the verbosity.

A verbose progress callback will print the section name as debug info whenever set_section is called with a non-empty section name.

Parameters
[in]verboseVerbosity level.

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