1 : |
agomez |
1 |
#include "printinfo.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "gadget.h" |
4 : |
|
|
#include "global.h" |
5 : |
|
|
|
6 : |
|
|
PrintInfo::PrintInfo() : printiter(0), printoutput(0), givenPrecision(0) {
|
7 : |
|
|
|
8 : |
|
|
strOutputFile = NULL;
|
9 : |
|
|
strParamOutFile = NULL;
|
10 : |
|
|
|
11 : |
|
|
char tmpname[12];
|
12 : |
|
|
strncpy(tmpname, "", 12);
|
13 : |
|
|
strcpy(tmpname, "params.out");
|
14 : |
|
|
setParamOutFile(tmpname);
|
15 : |
|
|
}
|
16 : |
|
|
|
17 : |
|
|
PrintInfo::PrintInfo(const PrintInfo& pi) {
|
18 : |
|
|
|
19 : |
|
|
strParamOutFile = NULL;
|
20 : |
|
|
setParamOutFile(pi.strParamOutFile);
|
21 : |
|
|
|
22 : |
|
|
strOutputFile = NULL;
|
23 : |
|
|
if (pi.strOutputFile != NULL)
|
24 : |
|
|
setOutputFile(pi.strOutputFile);
|
25 : |
|
|
|
26 : |
|
|
printoutput = pi.printoutput;
|
27 : |
|
|
givenPrecision = pi.givenPrecision;
|
28 : |
|
|
printiter = pi.printiter;
|
29 : |
|
|
}
|
30 : |
|
|
|
31 : |
|
|
PrintInfo::~PrintInfo() {
|
32 : |
|
|
if (strOutputFile != NULL) {
|
33 : |
|
|
delete[] strOutputFile;
|
34 : |
|
|
strOutputFile = NULL;
|
35 : |
|
|
}
|
36 : |
|
|
if (strParamOutFile != NULL) {
|
37 : |
|
|
delete[] strParamOutFile;
|
38 : |
|
|
strParamOutFile = NULL;
|
39 : |
|
|
}
|
40 : |
|
|
}
|
41 : |
|
|
|
42 : |
|
|
void PrintInfo::setOutputFile(char* filename) {
|
43 : |
|
|
if (strOutputFile != NULL) {
|
44 : |
|
|
delete[] strOutputFile;
|
45 : |
|
|
strOutputFile = NULL;
|
46 : |
|
|
}
|
47 : |
|
|
if (filename != NULL) {
|
48 : |
|
|
strOutputFile = new char[strlen(filename) + 1];
|
49 : |
|
|
strcpy(strOutputFile, filename);
|
50 : |
|
|
printoutput = 1;
|
51 : |
|
|
} else {
|
52 : |
|
|
strOutputFile = NULL;
|
53 : |
|
|
}
|
54 : |
|
|
}
|
55 : |
|
|
|
56 : |
|
|
void PrintInfo::setParamOutFile(char* filename) {
|
57 : |
|
|
if (strParamOutFile != NULL) {
|
58 : |
|
|
delete[] strParamOutFile;
|
59 : |
|
|
strParamOutFile = NULL;
|
60 : |
|
|
}
|
61 : |
|
|
if (filename != NULL) {
|
62 : |
|
|
strParamOutFile = new char[strlen(filename) + 1];
|
63 : |
|
|
strcpy(strParamOutFile, filename);
|
64 : |
|
|
} else {
|
65 : |
|
|
strParamOutFile = NULL;
|
66 : |
|
|
}
|
67 : |
|
|
}
|
68 : |
|
|
|
69 : |
|
|
void PrintInfo::checkPrintInfo(int network) {
|
70 : |
|
|
if (printiter < 1)
|
71 : |
|
|
printiter = 1;
|
72 : |
|
|
if (givenPrecision < 0)
|
73 : |
|
|
givenPrecision = 0;
|
74 : |
|
|
|
75 : |
|
|
//JMB check to see if we can actually open required files ...
|
76 : |
|
|
ofstream tmpfile;
|
77 : |
|
|
if (!network) {
|
78 : |
|
|
tmpfile.open(strParamOutFile, ios::out);
|
79 : |
|
|
handle.checkIfFailure(tmpfile, strParamOutFile);
|
80 : |
|
|
tmpfile.close();
|
81 : |
|
|
tmpfile.clear();
|
82 : |
|
|
}
|
83 : |
|
|
if (printoutput) {
|
84 : |
|
|
tmpfile.open(strOutputFile, ios::out);
|
85 : |
|
|
handle.checkIfFailure(tmpfile, strOutputFile);
|
86 : |
|
|
tmpfile.close();
|
87 : |
|
|
tmpfile.clear();
|
88 : |
|
|
}
|
89 : |
|
|
}
|