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