1 /***************************************************************************
2  *   Copyright (C) 2016 by pgRouting developers                            *
3  *   project@pgrouting.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License t &or more details.                        *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 #ifndef SRC_PRINT_PROGRESS_H_
22 #define SRC_PRINT_PROGRESS_H_
23 #pragma once
24 
25 
26 #include <iostream>
27 #include <string>
28 
29 template < typename T1 , typename T2>
30 void
print_progress(T1 wantProgress,T2 currentProgress)31 print_progress(T1 wantProgress, T2 currentProgress) {
32     int length = 50;
33     double percent = static_cast <double> (currentProgress) /  static_cast <double>(wantProgress);
34     int fillerLength = static_cast<int>(percent * length);
35 
36     std::string bar = "[";
37     for (int i = 0; i < fillerLength; i++) {
38         bar += "*";
39     }
40 
41     bar += "|";
42     for (int i = 0; i < length - fillerLength; i++) {
43         bar += " ";
44     }
45 
46     bar += "]";
47     std::cout << "\r"
48         << bar
49         << " (" << static_cast<int>(100 * percent) << "%)"
50         << " Total processed: " << currentProgress << std::flush;
51 }
52 #endif  // SRC_PRINT_PROGRESS_H_
53