Giter Site home page Giter Site logo

cpp-lead's Introduction

C++ Lead

I often found myself on the need of coding a progress bar in my C++ programs. It is an easy job, but often it amounts to some 10-20 lines that just needs to be typed and checked if it is working as intended. There are some packages that does the job. For example, the very popular boost library. There is also tqdm.cpp, which is a port to C++ of the very popular python module tqdm.

However, to use boost people (specially those who are starting learning) will often find easier to download the entire library when it is not actually needed. tqdm.cpp is in a pre-alpha stage last time I checked and I was not able to make it work.

It was due to these issues I made (mainly for my own use) the C++ Lead library: a header only library for generating progress bars. It is inspired on tqdm, but it does not wraps around iterators to automatically compute size and display the progress bar. Instead, you need to create an object and ask it to increase the bar on each step.

Why CPP Lead

Originally, the name was simply Progress Bar. But that was too generic. Thus, I put cpp on front of it, since it is for C++ and it became CPP Progress Bar, which was abreviated to cpppb. There were too many p's on it. But it turns out that "Pb" is the periodic table element symbol to lead. Thus, one can read "cpp pb" as cpp lead. I liked the word play and decided to stick to it.

Usage

The program below exemplifies the most basic usage:

include "ProgressBar.hpp" // Do not forget to place the ProgressBar.hpp in your include path

int main(int argv, char** argc){
    int nsteps = 100;

    ProgressBar pb(nsteps); // Create progress bar object

    for(int istep=0; istep<nsteps; ++istep){
        //<Your loop code>
        pb.step(); //Increments the display bat
    }
}

You may also add a "prefix" message to the bar by means of the constructor ProgressBar(int nsteps, std::string prefix). If you update only after a given number n of steps, you just use the ProgressBar::step(int n). This is useful if you have many iterations and wants to minimize the performance impact of printing the progress bar.

See the example folder for an example of usage. Also, look at the Makefile in the current folder as an example of how to compile a program with this library.

To see the progress bar in action, just clone this repository, compile the example with make and execute the ProgressBarExample file.

License

This software is distributed under the MIT License. See the LICENSE file for details.

cpp-lead's People

Contributors

willian-m avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.