Directory: | ./ |
---|---|
File: | tmp_project/PhoenixDataStream/src/data_stream_write_file.h |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 26 | 100.0% |
Branches: | 12 | 18 | 66.7% |
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_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 class in a file | ||
14 | template<typename T> | ||
15 | struct DataStream<FILE*, DataStreamMode::WRITE, std::vector<T> >{ | ||
16 | ///Get the size of a class std::vector T | ||
17 | /** @param[out] ds : file to write the class std::vector T | ||
18 | * @param data : data to be saved | ||
19 | * @return true on success, false otherwise | ||
20 | */ | ||
21 | 297 | static bool data_stream(FILE* & ds, std::vector<T> & data){ | |
22 | //Save the size of the data | ||
23 | 297 | size_t nbElement(data.size()); | |
24 |
1/2✓ Branch 1 taken 153 times.
✗ Branch 2 not taken.
|
297 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
25 |
2/4✓ Branch 0 taken 153 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 153 times.
|
297 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
26 | |||
27 | // if(data_stream_isSimpleType<T>()){ | ||
28 | // b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream_tab(ds, (T*)data.data(), nbElement); | ||
29 | // }else{ | ||
30 |
2/2✓ Branch 3 taken 1471 times.
✓ Branch 4 taken 153 times.
|
3208 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
31 |
1/2✓ Branch 2 taken 1471 times.
✗ Branch 3 not taken.
|
2911 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
32 | } | ||
33 | // } | ||
34 | 297 | return b; | |
35 | } | ||
36 | }; | ||
37 | |||
38 | ///@brief How to write a class in a file | ||
39 | template<typename T> | ||
40 | struct DataStream<FILE*, DataStreamMode::WRITE, std::list<T> >{ | ||
41 | ///Get the size of a class std::list T | ||
42 | /** @param[out] ds : file to write the class std::list T | ||
43 | * @param data : data to be saved | ||
44 | * @return true on success, false otherwise | ||
45 | */ | ||
46 | 300 | static bool data_stream(FILE* & ds, std::list<T> & data){ | |
47 | //Save the size of the data | ||
48 | 300 | size_t nbElement(data.size()); | |
49 |
1/1✓ Branch 1 taken 144 times.
|
300 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
50 |
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 |
51 |
2/2✓ Branch 3 taken 1440 times.
✓ Branch 4 taken 144 times.
|
3300 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
52 |
1/1✓ Branch 2 taken 1440 times.
|
3000 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
53 | } | ||
54 | 300 | return b; | |
55 | } | ||
56 | }; | ||
57 | |||
58 | ///@brief How to write a class in a file | ||
59 | template<typename T, typename U> | ||
60 | struct DataStream<FILE*, DataStreamMode::WRITE, std::map<T, U> >{ | ||
61 | ///Get the size of a class std::list T | ||
62 | /** @param[out] ds : file to write the class std::map T U | ||
63 | * @param data : data to be saved | ||
64 | * @return true on success, false otherwise | ||
65 | */ | ||
66 | 144 | static bool data_stream(FILE* & ds, std::map<T, U> & data){ | |
67 | //Save the size of the data | ||
68 | 144 | size_t nbElement(data.size()); | |
69 | 144 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); | |
70 | 144 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now | |
71 | 1488 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ | |
72 | 1344 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); | |
73 | 1344 | b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, it->second); | |
74 | } | ||
75 | 144 | return b; | |
76 | } | ||
77 | }; | ||
78 | |||
79 | ///@brief How to write a class in a file | ||
80 | template<typename T, typename U> | ||
81 | struct DataStream<FILE*, DataStreamMode::WRITE, std::pair<T, U> >{ | ||
82 | ///Get the size of a class std::list T | ||
83 | /** @param[out] ds : file to write the class std::pair T | ||
84 | * @param data : data to be saved | ||
85 | * @return true on success, false otherwise | ||
86 | */ | ||
87 | 2880 | static bool data_stream(FILE* & ds, std::pair<T, U> & data){ | |
88 | 2880 | bool b = DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
89 | 2880 | b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
90 | 2880 | return b; | |
91 | } | ||
92 | }; | ||
93 | |||
94 | |||
95 | |||
96 | #endif | ||
97 | |||
98 | |||
99 |