1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#ifndef __DATA_FILE_H__ |
8 |
|
|
#define __DATA_FILE_H__ |
9 |
|
|
|
10 |
|
|
#include "data_stream.h" |
11 |
|
|
|
12 |
|
|
///Save data in a message |
13 |
|
|
/** @param[out] iter : message to be written |
14 |
|
|
* @param data : data to be saved in the message |
15 |
|
|
* @return true on success, false otherwise |
16 |
|
|
*/ |
17 |
|
|
template<typename T> |
18 |
|
|
bool data_save(FILE* iter, const T & data){ |
19 |
|
|
return DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(iter, (T&)data); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
///Save data in a message |
23 |
|
|
/** @param[out] iter : message to be written |
24 |
|
|
* @param data : data to be saved in the message |
25 |
|
|
* @param nbElement : number of elements in the data |
26 |
|
|
* @return true on success, false otherwise |
27 |
|
|
*/ |
28 |
|
|
template<typename T> |
29 |
|
|
bool data_save(FILE* iter, const T * data, size_t nbElement){ |
30 |
|
|
return DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(iter, (T*)data, nbElement); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
///Load data from a message |
34 |
|
|
/** @param[out] iter : message to be read |
35 |
|
|
* @param[out] data : data to be loaded from the message |
36 |
|
|
* @return true on success, false otherwise |
37 |
|
|
*/ |
38 |
|
|
template<typename T> |
39 |
|
|
bool data_load(FILE* iter, T & data){ |
40 |
|
|
return DataStream<FILE*, DataStreamMode::READ, T>::data_stream(iter, data); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
///Load data from a message |
44 |
|
|
/** @param[out] iter : message to be read |
45 |
|
|
* @param[out] data : data to be loaded from the message |
46 |
|
|
* @param nbElement : number of elements in the data |
47 |
|
|
* @return true on success, false otherwise |
48 |
|
|
*/ |
49 |
|
|
template<typename T> |
50 |
|
|
bool data_load(FILE* iter, T * data, size_t nbElement){ |
51 |
|
|
return DataStream<FILE*, DataStreamMode::READ, T>::data_stream(iter, data, nbElement); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
///Save data in a message |
55 |
|
|
/** @param fileName : name of the file to be written |
56 |
|
|
* @param data : data to be saved in the message |
57 |
|
|
* @return true on success, false otherwise |
58 |
|
|
*/ |
59 |
|
|
template<typename T> |
60 |
|
1070 |
bool data_save(const std::string & fileName, const T & data){ |
61 |
✓ |
1070 |
FILE* iter = fopen(fileName.c_str(), "w"); |
62 |
✓✓ |
1070 |
if(iter == NULL){ |
63 |
|
266 |
return false; |
64 |
|
|
} |
65 |
✓ |
804 |
bool b(DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(iter, (T&)data)); |
66 |
✓ |
804 |
fclose(iter); |
67 |
|
804 |
return b; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
///Save data in a message |
71 |
|
|
/** @param fileName : name of the file to be written |
72 |
|
|
* @param data : data to be saved in the message |
73 |
|
|
* @param nbElement : number of elements in the data |
74 |
|
|
* @return true on success, false otherwise |
75 |
|
|
*/ |
76 |
|
|
template<typename T> |
77 |
|
4312 |
bool data_save(const std::string & fileName, const T * data, size_t nbElement){ |
78 |
✓ |
4312 |
FILE* iter = fopen(fileName.c_str(), "w"); |
79 |
✓✓ |
4312 |
if(iter == NULL){ |
80 |
|
2156 |
return false; |
81 |
|
|
} |
82 |
✓ |
2156 |
bool b(DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(iter, (T*)data, nbElement)); |
83 |
✓ |
2156 |
fclose(iter); |
84 |
|
2156 |
return b; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
///Load data from a message |
88 |
|
|
/** @param fileName : name of the file to be read |
89 |
|
|
* @param[out] data : data to be loaded from the message |
90 |
|
|
* @return true on success, false otherwise |
91 |
|
|
*/ |
92 |
|
|
template<typename T> |
93 |
|
538 |
bool data_load(const std::string & fileName, T & data){ |
94 |
✓ |
538 |
FILE* iter = fopen(fileName.c_str(), "r"); |
95 |
✓✓ |
538 |
if(iter == NULL){ |
96 |
|
136 |
return false; |
97 |
|
|
} |
98 |
✓ |
402 |
bool b(DataStream<FILE*, DataStreamMode::READ, T>::data_stream(iter, data)); |
99 |
✓ |
402 |
fclose(iter); |
100 |
|
402 |
return b; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
///Load data from a message |
104 |
|
|
/** @param fileName : name of the file to be read |
105 |
|
|
* @param[out] data : data to be loaded from the message |
106 |
|
|
* @param nbElement : number of elements in the data |
107 |
|
|
* @return true on success, false otherwise |
108 |
|
|
*/ |
109 |
|
|
template<typename T> |
110 |
|
2156 |
bool data_load(const std::string & fileName, T * data, size_t nbElement){ |
111 |
|
2156 |
FILE* iter = fopen(fileName.c_str(), "r"); |
112 |
|
2156 |
if(iter == NULL){ |
113 |
|
1078 |
return false; |
114 |
|
|
} |
115 |
|
1078 |
bool b(DataStream<FILE*, DataStreamMode::READ, T>::data_stream(iter, data, nbElement)); |
116 |
|
1078 |
fclose(iter); |
117 |
|
1078 |
return b; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
#endif |