Mercurial Hosting > traffic-intelligence
annotate c/utils.cpp @ 51:3aed17fc468d
utils to save object types
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 25 Sep 2010 11:38:42 -0400 |
parents | ef0d7caf8e91 |
children | a52653dca25d |
rev | line source |
---|---|
20
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
1 #include "utils.hpp" |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
2 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
3 #include <iostream> |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
4 #include <fstream> |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
5 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
6 using namespace std; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
7 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
8 void openWriteScientificPrecision(ofstream& out, const string& filename, const int& precision) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
9 ::openWritePrecision(out, filename, precision); |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
10 out.setf(ios::scientific); |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
11 } |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
12 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
13 void openWritePrecision(ofstream& out, const string& filename, const int& precision) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
14 out.open(filename.c_str(), ios::binary); |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
15 ::checkFileOpening(out, filename, "openWritePrecision"); |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
16 out.precision(precision); |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
17 } |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
18 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
19 bool openCheck(ifstream& f, const string& filename, const string& callingFunctionName) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
20 if (!f.is_open()) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
21 cerr << "Pb opening file " << filename << " in " << callingFunctionName << endl; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
22 return false; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
23 } else |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
24 return true; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
25 } |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
26 |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
27 bool openCheck(ofstream& f, const string& filename, const string& callingFunctionName) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
28 if (!f.is_open()) { |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
29 cerr << "Pb opening file " << filename << " in " << callingFunctionName << endl; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
30 return false; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
31 } else |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
32 return true; |
ef0d7caf8e91
draft code for feature saving (UBC format)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
3
diff
changeset
|
33 } |