Directory: | ./ |
---|---|
File: | tmp_project/PhoenixDataStream/src/data_stream_size.h |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 20 | 20 | 100.0% |
Branches: | 6 | 6 | 100.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_SIZE_H__ | ||
8 | #define __DATA_STREAM_SIZE_H__ | ||
9 | |||
10 | #include "data_stream_include.h" | ||
11 | |||
12 | ///@brief How to get size of a class | ||
13 | template<typename T> | ||
14 | struct DataStream<size_t, DataStreamMode::WRITE, std::vector<T> >{ | ||
15 | ///Get the size of a class std::vector T | ||
16 | /** @param[out] ds : size of the class std::vector T | ||
17 | * @param data : data to be used | ||
18 | * @return true on success, false otherwise | ||
19 | */ | ||
20 | 91 | static bool data_stream(size_t & ds, std::vector<T> & data){ | |
21 | 91 | ds += sizeof(size_t); | |
22 |
2/2✓ Branch 4 taken 230 times.
✓ Branch 5 taken 23 times.
|
791 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
23 |
1/1✓ Branch 2 taken 230 times.
|
700 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
24 | } | ||
25 | 91 | return true; | |
26 | } | ||
27 | }; | ||
28 | |||
29 | ///@brief How to get size of a class | ||
30 | template<typename T> | ||
31 | struct DataStream<size_t, DataStreamMode::WRITE, std::list<T> >{ | ||
32 | ///Get the size of a class std::list T | ||
33 | /** @param[out] ds : size of the class std::list T | ||
34 | * @param data : data to be used | ||
35 | * @return true on success, false otherwise | ||
36 | */ | ||
37 | 69 | static bool data_stream(size_t & ds, std::list<T> & data){ | |
38 | 69 | ds += sizeof(size_t); | |
39 |
2/2✓ Branch 4 taken 230 times.
✓ Branch 5 taken 23 times.
|
759 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
40 |
1/1✓ Branch 2 taken 230 times.
|
690 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
41 | } | ||
42 | 69 | return true; | |
43 | } | ||
44 | }; | ||
45 | |||
46 | ///@brief How to get size of a class | ||
47 | template<typename T, typename U> | ||
48 | struct DataStream<size_t, DataStreamMode::WRITE, std::map<T, U> >{ | ||
49 | ///Get the size of a class std::list T | ||
50 | /** @param[out] ds : size of the class std::map T U | ||
51 | * @param data : data to be used | ||
52 | * @return true on success, false otherwise | ||
53 | */ | ||
54 | 23 | static bool data_stream(size_t & ds, std::map<T, U> & data){ | |
55 | 23 | ds += sizeof(size_t); | |
56 | 253 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ | |
57 | 230 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); | |
58 | 230 | DataStream<size_t, DataStreamMode::WRITE, U>::data_stream(ds, it->second); | |
59 | } | ||
60 | 23 | return true; | |
61 | } | ||
62 | }; | ||
63 | |||
64 | ///@brief How to get size of a class | ||
65 | template<typename T, typename U> | ||
66 | struct DataStream<size_t, DataStreamMode::WRITE, std::pair<T, U> >{ | ||
67 | ///Get the size of a class std::list T | ||
68 | /** @param[out] ds : size of the class std::map T U | ||
69 | * @param data : data to be used | ||
70 | * @return true on success, false otherwise | ||
71 | */ | ||
72 | 460 | static bool data_stream(size_t & ds, std::pair<T, U> & data){ | |
73 | 460 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
74 | 460 | DataStream<size_t, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
75 | 460 | return true; | |
76 | } | ||
77 | }; | ||
78 | |||
79 | ///@brief Specialisation to get the size of a bool | ||
80 | template<> | ||
81 | struct DataStream<size_t, DataStreamMode::WRITE, bool>{ | ||
82 | static bool data_stream(size_t & ds, bool & data); | ||
83 | static bool data_stream(size_t & ds, bool * data, size_t nbElement); | ||
84 | }; | ||
85 | |||
86 | ///@brief Specialisation to get the size of a std::string | ||
87 | template<> | ||
88 | struct DataStream<size_t, DataStreamMode::WRITE, std::string>{ | ||
89 | static bool data_stream(size_t & ds, std::string & data); | ||
90 | }; | ||
91 | |||
92 | #endif | ||
93 | |||
94 |