File: progress.cpp

package info (click to toggle)
mothur 1.33.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,248 kB
  • ctags: 12,231
  • sloc: cpp: 152,046; fortran: 665; makefile: 74; sh: 34
file content (114 lines) | stat: -rw-r--r-- 2,384 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *  progress.cpp
 *  
 *
 *  Created by Pat Schloss on 8/14/08.
 *  Copyright 2008 Patrick D. Schloss. All rights reserved.
 *
 */


#include "progress.hpp"

const int totalTicks = 50;
const char marker = '|';


/***********************************************************************/

Progress::Progress(){
	try {
		m = MothurOut::getInstance();
		m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#");
		
		nTicks = 0;
		finalPos = 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Progress", "Progress");
		exit(1);
	}
}

/***********************************************************************/

Progress::Progress(string job, int end){
	try {
		m = MothurOut::getInstance();
		
		m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
		cout << setw(20) << left << job << setw(1) << marker;
		m->mothurOutJustToLog(job);
		m->mothurOut(toString(marker));
		cout.flush();

		nTicks = 0;
		finalPos = end;
		
	}
	catch(exception& e) {
		m->errorOut(e, "Progress", "Progress");
		exit(1);
	}
}

/***********************************************************************/

void Progress::newLine(string job, int end){
	try {
		m->mothurOutEndLine();
		cout << setw(20) << left << job << setw(1) << marker;
		m->mothurOutJustToLog(job);
		m->mothurOut(toString(marker));
		cout.flush();
		
		nTicks = 0;
		finalPos = end;
	}
	catch(exception& e) {
		m->errorOut(e, "Progress", "newLine");
		exit(1);
	}
}
	
/***********************************************************************/

void Progress::update(const int currentPos){
	try {
		int ratio = int(totalTicks * (float)currentPos / finalPos);
	
		if(ratio > nTicks){
			for(int i=nTicks;i<ratio;i++){
				m->mothurOut(toString(marker));
				cout.flush();
			}
			nTicks = ratio;
		}
	}
	catch(exception& e) {
		m->errorOut(e, "Progress", "update");
		exit(1);
	}
}

/***********************************************************************/

void Progress::finish(){
	try {
		for(int i=nTicks;i<totalTicks;i++){
			m->mothurOut(toString(marker));
			cout.flush();
		}
	
	
		m->mothurOutEndLine();
		m->mothurOut("***********************************************************************\n");
		cout.flush();
	}
	catch(exception& e) {
		m->errorOut(e, "Progress", "finish");
		exit(1);
	}
}

/***********************************************************************/