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 |
|
247 |
static bool data_stream(FILE* & ds, std::vector<T> & data){ |
21 |
|
|
//Get the number of elements |
22 |
|
247 |
size_t nbElement(0lu); |
23 |
✓ |
247 |
bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
24 |
✓✗✗✓
|
247 |
if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
25 |
✓✓✓✗
|
2690 |
for(size_t i(0lu); i < nbElement && b; ++i){ |
26 |
|
2466 |
T tmp; |
27 |
✓ |
2443 |
b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
28 |
✓ |
2443 |
data.push_back(tmp); |
29 |
|
|
} |
30 |
|
247 |
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 |
✓ |
264 |
bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
46 |
✓✗✗✓
|
264 |
if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
47 |
✓✓✓✗
|
2904 |
for(size_t i(0lu); i < nbElement && b; ++i){ |
48 |
|
2420 |
T tmp; |
49 |
✓ |
2640 |
b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmp); |
50 |
✓ |
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 |
✓ |
242 |
bool b = DataStream<FILE*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement); |
68 |
✓✗✗✓
|
242 |
if(nbElement == 0lu || !b){return b;} //If there is no element, quit now |
69 |
✓✓✓✗
|
2486 |
for(size_t i(0lu); i < nbElement && b; ++i){ |
70 |
|
|
T tmpFirst; |
71 |
✓ |
2244 |
b &= DataStream<FILE*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst); |
72 |
|
|
U tmpSecond; |
73 |
✓ |
2244 |
b &= DataStream<FILE*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond); |
74 |
✓ |
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 |
|
|
|