Directory: | ./ |
---|---|
File: | src/convertToString_impl.h |
Date: | 2024-11-07 16:05:26 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 11 | 11 | 100.0% |
Branches: | 6 | 9 | 66.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __CONVERTTOSTRING_IMPL_H__ | ||
8 | #define __CONVERTTOSTRING_IMPL_H__ | ||
9 | |||
10 | #include "convertToString.h" | ||
11 | |||
12 | ///Convert a type into a string | ||
13 | /** @param val : value to be converted | ||
14 | * @return converted string | ||
15 | */ | ||
16 | template<typename T> | ||
17 | 58 | std::string convertToString(const T & val){ | |
18 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
58 | std::stringstream str; |
19 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
58 | str << val; |
20 |
1/2✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
|
116 | return str.str(); |
21 | 58 | } | |
22 | |||
23 | ///Convert a string into value | ||
24 | /** @param str : string to be converted | ||
25 | * @return converted value | ||
26 | */ | ||
27 | template<typename T> | ||
28 | 1 | T stringToValue(const std::string & str){ | |
29 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::stringstream strStream; |
30 |
1/1✓ Branch 1 taken 1 times.
|
1 | strStream << str; |
31 | T val; | ||
32 |
1/1✓ Branch 1 taken 1 times.
|
1 | strStream >> val; |
33 | 1 | return val; | |
34 | 1 | } | |
35 | |||
36 | |||
37 | #endif | ||
38 | |||
39 |