-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoutput_log.cpp
79 lines (67 loc) · 1.32 KB
/
output_log.cpp
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
/*
* log.cpp
*
* Created on: Nov 11, 2009
* Author: Adam Auton
* ($Revision: 66 $)
*/
#include "output_log.h"
void printLOG(string s)
{
cout << s; cout.flush();
LOG << s; LOG.flush();
}
void error(string err_msg, int error_code)
{
printLOG("Error:" + err_msg + "\n");
exit(error_code);
}
void 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 counted_warning(string err_msg)
{
static unsigned int warning_count = 0;
printLOG(err_msg + "\n");
warning_count++;
if (warning_count > 1000)
error("Stopping at 1000 entry-level warnings", 10);
}
void warning(string err_msg)
{
printLOG(err_msg + "\n");
}
string int2str(int n)
{
std::ostringstream s2( std::stringstream::out );
s2 << n;
return s2.str();
}
string longint2str(long int n)
{
std::ostringstream s2( std::stringstream::out );
s2 << n;
return s2.str();
}
string dbl2str(double n, int prc)
{
std::ostringstream s2;
if ( prc > 0 )
s2.precision(prc);
s2 << n;
return s2.str();
}
string dbl2str_fixed(double n, int prc)
{
std::ostringstream s2;
s2 << setiosflags( ios::fixed );
if ( prc > 0 )
s2.precision(prc);
s2 << n;
return s2.str();
}