Directory: | ./ |
---|---|
File: | tmp_project/DataStream/src/data_stream_read_message.h |
Date: | 2024-12-09 11:00:39 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 31 | 31 | 100.0% |
Branches: | 25 | 34 | 73.5% |
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_MESSAGE_H__ | ||
8 | #define __DATA_STREAM_READ_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<char*,DataStreamMode::READ, 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 | 32 | static bool data_stream(char* & ds, std::vector<T> & data){ | |
22 | //Get the number of elements | ||
23 | 32 | size_t nbElement(0lu); | |
24 |
1/1✓ Branch 1 taken 16 times.
|
32 | bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
25 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
32 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
26 |
3/4✓ Branch 0 taken 160 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
|
352 | for(size_t i(0lu); i < nbElement && b; ++i){ |
27 | 160 | T tmp; | |
28 |
1/1✓ Branch 1 taken 160 times.
|
320 | b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
29 |
1/1✓ Branch 1 taken 160 times.
|
320 | data.push_back(tmp); |
30 | } | ||
31 | 32 | return b; | |
32 | } | ||
33 | }; | ||
34 | |||
35 | ///@brief How to write a class in a stream | ||
36 | template<typename T> | ||
37 | struct DataStream<char*,DataStreamMode::READ, std::list<T> >{ | ||
38 | ///Get the size of a class std::list T | ||
39 | /** @param[out] ds : stream to write the class std::list T | ||
40 | * @param data : data to be saved | ||
41 | * @return true on success, false otherwise | ||
42 | */ | ||
43 | 16 | static bool data_stream(char* & ds, std::list<T> & data){ | |
44 | //Get the number of elements | ||
45 | 16 | size_t nbElement(0lu); | |
46 |
1/1✓ Branch 1 taken 8 times.
|
16 | bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
47 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
16 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
48 |
3/4✓ Branch 0 taken 80 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
|
176 | for(size_t i(0lu); i < nbElement && b; ++i){ |
49 | T tmp; | ||
50 |
1/1✓ Branch 1 taken 80 times.
|
160 | b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
51 |
1/1✓ Branch 1 taken 80 times.
|
160 | data.push_back(tmp); |
52 | } | ||
53 | 16 | return b; | |
54 | } | ||
55 | }; | ||
56 | |||
57 | ///@brief How to write a class in a stream | ||
58 | template<typename T, typename U> | ||
59 | struct DataStream<char*,DataStreamMode::READ, std::map<T, U> >{ | ||
60 | ///Get the size of a class std::list T | ||
61 | /** @param[out] ds : stream to write the class std::map T U | ||
62 | * @param data : data to be saved | ||
63 | * @return true on success, false otherwise | ||
64 | */ | ||
65 | 16 | static bool data_stream(char* & ds, std::map<T, U> & data){ | |
66 | //Get the number of elements | ||
67 | 16 | size_t nbElement(0lu); | |
68 |
1/1✓ Branch 1 taken 8 times.
|
16 | bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
69 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
16 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
70 |
3/4✓ Branch 0 taken 80 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
|
176 | for(size_t i(0lu); i < nbElement && b; ++i){ |
71 | T tmpFirst; | ||
72 |
1/1✓ Branch 1 taken 80 times.
|
160 | b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst); |
73 | U tmpSecond; | ||
74 |
1/1✓ Branch 1 taken 80 times.
|
160 | b &= DataStream<char*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond); |
75 |
1/1✓ Branch 1 taken 80 times.
|
160 | data[tmpFirst] = tmpSecond; //Add data in map |
76 | } | ||
77 | 16 | return b; | |
78 | } | ||
79 | }; | ||
80 | |||
81 | ///@brief How to write a class in a stream | ||
82 | template<typename T, typename U> | ||
83 | struct DataStream<char*,DataStreamMode::READ, std::pair<T, U> >{ | ||
84 | ///Get the size of a class std::list T | ||
85 | /** @param[out] ds : stream to write the class std::pair T | ||
86 | * @param data : data to be saved | ||
87 | * @return true on success, false otherwise | ||
88 | */ | ||
89 | 80 | static bool data_stream(char* & ds, std::pair<T, U> & data){ | |
90 | T tmpFirst; | ||
91 | 80 | bool b = DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst); | |
92 | U tmpSecond; | ||
93 | 80 | b &= DataStream<char*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond); | |
94 | 80 | data = std::pair<T, U>(tmpFirst, tmpSecond); | |
95 | 80 | return b; | |
96 | } | ||
97 | }; | ||
98 | |||
99 | |||
100 | |||
101 | #endif | ||
102 | |||
103 | |||
104 |