]> git.donarmstrong.com Git - mothur.git/blob - progress.cpp
Initial revision
[mothur.git] / progress.cpp
1 /*
2  *  progress.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include <iostream>
11 #include <string>
12 #include "progress.hpp"
13 #include <exception>
14
15 using namespace std;
16
17 const int totalTicks = 50;
18 const char marker = '|';
19
20
21 /***********************************************************************/
22
23 Progress::Progress(string job, int end){
24         try {
25                 cout << "*******************#****#****#****#****#****#****#****#****#****#****#\n";
26                 cout << job << marker;
27                 cout.flush();
28         
29                 nTicks = 0;
30                 finalPos = end;
31         }
32         catch(exception& e) {
33                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34                 exit(1);
35         }
36         catch(...) {
37                 cout << "An unknown error has occurred in the Progress class function Progress. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40 }
41
42 /***********************************************************************/
43
44 void Progress::update(const int currentPos){
45         try {
46                 int ratio = int(totalTicks * (float)currentPos / finalPos);
47         
48                 if(ratio > nTicks){
49                         for(int i=nTicks;i<ratio;i++){
50                                 cout << marker;
51                                 cout.flush();
52                         }
53                         nTicks = ratio;
54                 }
55         }
56         catch(exception& e) {
57                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58                 exit(1);
59         }
60         catch(...) {
61                 cout << "An unknown error has occurred in the Progress class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64 }
65
66 /***********************************************************************/
67
68 void Progress::finish(){
69         try {
70                 for(int i=nTicks;i<totalTicks;i++){
71                         cout << marker;
72                         cout.flush();
73                 }
74         
75         
76                 cout << endl;
77                 cout << "**********************************************************************\n";
78                 cout.flush();
79         }
80         catch(exception& e) {
81                 cout << "Standard Error: " << e.what() << " has occurred in the Progress class Function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82                 exit(1);
83         }
84         catch(...) {
85                 cout << "An unknown error has occurred in the Progress class function finish. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86                 exit(1);
87         }
88 }
89
90 /***********************************************************************/