GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixDataStream/src/data_stream_file.cpp
Date: 2025-03-14 11:54:19
Exec Total Coverage
Lines: 19 19 100.0%
Branches: 9 13 69.2%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8 #include "data_stream_file.h"
9
10 ///Read the data bool in the file
11 /** @param[out] ds : file to be read
12 * @param[out] data : data to be set
13 * @return true on success, false otherwise
14 */
15 627 bool DataStream<FILE*, DataStreamMode::READ, bool>::data_stream(FILE* & ds, bool & data){
16 627 return fread((void*)&data, sizeof(bool), 1lu, ds) == 1lu;
17 }
18
19 ///Read the data bool in the file
20 /** @param[out] ds : file to be read
21 * @param[out] data : table of data to be set
22 * @param nbElement : number of element of this data
23 * @return true on success, false otherwise
24 */
25 98 bool DataStream<FILE*, DataStreamMode::READ, bool>::data_stream(FILE* & ds, bool * data, size_t nbElement){
26 98 return fread((void*)data, sizeof(bool), nbElement, ds) == nbElement;
27 }
28
29 ///Save the data bool in the file
30 /** @param[out] ds : file to be written
31 * @param data : data to be saved in the file
32 * @return true on success, false otherwise
33 */
34 627 bool DataStream<FILE*, DataStreamMode::WRITE, bool>::data_stream(FILE* & ds, bool & data){
35 627 return fwrite((const void*)&data, sizeof(bool), 1lu, ds) == 1lu;
36 }
37
38 ///Save the data bool in the file
39 /** @param[out] ds : file to be written
40 * @param data : data to be saved in the file
41 * @param nbElement : number of element of this data
42 * @return true on success, false otherwise
43 */
44 98 bool DataStream<FILE*, DataStreamMode::WRITE, bool>::data_stream(FILE* & ds, bool * data, size_t nbElement){
45 98 return fwrite((const void*)data, sizeof(bool), nbElement, ds) == nbElement;
46 }
47
48 ///Load a std::string from a file
49 /** @param[out] ds : file iterator which contains std::string
50 * @param data : std::string to be loaded
51 * @return true on success, false otherwise
52 */
53 2 bool DataStream<FILE*, DataStreamMode::READ, std::string>::data_stream(FILE* & ds, std::string & data){
54 2 size_t nbElement(0lu);
55
1/1
✓ Branch 1 taken 2 times.
2 bool b = DataStream<FILE*, DataStreamMode::READ, size_t>::data_stream(ds, nbElement);
56
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if(nbElement == 0lu || !b){return b;}
57
1/1
✓ Branch 1 taken 2 times.
2 data.resize(nbElement);
58
1/1
✓ Branch 2 taken 2 times.
2 return fread((void*)data.data(), sizeof(char), nbElement, ds) == nbElement;
59 }
60
61
62 ///Save a std::string into a file
63 /** @param[out] ds : file iterator to be written
64 * @param data : std::string to be saved
65 * @return true on success, false otherwise
66 */
67 2 bool DataStream<FILE*, DataStreamMode::WRITE, std::string>::data_stream(FILE* & ds, std::string & data){
68 2 size_t nbElement(data.size());
69
1/1
✓ Branch 1 taken 2 times.
2 bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
70
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if(nbElement == 0lu || !b){return b;}
71
1/1
✓ Branch 2 taken 2 times.
2 return fwrite(data.data(), sizeof(char), nbElement, ds) == nbElement;
72 }
73
74
75