File: output_log.cpp

package info (click to toggle)
vcftools 0.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,396 kB
  • sloc: perl: 10,233; cpp: 7,950; pascal: 751; makefile: 60; php: 43; sh: 12
file content (102 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download
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
/*
 * log.cpp
 *
 *  Created on: Nov 11, 2009
 *      Author: Adam Auton
 *      ($Revision: 66 $)
 */

#include "output_log.h"

output_log::output_log() : output_to_screen(true)
{

}

void output_log::open(const string &filename_prefix )
{
	LOG.open((filename_prefix + ".log").c_str());
}

void output_log::close()
{
	LOG.close();
}

void output_log::set_screen_output(bool do_screen_output)
{
	output_to_screen = do_screen_output;
}

void output_log::printLOG(string s)
{
	LOG << s; LOG.flush();
	if (output_to_screen)
	{
		cout << s; cout.flush();
	}
}

void output_log::error(string err_msg, int error_code)
{
	printLOG("Error:" + err_msg + "\n");
	exit(error_code);
}


void output_log::error(string err_msg, double value1, double value2, int error_code)
{
	printLOG("Error:" + err_msg + "\n");
	stringstream ss;
	ss << "Value1=" << value1 << " Value2=" << value2 << endl;
	printLOG(ss.str());
	exit(error_code);
}

void output_log::warning(string err_msg)
{
	printLOG(err_msg + "\n");
}

void output_log::one_off_warning(string err_msg)
{
	static set<string> previous_warnings;
	if (previous_warnings.find(err_msg) == previous_warnings.end())
	{
		printLOG(err_msg + "\n");
		previous_warnings.insert(err_msg);
	}
}

string output_log::int2str(int n)
{
  std::ostringstream s2( std::stringstream::out );
  s2 << n;
  return s2.str();
}

string output_log::longint2str(long int n)
{
  std::ostringstream s2( std::stringstream::out );
  s2 << n;
  return s2.str();
}

string output_log::dbl2str(double n, int prc)
{
  std::ostringstream s2;
  if ( prc > 0 )
    s2.precision(prc);
  s2 << n;
  return s2.str();
}

string output_log::dbl2str_fixed(double n, int prc)
{
  std::ostringstream s2;
  s2 << setiosflags( ios::fixed );
  if ( prc > 0 )
    s2.precision(prc);
  s2 << n;
  return s2.str();
}