Program Listing for File Progress.hpp
↰ Return to documentation for file (include/lvr2/util/Progress.hpp)
/*
* ProgressBar.h
*
* Created on: 14.01.2011
* Author: Thomas Wiemann
*/
#ifndef LVR2_PROGRESSBARQT_H_
#define LVR2_PROGRESSBARQT_H_
#include <string>
#include <sstream>
#include <iostream>
#include <chrono>
using std::stringstream;
using std::cout;
using std::endl;
using std::flush;
using std::string;
using std::wstring;
using std::wcout;
#include <boost/thread/mutex.hpp>
namespace lvr2
{
typedef void(*ProgressCallbackPtr)(int);
typedef void(*ProgressTitleCallbackPtr)(string);
class ProgressBar
{
public:
ProgressBar(size_t max_val, string prefix = "");
virtual ~ProgressBar();
void operator++();
void operator+=(size_t n);
static void setProgressCallback(ProgressCallbackPtr);
static void setProgressTitleCallback(ProgressTitleCallbackPtr);
protected:
void print_bar();
string m_prefix;
size_t m_maxVal;
size_t m_currentVal;
boost::mutex m_mutex;
int m_percent;
std::chrono::time_point<std::chrono::system_clock> m_start;
stringstream m_stream;
string m_fillstring;
static ProgressCallbackPtr m_progressCallback;
static ProgressTitleCallbackPtr m_titleCallback;
};
class ProgressCounter
{
public:
/***
* @brief CTor.
*
* @param stepVal After m_stepVal operations a new output is generated
* @param prefix The prefix string for progress output
*/
ProgressCounter(int stepVal, string prefix = "");
/***
* @brief Increase the progress counter
*/
void operator++();
protected:
void print_progress();
string m_prefix;
size_t m_stepVal;
size_t m_currentVal;
boost::mutex m_mutex;
stringstream m_stream;
string m_fillstring;
};
typedef void(*PacmanProgressCallbackPtr)(int);
typedef void(*PacmanProgressTitleCallbackPtr)(string);
class PacmanProgressBar
{
public:
PacmanProgressBar(size_t max_val, string prefix = "", size_t bar_length = 60 );
virtual ~PacmanProgressBar();
void operator++();
static void setProgressCallback(ProgressCallbackPtr);
static void setProgressTitleCallback(ProgressTitleCallbackPtr);
protected:
void print_bar();
string m_prefix;
size_t m_maxVal;
size_t m_currentVal;
boost::mutex m_mutex;
int m_percent;
// bar length
int m_bar_length;
stringstream m_stream;
string m_fillstring;
static PacmanProgressCallbackPtr m_progressCallback;
static PacmanProgressTitleCallbackPtr m_titleCallback;
};
} // namespace lvr2
#endif /* PROGRESSBAR_H_ */