GCC Code Coverage Report


Directory: ./
File: src/data_stream_write_file.h
Date: 2026-10-16 16:49:17
Exec Total Coverage
Lines: 30 30 100.0%
Functions: 589 589 100.0%
Branches: 20 26 76.9%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : LGPL-3.0-only
5 ****************************************/
6
7 #ifndef __DATA_STREAM_WRITE_FILE_H__
8 #define __DATA_STREAM_WRITE_FILE_H__
9
10 #include "data_stream_include.h"
11 #include "data_stream_isSimpleType.h"
12
13 ///@brief How to write a pointer address in a file
14 template<typename T>
15 struct DataStream<FILE*, DataStreamMode::WRITE, T* >{
16 ///Write a pointer address in a file
17 /** @param[out] ds : file to write the pointer address into
18 * @param data : data to be used
19 * @return true on success, false otherwise
20 */
21 1 static bool data_stream(FILE* & ds, T* & data){
22 1 size_t value = (size_t)data;
23
1/1
✓ Branch 0 (2→3) taken 1 times.
1 bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, value);
24 1 return b;
25 }
26 };
27
28 ///@brief How to write a class in a file
29 template<typename T>
30 struct DataStream<FILE*, DataStreamMode::WRITE, std::vector<T> >{
31 ///Get the size of a class std::vector T
32 /** @param[out] ds : file to write the class std::vector T
33 * @param data : data to be saved
34 * @return true on success, false otherwise
35 */
36 144 static bool data_stream(FILE* & ds, std::vector<T> & data){
37 //Save the size of the data
38 144 size_t nbElement(data.size());
39
1/1
✓ Branch 0 (3→4) taken 144 times.
144 bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
40
2/4
✓ Branch 0 (4→5) taken 144 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 144 times.
144 if(nbElement == 0lu || !b){return b;} //If there is no element, quit now
41
42 // if(data_stream_isSimpleType<T>()){
43 // b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream_tab(ds, (T*)data.data(), nbElement);
44 // }else{
45
2/2
✓ Branch 0 (21→8) taken 1440 times.
✓ Branch 1 (21→22) taken 144 times.
3168 for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){
46
1/1
✓ Branch 0 (10→11) taken 1440 times.
1440 b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it);
47 }
48 // }
49 144 return b;
50 }
51 };
52
53 ///@brief How to write a class in a file
54 template<typename T>
55 struct DataStream<FILE*, DataStreamMode::WRITE, std::list<T> >{
56 ///Get the size of a class std::list T
57 /** @param[out] ds : file to write the class std::list T
58 * @param data : data to be saved
59 * @return true on success, false otherwise
60 */
61 156 static bool data_stream(FILE* & ds, std::list<T> & data){
62 //Save the size of the data
63 156 size_t nbElement(data.size());
64
1/1
✓ Branch 0 (3→4) taken 156 times.
156 bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
65
2/4
✓ Branch 0 (4→5) taken 156 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 156 times.
156 if(nbElement == 0lu || !b){return b;} //If there is no element, quit now
66
2/2
✓ Branch 0 (13→8) taken 1560 times.
✓ Branch 1 (13→14) taken 156 times.
1716 for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){
67
1/1
✓ Branch 0 (9→10) taken 1560 times.
1560 b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it);
68 }
69 156 return b;
70 }
71 };
72
73 ///@brief How to write a class in a file
74 template<typename T, typename U>
75 struct DataStream<FILE*, DataStreamMode::WRITE, std::map<T, U> >{
76 ///Get the size of a class std::list T
77 /** @param[out] ds : file to write the class std::map T U
78 * @param data : data to be saved
79 * @return true on success, false otherwise
80 */
81 144 static bool data_stream(FILE* & ds, std::map<T, U> & data){
82 //Save the size of the data
83 144 size_t nbElement(data.size());
84
1/1
✓ Branch 0 (3→4) taken 144 times.
144 bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
85
2/4
✓ Branch 0 (4→5) taken 144 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 144 times.
144 if(nbElement == 0lu || !b){return b;} //If there is no element, quit now
86
2/2
✓ Branch 0 (15→8) taken 1344 times.
✓ Branch 1 (15→16) taken 144 times.
1488 for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){
87
1/1
✓ Branch 0 (9→10) taken 1344 times.
1344 b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first);
88
1/1
✓ Branch 0 (11→12) taken 1344 times.
1344 b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, it->second);
89 }
90 144 return b;
91 }
92 };
93
94 ///@brief How to write a class in a file
95 template<typename T, typename U>
96 struct DataStream<FILE*, DataStreamMode::WRITE, std::pair<T, U> >{
97 ///Get the size of a class std::list T
98 /** @param[out] ds : file to write the class std::pair T
99 * @param data : data to be saved
100 * @return true on success, false otherwise
101 */
102 2880 static bool data_stream(FILE* & ds, std::pair<T, U> & data){
103 2880 bool b = DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first);
104 2880 b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, data.second);
105 2880 return b;
106 }
107 };
108
109
110
111 #endif
112
113
114