Libosmium  2.11.1
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
osmium::ProgressBar Class Reference

#include <progress_bar.hpp>

Public Member Functions

 ProgressBar (size_t max_size, bool enable) noexcept
 
 ~ProgressBar ()
 
void update (size_t current_size)
 
void file_done (size_t file_size)
 
void done ()
 
void remove ()
 

Private Member Functions

void display ()
 

Static Private Member Functions

static const char * bar () noexcept
 
static const char * spc () noexcept
 

Private Attributes

size_t m_max_size
 
size_t m_done_size = 0
 
size_t m_current_size = 0
 
size_t m_prev_percent = 100 + 1
 
bool m_enable
 
bool m_do_cleanup = true
 

Static Private Attributes

static constexpr const size_t length = 70
 

Detailed Description

Displays a progress bar on STDERR. Can be used together with the osmium::io::Reader class for instance.

Constructor & Destructor Documentation

osmium::ProgressBar::ProgressBar ( size_t  max_size,
bool  enable 
)
inlinenoexcept

Initializes the progress bar. No output yet.

Parameters
max_sizeMax size equivalent to 100%.
enableSet to false to disable (for instance if stderr is not a TTY).
osmium::ProgressBar::~ProgressBar ( )
inline

Member Function Documentation

static const char* osmium::ProgressBar::bar ( )
inlinestaticprivatenoexcept
void osmium::ProgressBar::display ( )
inlineprivate
void osmium::ProgressBar::done ( )
inline

Call this at the end. Will update the progress bar to 100% and print a final line feed. If this is not called explicitly the destructor will also call this.

void osmium::ProgressBar::file_done ( size_t  file_size)
inline

If you are reading multiple files, call this function after each file is finished.

Parameters
file_sizeThe size of the file just finished.
void osmium::ProgressBar::remove ( )
inline

Removes the progress bar. Call this before doing any other output. The next time update() is called, the progress bar will be visible again.

static const char* osmium::ProgressBar::spc ( )
inlinestaticprivatenoexcept
void osmium::ProgressBar::update ( size_t  current_size)
inline

Call this function to update the progress bar. Actual update will only happen if the percentage changed from the last time this function was called.

Parameters
current_sizeCurrent size. Used together with the max_size from constructor to calculate the percentage.

Member Data Documentation

constexpr const size_t osmium::ProgressBar::length = 70
staticprivate
size_t osmium::ProgressBar::m_current_size = 0
private
bool osmium::ProgressBar::m_do_cleanup = true
private
size_t osmium::ProgressBar::m_done_size = 0
private
bool osmium::ProgressBar::m_enable
private
size_t osmium::ProgressBar::m_max_size
private
size_t osmium::ProgressBar::m_prev_percent = 100 + 1
private

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