GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixFileParser/src/openFileStream.cpp
Date: 2025-03-14 11:45:13
Exec Total Coverage
Lines: 48 48 100.0%
Branches: 58 58 100.0%

Line Branch Exec Source
1
2 /***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6 ****************************************/
7
8 #include <iostream>
9 #include "convertToString.h"
10 #include "openFileStream.h"
11
12
13 ///Open a ofstream and says if there is a problem
14 /** @param fs : ofstream to open
15 * @param fileName : name of the file in witch to write
16 * @return true on success, false otherwise
17 */
18 93 bool openFileStream(std::ofstream & fs, const PPath & fileName){
19 93 fs.open(fileName.c_str());
20
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 91 times.
93 if(!fs.is_open()){
21 2 std::cerr << "openFileStream : can't open file '" << fileName << "'" << std::endl;
22 2 return false;
23 91 }else return true;
24 }
25
26 ///Open a ofstream and says if there is a problem
27 /** @param fs : ifstream to open
28 * @param fileName : name of the file in witch to write
29 * @return true on success, false otherwise
30 */
31 93 bool openFileStream(std::ifstream & fs, const PPath & fileName){
32 93 fs.open(fileName.c_str());
33
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 91 times.
93 if(!fs.is_open()){
34 2 std::cerr << "openFileStream : can't open file '" << fileName << "'" << std::endl;
35 2 return false;
36 91 }else return true;
37 }
38
39 ///Open a vector of ofstream
40 /** @param[out] fs : vector of ofstream to be opened
41 * @param fileName : basic name of the file to be used (the file name will have a file index)
42 * @param nbFile : number of file to open
43 * @return true on success, false otherwise
44 */
45 20 bool openFileStream(PVecOFStream & fs, const PPath & fileName, size_t nbFile){
46
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
47
3/3
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
18 PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
48
7/7
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 6 taken 9 times.
✓ Branch 9 taken 9 times.
✓ Branch 12 taken 9 times.
✓ Branch 15 taken 9 times.
18 if(extention != ""){extention = PString("." + extention);}
49
1/1
✓ Branch 1 taken 18 times.
18 fs.resize(nbFile);
50 18 bool b(true);
51 18 size_t i(0lu);
52
2/2
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 18 times.
108 for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
53
8/8
✓ Branch 1 taken 90 times.
✓ Branch 4 taken 90 times.
✓ Branch 7 taken 90 times.
✓ Branch 10 taken 90 times.
✓ Branch 13 taken 90 times.
✓ Branch 16 taken 90 times.
✓ Branch 19 taken 90 times.
✓ Branch 22 taken 90 times.
180 PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
54
1/1
✓ Branch 2 taken 90 times.
90 b &= openFileStream(*it, tmpFileName);
55 90 ++i;
56 90 }
57 18 return b;
58 18 }
59
60 ///Open a vector of ifstream
61 /** @param[out] fs : vector of ifstream to be opened
62 * @param fileName : basic name of the file to be used (the file name will have a file index)
63 * @param nbFile : number of file to open
64 * @return true on success, false otherwise
65 */
66 20 bool openFileStream(PVecIFStream & fs, const PPath & fileName, size_t nbFile){
67
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
68
3/3
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
18 PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
69
7/7
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 6 taken 9 times.
✓ Branch 9 taken 9 times.
✓ Branch 12 taken 9 times.
✓ Branch 15 taken 9 times.
18 if(extention != ""){extention = PPath("." + extention);}
70
1/1
✓ Branch 1 taken 18 times.
18 fs.resize(nbFile);
71 18 bool b(true);
72 18 size_t i(0lu);
73
2/2
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 18 times.
108 for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
74
8/8
✓ Branch 1 taken 90 times.
✓ Branch 4 taken 90 times.
✓ Branch 7 taken 90 times.
✓ Branch 10 taken 90 times.
✓ Branch 13 taken 90 times.
✓ Branch 16 taken 90 times.
✓ Branch 19 taken 90 times.
✓ Branch 22 taken 90 times.
180 PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
75
1/1
✓ Branch 2 taken 90 times.
90 b &= openFileStream(*it, tmpFileName);
76 90 ++i;
77 90 }
78 18 return b;
79 18 }
80
81 ///Close a vector of ofstream
82 /** @param[out] fs : vector of ofstream to be closed
83 */
84 20 void closeFileStream(PVecOFStream & fs){
85
2/2
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 20 times.
110 for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
86
1/1
✓ Branch 2 taken 90 times.
90 it->close();
87 }
88 20 }
89
90 ///Close a vector of ifstream
91 /** @param[out] fs : vector of ifstream to be closed
92 */
93 20 void closeFileStream(PVecIFStream & fs){
94
2/2
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 20 times.
110 for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
95
1/1
✓ Branch 2 taken 90 times.
90 it->close();
96 }
97 20 }
98
99