GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/DataStream/src/data_stream_read_message.h Lines: 31 31 100.0 %
Date: 2024-12-09 15:30:52 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_MESSAGE_H__
8
#define __DATA_STREAM_READ_MESSAGE_H__
9
10
#include "data_stream_include.h"
11
12
13
///@brief How to write a class in a stream
14
template<typename T>
15
struct DataStream<char*,DataStreamMode::READ, std::vector<T> >{
16
	///Get the size of a class std::vector T
17
	/**	@param[out] ds : stream to write the class std::vector T
18
	 * 	@param data : data to be saved
19
	 * 	@return true on success, false otherwise
20
	*/
21
32
	static bool data_stream(char* & ds, std::vector<T> & data){
22
		//Get the number of elements
23
32
		size_t nbElement(0lu);
24
32
		bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement);
25

32
		if(nbElement == 0lu || !b){return b;}		//If there is no element, quit now
26

352
		for(size_t i(0lu); i < nbElement && b; ++i){
27
160
			T tmp;
28
320
			b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmp);
29
320
			data.push_back(tmp);
30
		}
31
32
		return b;
32
	}
33
};
34
35
///@brief How to write a class in a stream
36
template<typename T>
37
struct DataStream<char*,DataStreamMode::READ, std::list<T> >{
38
	///Get the size of a class std::list T
39
	/**	@param[out] ds : stream to write the class std::list T
40
	 * 	@param data : data to be saved
41
	 * 	@return true on success, false otherwise
42
	*/
43
16
	static bool data_stream(char* & ds, std::list<T> & data){
44
		//Get the number of elements
45
16
		size_t nbElement(0lu);
46
16
		bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement);
47

16
		if(nbElement == 0lu || !b){return b;}		//If there is no element, quit now
48

176
		for(size_t i(0lu); i < nbElement && b; ++i){
49
			T tmp;
50
160
			b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmp);
51
160
			data.push_back(tmp);
52
		}
53
16
		return b;
54
	}
55
};
56
57
///@brief How to write a class in a stream
58
template<typename T, typename U>
59
struct DataStream<char*,DataStreamMode::READ, std::map<T, U> >{
60
	///Get the size of a class std::list T
61
	/**	@param[out] ds : stream to write the class std::map T U
62
	 * 	@param data : data to be saved
63
	 * 	@return true on success, false otherwise
64
	*/
65
16
	static bool data_stream(char* & ds, std::map<T, U> & data){
66
		//Get the number of elements
67
16
		size_t nbElement(0lu);
68
16
		bool b = DataStream<char*,DataStreamMode::READ, size_t>::data_stream(ds, nbElement);
69

16
		if(nbElement == 0lu || !b){return b;}		//If there is no element, quit now
70

176
		for(size_t i(0lu); i < nbElement && b; ++i){
71
			T tmpFirst;
72
160
			b &= DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst);
73
			U tmpSecond;
74
160
			b &= DataStream<char*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond);
75
160
			data[tmpFirst] = tmpSecond;	//Add data in map
76
		}
77
16
		return b;
78
	}
79
};
80
81
///@brief How to write a class in a stream
82
template<typename T, typename U>
83
struct DataStream<char*,DataStreamMode::READ, std::pair<T, U> >{
84
	///Get the size of a class std::list T
85
	/**	@param[out] ds : stream to write the class std::pair T
86
	 * 	@param data : data to be saved
87
	 * 	@return true on success, false otherwise
88
	*/
89
80
	static bool data_stream(char* & ds, std::pair<T, U> & data){
90
		T tmpFirst;
91
80
		bool b = DataStream<char*,DataStreamMode::READ, T>::data_stream(ds, tmpFirst);
92
		U tmpSecond;
93
80
		b &= DataStream<char*,DataStreamMode::READ, U>::data_stream(ds, tmpSecond);
94
80
		data = std::pair<T, U>(tmpFirst, tmpSecond);
95
80
		return b;
96
	}
97
};
98
99
100
101
#endif
102
103