| Directory: | ./ |
|---|---|
| File: | tmp_project/DataStream/src/data_stream_write_file.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_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 | 347 | static bool data_stream(FILE* & ds, std::vector<T> & data){ | |
| 22 | //Save the size of the data | ||
| 23 | 347 | size_t nbElement(data.size()); | |
| 24 |
1/1✓ Branch 1 taken 121 times.
|
347 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 25 |
2/4✓ Branch 0 taken 121 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 121 times.
|
347 | 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 1210 times.
✓ Branch 4 taken 121 times.
|
2930 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 31 |
1/1✓ Branch 2 taken 1210 times.
|
2635 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 32 | } | ||
| 33 | // } | ||
| 34 | 295 | 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 | 264 | static bool data_stream(FILE* & ds, std::list<T> & data){ | |
| 47 | //Save the size of the data | ||
| 48 | 264 | size_t nbElement(data.size()); | |
| 49 |
1/1✓ Branch 1 taken 132 times.
|
264 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 50 |
2/4✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 132 times.
|
264 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
| 51 |
2/2✓ Branch 3 taken 1320 times.
✓ Branch 4 taken 132 times.
|
2904 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 52 |
1/1✓ Branch 2 taken 1320 times.
|
2640 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 53 | } | ||
| 54 | 264 | 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 | 242 | static bool data_stream(FILE* & ds, std::map<T, U> & data){ | |
| 67 | //Save the size of the data | ||
| 68 | 242 | size_t nbElement(data.size()); | |
| 69 |
1/1✓ Branch 1 taken 121 times.
|
242 | bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement); |
| 70 |
2/4✓ Branch 0 taken 121 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 121 times.
|
242 | if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
| 71 |
2/2✓ Branch 3 taken 1122 times.
✓ Branch 4 taken 121 times.
|
2486 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ |
| 72 |
1/1✓ Branch 2 taken 1122 times.
|
2244 | b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); |
| 73 |
1/1✓ Branch 2 taken 1122 times.
|
2244 | b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, it->second); |
| 74 | } | ||
| 75 | 242 | 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 | 2420 | static bool data_stream(FILE* & ds, std::pair<T, U> & data){ | |
| 88 | 2420 | bool b = DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
| 89 | 2420 | b &= DataStream<FILE*, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
| 90 | 2420 | return b; | |
| 91 | } | ||
| 92 | }; | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | #endif | ||
| 97 | |||
| 98 | |||
| 99 |