Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
osmium::ProgressBar Class Reference

#include <progress_bar.hpp>

Public Member Functions

 ProgressBar (std::size_t max_size, bool enable) noexcept
 
 ProgressBar (const ProgressBar &)=delete
 
ProgressBaroperator= (const ProgressBar &)=delete
 
 ProgressBar (ProgressBar &&) noexcept=default
 
ProgressBaroperator= (ProgressBar &&)=default
 
 ~ProgressBar ()
 
void update (std::size_t current_size)
 
void file_done (std::size_t file_size)
 
void done ()
 
void remove ()
 

Private Types

enum  { full_length = 70 }
 

Private Member Functions

void display ()
 

Static Private Member Functions

static const char * bar (std::size_t len=full_length) noexcept
 
static const char * spc (std::size_t len=full_length) noexcept
 

Private Attributes

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

Detailed Description

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

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
full_length 

Constructor & Destructor Documentation

◆ ProgressBar() [1/3]

osmium::ProgressBar::ProgressBar ( std::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).

◆ ProgressBar() [2/3]

osmium::ProgressBar::ProgressBar ( const ProgressBar )
delete

◆ ProgressBar() [3/3]

osmium::ProgressBar::ProgressBar ( ProgressBar &&  )
defaultnoexcept

◆ ~ProgressBar()

osmium::ProgressBar::~ProgressBar ( )
inline

Member Function Documentation

◆ bar()

static const char * osmium::ProgressBar::bar ( std::size_t  len = full_length)
inlinestaticprivatenoexcept

◆ display()

void osmium::ProgressBar::display ( )
inlineprivate

◆ done()

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.

◆ file_done()

void osmium::ProgressBar::file_done ( std::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.

◆ operator=() [1/2]

ProgressBar & osmium::ProgressBar::operator= ( const ProgressBar )
delete

◆ operator=() [2/2]

ProgressBar & osmium::ProgressBar::operator= ( ProgressBar &&  )
default

◆ remove()

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.

◆ spc()

static const char * osmium::ProgressBar::spc ( std::size_t  len = full_length)
inlinestaticprivatenoexcept

◆ update()

void osmium::ProgressBar::update ( std::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

◆ m_current_size

std::size_t osmium::ProgressBar::m_current_size = 0
private

◆ m_do_cleanup

bool osmium::ProgressBar::m_do_cleanup = true
private

◆ m_done_size

std::size_t osmium::ProgressBar::m_done_size = 0
private

◆ m_enable

bool osmium::ProgressBar::m_enable
private

◆ m_max_size

std::size_t osmium::ProgressBar::m_max_size
private

◆ m_prev_percent

std::size_t osmium::ProgressBar::m_prev_percent = 100 + 1
private

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