GCC Code Coverage Report


Directory: ./
File: src/openFileStream.cpp
Date: 2025-09-08 16:55:04
Exec Total Coverage
Lines: 48 48 100.0%
Functions: 6 6 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 0 (5→6) taken 2 times.
✓ Branch 1 (5→11) 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 0 (5→6) taken 2 times.
✓ Branch 1 (5→11) 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 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 18 times.
20 if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
47
3/3
✓ Branch 0 (4→5) taken 18 times.
✓ Branch 2 (5→6) taken 18 times.
✓ Branch 4 (6→7) taken 18 times.
18 PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
48
7/7
✓ Branch 0 (8→9) taken 18 times.
✓ Branch 2 (9→10) taken 9 times.
✓ Branch 3 (9→18) taken 9 times.
✓ Branch 4 (10→11) taken 9 times.
✓ Branch 6 (11→12) taken 9 times.
✓ Branch 8 (12→13) taken 9 times.
✓ Branch 10 (13→14) taken 9 times.
18 if(extention != ""){extention = PString("." + extention);}
49
1/1
✓ Branch 0 (18→19) taken 18 times.
18 fs.resize(nbFile);
50 18 bool b(true);
51 18 size_t i(0lu);
52
2/2
✓ Branch 0 (49→20) taken 90 times.
✓ Branch 1 (49→50) taken 18 times.
216 for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
53
8/8
✓ Branch 0 (20→21) taken 90 times.
✓ Branch 2 (21→22) taken 90 times.
✓ Branch 4 (22→23) taken 90 times.
✓ Branch 6 (23→24) taken 90 times.
✓ Branch 8 (24→25) taken 90 times.
✓ Branch 10 (25→26) taken 90 times.
✓ Branch 12 (26→27) taken 90 times.
✓ Branch 14 (27→28) taken 90 times.
90 PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
54
1/1
✓ Branch 0 (37→38) 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 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 18 times.
20 if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
68
3/3
✓ Branch 0 (4→5) taken 18 times.
✓ Branch 2 (5→6) taken 18 times.
✓ Branch 4 (6→7) taken 18 times.
18 PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
69
7/7
✓ Branch 0 (8→9) taken 18 times.
✓ Branch 2 (9→10) taken 9 times.
✓ Branch 3 (9→18) taken 9 times.
✓ Branch 4 (10→11) taken 9 times.
✓ Branch 6 (11→12) taken 9 times.
✓ Branch 8 (12→13) taken 9 times.
✓ Branch 10 (13→14) taken 9 times.
18 if(extention != ""){extention = PPath("." + extention);}
70
1/1
✓ Branch 0 (18→19) taken 18 times.
18 fs.resize(nbFile);
71 18 bool b(true);
72 18 size_t i(0lu);
73
2/2
✓ Branch 0 (49→20) taken 90 times.
✓ Branch 1 (49→50) taken 18 times.
216 for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
74
8/8
✓ Branch 0 (20→21) taken 90 times.
✓ Branch 2 (21→22) taken 90 times.
✓ Branch 4 (22→23) taken 90 times.
✓ Branch 6 (23→24) taken 90 times.
✓ Branch 8 (24→25) taken 90 times.
✓ Branch 10 (25→26) taken 90 times.
✓ Branch 12 (26→27) taken 90 times.
✓ Branch 14 (27→28) taken 90 times.
90 PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
75
1/1
✓ Branch 0 (37→38) 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 0 (16→3) taken 90 times.
✓ Branch 1 (16→17) taken 20 times.
220 for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
86
1/1
✓ Branch 0 (5→6) 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 0 (16→3) taken 90 times.
✓ Branch 1 (16→17) taken 20 times.
220 for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
95
1/1
✓ Branch 0 (5→6) taken 90 times.
90 it->close();
96 }
97 20 }
98
99