forked from hundlab/LongQt-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iobase.cpp
53 lines (48 loc) · 1.31 KB
/
iobase.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
//################################################
// This code file
// defines an abstract class used to read and write
//
// Copyright (C) 2015 Thomas J. Hund.
// Updated 07/2015
// Email thomas.hund@osumc.edu
//#################################################
#include <QDebug>
#include "iobase.h"
bool IOBase::setOutputfile(string filename, set<string> set, ofstream* ofile) {
ifstream test;
bool exists;
std::set<string>::iterator it;
test.open(filename);
exists = test.good();
test.close();
if(ofile->is_open()) {
ofile->close();
}
ofile->precision(10);
ofile->open(filename,ios_base::app);
if(!ofile->good()) {
qCritical() << "Error Opening " << filename.c_str();
return false;
} else if(!exists) {
for(it = set.begin(); it != set.end(); it++) {
*ofile << *it << "\t";
}
*ofile << endl;
}
return true;
};
bool IOBase::write(set<string> selection, map<string, double*> map, ofstream* ofile) {
if(!ofile->good()) {
return false;
}
for(set<string>::iterator it = selection.begin(); it != selection.end(); it++) {
*ofile << *map[*it] << "\t";
}
*ofile << endl;
return true;
};
void IOBase::closeFile(ofstream* ofile) {
if(ofile->is_open()) {
ofile->close();
}
}