Directory: | ./ |
---|---|
File: | tmp_project/PhoenixDataStream/src/data_stream_read_file.h |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 32 | 32 | 100.0% |
Branches: | 17 | 26 | 65.4% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __DATA_STREAM_READ_FILE_H__ | ||
8 | #define __DATA_STREAM_READ_FILE_H__ | ||
9 | |||
10 | #include "data_stream_include.h" | ||
11 | |||
12 | ///@brief How to write a class in a file | ||
13 | template<typename T> | ||
14 | struct DataStream<FILE*,DataStreamMode::READ, std::vector<T> >{ | ||
15 | ///Get the size of a class std::vector T | ||
16 | /** @param[out] ds : file to write the class std::vector T | ||
17 | * @param data : data to be saved | ||
18 | * @return true on success, false otherwise | ||
19 | */ | ||
20 | 301 | static bool data_stream(FILE* & ds, std::vector<T> & data){ | |
21 | //Get the number of elements | ||
22 | 301 | size_t nbElement(0lu); | |
23 |
1/2✓ Branch 1 taken 157 times.
✗ Branch 2 not taken.
|
301 | bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
24 |
2/4✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 157 times.
|
301 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
25 |
4/5✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 183 times.
✓ Branch 2 taken 1453 times.
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
|
3220 | for(size_t i(0lu); i < nbElement && b; ++i){ |
26 | 2919 | T tmp; | |
27 |
1/2✓ Branch 1 taken 1479 times.
✗ Branch 2 not taken.
|
2919 | b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
28 |
1/2✓ Branch 1 taken 1479 times.
✗ Branch 2 not taken.
|
2919 | data.push_back(tmp); |
29 | } | ||
30 | 301 | return b; | |
31 | } | ||
32 | }; | ||
33 | |||
34 | ///@brief How to write a class in a file | ||
35 | template<typename T> | ||
36 | struct DataStream<FILE*,DataStreamMode::READ, std::list<T> >{ | ||
37 | ///Get the size of a class std::list T | ||
38 | /** @param[out] ds : file to write the class std::list T | ||
39 | * @param data : data to be saved | ||
40 | * @return true on success, false otherwise | ||
41 | */ | ||
42 | 300 | static bool data_stream(FILE* & ds, std::list<T> & data){ | |
43 | //Get the number of elements | ||
44 | 300 | size_t nbElement(0lu); | |
45 |
1/1✓ Branch 1 taken 144 times.
|
300 | bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
46 |
2/4✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
|
300 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
47 |
3/4✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 1440 times.
✗ Branch 3 not taken.
|
3300 | for(size_t i(0lu); i < nbElement && b; ++i){ |
48 | 2880 | T tmp; | |
49 |
1/1✓ Branch 1 taken 1440 times.
|
3000 | b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
50 |
1/1✓ Branch 1 taken 1440 times.
|
3000 | data.push_back(tmp); |
51 | } | ||
52 | 300 | return b; | |
53 | } | ||
54 | }; | ||
55 | |||
56 | ///@brief How to write a class in a file | ||
57 | template<typename T, typename U> | ||
58 | struct DataStream<FILE*,DataStreamMode::READ, std::map<T, U> >{ | ||
59 | ///Get the size of a class std::list T | ||
60 | /** @param[out] ds : file to write the class std::map T U | ||
61 | * @param data : data to be saved | ||
62 | * @return true on success, false otherwise | ||
63 | */ | ||
64 | 144 | static bool data_stream(FILE* & ds, std::map<T, U> & data){ | |
65 | //Get the number of elements | ||
66 | 144 | size_t nbElement(0lu); | |
67 | 144 | bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); | |
68 | 144 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now | |
69 | 1488 | for(size_t i(0lu); i < nbElement && b; ++i){ | |
70 | T tmpFirst; | ||
71 | 1344 | b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst); | |
72 | U tmpSecond; | ||
73 | 1344 | b &= DataStream<FILE*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond); | |
74 | 1344 | data[tmpFirst] = tmpSecond; //Add data in map | |
75 | } | ||
76 | 144 | return b; | |
77 | } | ||
78 | }; | ||
79 | |||
80 | ///@brief How to write a class in a file | ||
81 | template<typename T, typename U> | ||
82 | struct DataStream<FILE*,DataStreamMode::READ, std::pair<T, U> >{ | ||
83 | ///Get the size of a class std::list T | ||
84 | /** @param[out] ds : file to write the class std::pair T | ||
85 | * @param data : data to be saved | ||
86 | * @return true on success, false otherwise | ||
87 | */ | ||
88 | 2880 | static bool data_stream(FILE* & ds, std::pair<T, U> & data){ | |
89 | T tmpFirst; | ||
90 | 2880 | bool b = DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst); | |
91 | U tmpSecond; | ||
92 | 2880 | b &= DataStream<FILE*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond); | |
93 | 2880 | data = std::pair<T, U>(tmpFirst, tmpSecond); | |
94 | 2880 | return b; | |
95 | } | ||
96 | }; | ||
97 | |||
98 | |||
99 | |||
100 | #endif | ||
101 | |||
102 | |||
103 |