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