| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : LGPL-3.0-only | ||
| 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 | ///@brief How to write a pointer address in a message | ||
| 13 | template<typename T> | ||
| 14 | struct DataStream<DataStreamIter, DataStreamMode::WRITE, T* >{ | ||
| 15 | ///Write a pointer address in a message | ||
| 16 | /** @param[out] ds : message to write the pointer address into | ||
| 17 | * @param data : data to be used | ||
| 18 | * @return true on success, false otherwise | ||
| 19 | */ | ||
| 20 | 1 | static bool data_stream(DataStreamIter & ds, T* & data){ | |
| 21 | 1 | size_t value = (size_t)data; | |
| 22 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | bool b = DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(ds, value); |
| 23 | 1 | return b; | |
| 24 | } | ||
| 25 | }; | ||
| 26 | |||
| 27 | ///@brief How to write a class in a stream | ||
| 28 | template<typename T> | ||
| 29 | struct DataStream<DataStreamIter, DataStreamMode::WRITE, std::vector<T> >{ | ||
| 30 | ///Get the size of a class std::vector T | ||
| 31 | /** @param[out] ds : stream to write the class std::vector T | ||
| 32 | * @param data : data to be saved | ||
| 33 | * @return true on success, false otherwise | ||
| 34 | */ | ||
| 35 | 26 | static bool data_stream(DataStreamIter & ds, std::vector<T> & data){ | |
| 36 | //Save the size of the data | ||
| 37 | 26 | size_t nbElement(data.size()); | |
| 38 |
1/1✓ Branch 0 (3→4) taken 26 times.
|
26 | bool b = DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 39 |
2/4✓ Branch 0 (4→5) taken 26 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 26 times.
|
26 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
| 40 |
2/2✓ Branch 0 (21→8) taken 260 times.
✓ Branch 1 (21→22) taken 26 times.
|
572 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 41 |
1/1✓ Branch 0 (10→11) taken 260 times.
|
260 | b &= DataStream<DataStreamIter, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 42 | } | ||
| 43 | 26 | return b; | |
| 44 | } | ||
| 45 | }; | ||
| 46 | |||
| 47 | ///@brief How to write a class in a stream | ||
| 48 | template<typename T> | ||
| 49 | struct DataStream<DataStreamIter, DataStreamMode::WRITE, std::list<T> >{ | ||
| 50 | ///Get the size of a class std::list T | ||
| 51 | /** @param[out] ds : stream to write the class std::list T | ||
| 52 | * @param data : data to be saved | ||
| 53 | * @return true on success, false otherwise | ||
| 54 | */ | ||
| 55 | 26 | static bool data_stream(DataStreamIter & ds, std::list<T> & data){ | |
| 56 | //Save the size of the data | ||
| 57 | 26 | size_t nbElement(data.size()); | |
| 58 |
1/1✓ Branch 0 (3→4) taken 26 times.
|
26 | bool b = DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 59 |
2/4✓ Branch 0 (4→5) taken 26 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 26 times.
|
26 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
| 60 |
2/2✓ Branch 0 (13→8) taken 260 times.
✓ Branch 1 (13→14) taken 26 times.
|
286 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 61 |
1/1✓ Branch 0 (9→10) taken 260 times.
|
260 | b &= DataStream<DataStreamIter, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 62 | } | ||
| 63 | 26 | return b; | |
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | ///@brief How to write a class in a stream | ||
| 68 | template<typename T, typename U> | ||
| 69 | struct DataStream<DataStreamIter, DataStreamMode::WRITE, std::map<T, U> >{ | ||
| 70 | ///Get the size of a class std::list T | ||
| 71 | /** @param[out] ds : stream to write the class std::map T U | ||
| 72 | * @param data : data to be saved | ||
| 73 | * @return true on success, false otherwise | ||
| 74 | */ | ||
| 75 | 13 | static bool data_stream(DataStreamIter & ds, std::map<T, U> & data){ | |
| 76 | //Save the size of the data | ||
| 77 | 13 | size_t nbElement(data.size()); | |
| 78 |
1/1✓ Branch 0 (3→4) taken 13 times.
|
13 | bool b = DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 79 |
2/4✓ Branch 0 (4→5) taken 13 times.
✗ Branch 1 (4→6) not taken.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 13 times.
|
13 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
| 80 |
2/2✓ Branch 0 (15→8) taken 130 times.
✓ Branch 1 (15→16) taken 13 times.
|
143 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ |
| 81 |
1/1✓ Branch 0 (9→10) taken 130 times.
|
130 | b &= DataStream<DataStreamIter, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); |
| 82 |
1/1✓ Branch 0 (11→12) taken 130 times.
|
130 | b &= DataStream<DataStreamIter, DataStreamMode::WRITE, U>::data_stream(ds, it->second); |
| 83 | } | ||
| 84 | 13 | return b; | |
| 85 | } | ||
| 86 | }; | ||
| 87 | |||
| 88 | ///@brief How to write a class in a stream | ||
| 89 | template<typename T, typename U> | ||
| 90 | struct DataStream<DataStreamIter, DataStreamMode::WRITE, std::pair<T, U> >{ | ||
| 91 | ///Get the size of a class std::list T | ||
| 92 | /** @param[out] ds : stream to write the class std::pair T | ||
| 93 | * @param data : data to be saved | ||
| 94 | * @return true on success, false otherwise | ||
| 95 | */ | ||
| 96 | 260 | static bool data_stream(DataStreamIter & ds, std::pair<T, U> & data){ | |
| 97 | 260 | bool b = DataStream<DataStreamIter, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
| 98 | 260 | b &= DataStream<DataStreamIter, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
| 99 | 260 | return b; | |
| 100 | } | ||
| 101 | }; | ||
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | #endif | ||
| 106 | |||
| 107 | |||
| 108 |