| Directory: | ./ |
|---|---|
| File: | tmp_project/DataStream/src/data_stream_write_message.h |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 26 | 26 | 100.0% |
| Branches: | 19 | 25 | 76.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<char*, 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 | 32 | static bool data_stream(char* & ds, std::vector<T> & data){ | |
| 22 | //Save the size of the data | ||
| 23 | 32 | size_t nbElement(data.size()); | |
| 24 |
1/1✓ Branch 1 taken 16 times.
|
32 | bool b = DataStream<char*, DataStreamMode::WRITE, 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 |
2/2✓ Branch 3 taken 160 times.
✓ Branch 4 taken 16 times.
|
352 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 27 |
1/1✓ Branch 2 taken 160 times.
|
320 | b &= DataStream<char*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 28 | } | ||
| 29 | 32 | return b; | |
| 30 | } | ||
| 31 | }; | ||
| 32 | |||
| 33 | ///@brief How to write a class in a stream | ||
| 34 | template<typename T> | ||
| 35 | struct DataStream<char*, 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 | 16 | static bool data_stream(char* & ds, std::list<T> & data){ | |
| 42 | //Save the size of the data | ||
| 43 | 16 | size_t nbElement(data.size()); | |
| 44 |
1/1✓ Branch 1 taken 8 times.
|
16 | bool b = DataStream<char*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 45 |
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 |
| 46 |
2/2✓ Branch 3 taken 80 times.
✓ Branch 4 taken 8 times.
|
176 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 47 |
1/1✓ Branch 2 taken 80 times.
|
160 | b &= DataStream<char*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 48 | } | ||
| 49 | 16 | return b; | |
| 50 | } | ||
| 51 | }; | ||
| 52 | |||
| 53 | ///@brief How to write a class in a stream | ||
| 54 | template<typename T, typename U> | ||
| 55 | struct DataStream<char*, 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 | 16 | static bool data_stream(char* & ds, std::map<T, U> & data){ | |
| 62 | //Save the size of the data | ||
| 63 | 16 | size_t nbElement(data.size()); | |
| 64 |
1/1✓ Branch 1 taken 8 times.
|
16 | bool b = DataStream<char*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 65 |
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 |
| 66 |
2/2✓ Branch 3 taken 80 times.
✓ Branch 4 taken 8 times.
|
176 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ |
| 67 |
1/1✓ Branch 2 taken 80 times.
|
160 | b &= DataStream<char*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); |
| 68 |
1/1✓ Branch 2 taken 80 times.
|
160 | b &= DataStream<char*, DataStreamMode::WRITE, U>::data_stream(ds, it->second); |
| 69 | } | ||
| 70 | 16 | return b; | |
| 71 | } | ||
| 72 | }; | ||
| 73 | |||
| 74 | ///@brief How to write a class in a stream | ||
| 75 | template<typename T, typename U> | ||
| 76 | struct DataStream<char*, 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 | 80 | static bool data_stream(char* & ds, std::pair<T, U> & data){ | |
| 83 | 80 | bool b = DataStream<char*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
| 84 | 80 | b &= DataStream<char*, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
| 85 | 80 | return b; | |
| 86 | } | ||
| 87 | }; | ||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | #endif | ||
| 92 | |||
| 93 | |||
| 94 |