]> git.donarmstrong.com Git - mothur.git/blob - progress.cpp
created mothurOut class to handle logfiles
[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
11 #include "progress.hpp"
12
13 const int totalTicks = 50;
14 const char marker = '|';
15
16
17 /***********************************************************************/
18
19 Progress::Progress(){
20         try {
21                 m = MothurOut::getInstance();
22                 m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#");
23                 
24                 nTicks = 0;
25                 finalPos = 0;
26         }
27         catch(exception& e) {
28                 m->errorOut(e, "Progress", "Progress");
29                 exit(1);
30         }
31 }
32
33 /***********************************************************************/
34
35 Progress::Progress(string job, int end){
36         try {
37                 m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
38                 cout << setw(20) << left << job << setw(1) << marker;
39                 m->mothurOutJustToLog(job);
40                 m->mothurOut(toString(marker));
41                 cout.flush();
42
43                 nTicks = 0;
44                 finalPos = end;
45         }
46         catch(exception& e) {
47                 m->errorOut(e, "Progress", "Progress");
48                 exit(1);
49         }
50 }
51
52 /***********************************************************************/
53
54 void Progress::newLine(string job, int end){
55         try {
56                 m->mothurOutEndLine();
57                 cout << setw(20) << left << job << setw(1) << marker;
58                 m->mothurOutJustToLog(job);
59                 m->mothurOut(toString(marker));
60                 cout.flush();
61                 
62                 nTicks = 0;
63                 finalPos = end;
64         }
65         catch(exception& e) {
66                 m->errorOut(e, "Progress", "newLine");
67                 exit(1);
68         }
69 }
70         
71 /***********************************************************************/
72
73 void Progress::update(const int currentPos){
74         try {
75                 int ratio = int(totalTicks * (float)currentPos / finalPos);
76         
77                 if(ratio > nTicks){
78                         for(int i=nTicks;i<ratio;i++){
79                                 m->mothurOut(toString(marker));
80                                 cout.flush();
81                         }
82                         nTicks = ratio;
83                 }
84         }
85         catch(exception& e) {
86                 m->errorOut(e, "Progress", "update");
87                 exit(1);
88         }
89 }
90
91 /***********************************************************************/
92
93 void Progress::finish(){
94         try {
95                 for(int i=nTicks;i<totalTicks;i++){
96                         m->mothurOut(toString(marker));
97                         cout.flush();
98                 }
99         
100         
101                 m->mothurOutEndLine();
102                 m->mothurOut("***********************************************************************\n");
103                 cout.flush();
104         }
105         catch(exception& e) {
106                 m->errorOut(e, "Progress", "finish");
107                 exit(1);
108         }
109 }
110
111 /***********************************************************************/