vSMC
vSMC: Scalable Monte Carlo
Public Types | Public Member Functions | List of all members
vsmc::Progress< ThreadType, ThisThread > Class Template Reference

Display a progress bar while algorithm proceed. More...

#include <vsmc/utility/progress.hpp>

Public Types

typedef ThreadType thread_type
 

Public Member Functions

 Progress (std::ostream &os=std::cout)
 Construct a Progress with an output stream. More...
 
void increment (std::size_t step=1)
 Increment the iteration count. More...
 
void start (std::size_t total, const std::string &msg=std::string(), std::size_t length=0, bool show_iter=false, double interval=0.1)
 Start to print the progress. More...
 
void stop (bool finished=false)
 Stop to print the progress. More...
 

Detailed Description

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
class vsmc::Progress< ThreadType, ThisThread >

Display a progress bar while algorithm proceed.

Template Parameters
ThreadTypeAny type that (partially) follows C++11 std::thread interface. In particular, the following calls shal be supported,
void (task *) (void *); // A function pointer
void *context; // A void pointer
ThreadType *thread_ptr_ = new ThreadType(task, context);
thread_ptr_->joinable();
thread_ptr_->join();
delete thread_ptr_;
ThisThreadThis shall be a class that provides a sleep static member function that allows the calling thread to sleep for a specified time in seconds. A simple implementation using C++11 sleep_for is as the following,
struct ThisThread
{
static void sleep (double s)
{
// Make the interval acurate to milliseconds
double ms = std::max(1.0, std::floor(s * 1000));
std::this_thread::sleep_for(std::chrono::milliseconds(
static_cast<std::chrono::milliseconds::rep>(ms)));
}
};
An implementation using Boost is almost the same except for the namespace changing from std to boost.

Definition at line 100 of file progress.hpp.

Member Typedef Documentation

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
typedef ThreadType vsmc::Progress< ThreadType, ThisThread >::thread_type

Definition at line 104 of file progress.hpp.

Constructor & Destructor Documentation

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
vsmc::Progress< ThreadType, ThisThread >::Progress ( std::ostream &  os = std::cout)
inline

Construct a Progress with an output stream.

Definition at line 107 of file progress.hpp.

Member Function Documentation

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
void vsmc::Progress< ThreadType, ThisThread >::increment ( std::size_t  step = 1)
inline

Increment the iteration count.

Definition at line 158 of file progress.hpp.

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
void vsmc::Progress< ThreadType, ThisThread >::start ( std::size_t  total,
const std::string &  msg = std::string(),
std::size_t  length = 0,
bool  show_iter = false,
double  interval = 0.1 
)
inline

Start to print the progress.

Parameters
totalTotal amount of work represented by an integer, for example file size or SMC algorithm total number of iterations
msgA (short) discreptive message
lengthThe length of the progress bar between brackets. If it is zero, then no bar is displayed at all
show_iterShall the iteration count be displayed.
intervalThe sleep interval in seconds

Definition at line 122 of file progress.hpp.

template<typename ThreadType = std::thread, typename ThisThread = internal::ProgressThisThread>
void vsmc::Progress< ThreadType, ThisThread >::stop ( bool  finished = false)
inline

Stop to print the progress.

Parameters
finishedIf true, then it is assumed that all work has been finished, and at the end the progress will be shown as 100% and total/total, where total is the first parameter of start. Otherwise, whatever progress has been made will be shown.

Definition at line 147 of file progress.hpp.