GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/src/data_stream_write_file.h Lines: 26 26 100.0 %
Date: 2024-12-09 15:30:52 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
253
	static bool data_stream(FILE* & ds, std::vector<T> & data){
22
		//Save the size of the data
23
253
		size_t nbElement(data.size());
24
253
		bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
25

253
		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
2686
			for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){
31
2433
				b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, *it);
32
			}
33
// 		}
34
253
		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
264
		bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
50

264
		if(nbElement == 0lu || !b){return b;}		//If there is no element, quit now
51
2904
		for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){
52
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
242
		bool b = DataStream<FILE*, DataStreamMode::WRITE, size_t>::data_stream(ds, nbElement);
70

242
		if(nbElement == 0lu || !b){return b;}		//If there is no element, quit now
71
2486
		for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){
72
2244
			b &= DataStream<FILE*, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first);
73
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