| Directory: | ./ |
|---|---|
| File: | tmp_project/DataStream/src/data_stream_size.h |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 20 | 20 | 100.0% |
| Branches: | 10 | 10 | 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 | 64 | static bool data_stream(size_t & ds, std::vector<T> & data){ | |
| 21 | 64 | ds += sizeof(size_t); | |
| 22 |
2/2✓ Branch 4 taken 320 times.
✓ Branch 5 taken 32 times.
|
704 | for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 23 |
1/1✓ Branch 2 taken 320 times.
|
640 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 24 | } | ||
| 25 | 64 | 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 | 64 | static bool data_stream(size_t & ds, std::list<T> & data){ | |
| 38 | 64 | ds += sizeof(size_t); | |
| 39 |
2/2✓ Branch 4 taken 320 times.
✓ Branch 5 taken 32 times.
|
704 | for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it){ |
| 40 |
1/1✓ Branch 2 taken 320 times.
|
640 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, *it); |
| 41 | } | ||
| 42 | 64 | 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 | 24 | static bool data_stream(size_t & ds, std::map<T, U> & data){ | |
| 55 | 24 | ds += sizeof(size_t); | |
| 56 |
2/2✓ Branch 4 taken 120 times.
✓ Branch 5 taken 12 times.
|
264 | for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it){ |
| 57 |
1/1✓ Branch 2 taken 120 times.
|
240 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, (T&)it->first); |
| 58 |
1/1✓ Branch 2 taken 120 times.
|
240 | DataStream<size_t, DataStreamMode::WRITE, U>::data_stream(ds, it->second); |
| 59 | } | ||
| 60 | 24 | 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 | 320 | static bool data_stream(size_t & ds, std::pair<T, U> & data){ | |
| 73 | 320 | DataStream<size_t, DataStreamMode::WRITE, T>::data_stream(ds, (T&)data.first); | |
| 74 | 320 | DataStream<size_t, DataStreamMode::WRITE, U>::data_stream(ds, data.second); | |
| 75 | 320 | 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 char | ||
| 87 | template<> | ||
| 88 | struct DataStream<size_t, DataStreamMode::WRITE, char>{ | ||
| 89 | static bool data_stream(size_t & ds, char & data); | ||
| 90 | static bool data_stream(size_t & ds, char * data, size_t nbElement); | ||
| 91 | }; | ||
| 92 | |||
| 93 | ///@brief Specialisation to get the size of a short | ||
| 94 | template<> | ||
| 95 | struct DataStream<size_t, DataStreamMode::WRITE, short>{ | ||
| 96 | static bool data_stream(size_t & ds, short & data); | ||
| 97 | static bool data_stream(size_t & ds, short * data, size_t nbElement); | ||
| 98 | }; | ||
| 99 | |||
| 100 | ///@brief Specialisation to get the size of a int | ||
| 101 | template<> | ||
| 102 | struct DataStream<size_t, DataStreamMode::WRITE, int>{ | ||
| 103 | static bool data_stream(size_t & ds, int & data); | ||
| 104 | static bool data_stream(size_t & ds, int * data, size_t nbElement); | ||
| 105 | }; | ||
| 106 | |||
| 107 | ///@brief Specialisation to get the size of a long int | ||
| 108 | template<> | ||
| 109 | struct DataStream<size_t, DataStreamMode::WRITE, long int>{ | ||
| 110 | static bool data_stream(size_t & ds, long int & data); | ||
| 111 | static bool data_stream(size_t & ds, long int * data, size_t nbElement); | ||
| 112 | }; | ||
| 113 | |||
| 114 | ///@brief Specialisation to get the size of a unsigned char | ||
| 115 | template<> | ||
| 116 | struct DataStream<size_t, DataStreamMode::WRITE, unsigned char>{ | ||
| 117 | static bool data_stream(size_t & ds, unsigned char & data); | ||
| 118 | static bool data_stream(size_t & ds, unsigned char * data, size_t nbElement); | ||
| 119 | }; | ||
| 120 | |||
| 121 | ///@brief Specialisation to get the size of a unsigned short | ||
| 122 | template<> | ||
| 123 | struct DataStream<size_t, DataStreamMode::WRITE, unsigned short>{ | ||
| 124 | static bool data_stream(size_t & ds, unsigned short & data); | ||
| 125 | static bool data_stream(size_t & ds, unsigned short * data, size_t nbElement); | ||
| 126 | }; | ||
| 127 | |||
| 128 | ///@brief Specialisation to get the size of a unsigned int | ||
| 129 | template<> | ||
| 130 | struct DataStream<size_t, DataStreamMode::WRITE, unsigned int>{ | ||
| 131 | static bool data_stream(size_t & ds, unsigned int & data); | ||
| 132 | static bool data_stream(size_t & ds, unsigned int * data, size_t nbElement); | ||
| 133 | }; | ||
| 134 | |||
| 135 | ///@brief Specialisation to get the size of a long unsigned int | ||
| 136 | template<> | ||
| 137 | struct DataStream<size_t, DataStreamMode::WRITE, long unsigned int>{ | ||
| 138 | static bool data_stream(size_t & ds, long unsigned int & data); | ||
| 139 | static bool data_stream(size_t & ds, long unsigned int * data, size_t nbElement); | ||
| 140 | }; | ||
| 141 | |||
| 142 | ///@brief Specialisation to get the size of a float | ||
| 143 | template<> | ||
| 144 | struct DataStream<size_t, DataStreamMode::WRITE, float>{ | ||
| 145 | static bool data_stream(size_t & ds, float & data); | ||
| 146 | static bool data_stream(size_t & ds, float * data, size_t nbElement); | ||
| 147 | }; | ||
| 148 | |||
| 149 | ///@brief Specialisation to get the size of a double | ||
| 150 | template<> | ||
| 151 | struct DataStream<size_t, DataStreamMode::WRITE, double>{ | ||
| 152 | static bool data_stream(size_t & ds, double & data); | ||
| 153 | static bool data_stream(size_t & ds, double * data, size_t nbElement); | ||
| 154 | }; | ||
| 155 | |||
| 156 | ///@brief Specialisation to get the size of a std::string | ||
| 157 | template<> | ||
| 158 | struct DataStream<size_t, DataStreamMode::WRITE, std::string>{ | ||
| 159 | static bool data_stream(size_t & ds, std::string & data); | ||
| 160 | }; | ||
| 161 | |||
| 162 | #endif | ||
| 163 | |||
| 164 |