GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/*************************************** |
||
2 |
Auteur : Pierre Aubert |
||
3 |
Mail : pierre.aubert@lapp.in2p3.fr |
||
4 |
Licence : CeCILL-C |
||
5 |
****************************************/ |
||
6 |
|||
7 |
#include "OptionType.h" |
||
8 |
|||
9 |
///Say if the option type is a signed integer |
||
10 |
/** @param type : type to be checked |
||
11 |
* @return true if type is a signed integer, false otherwise |
||
12 |
*/ |
||
13 |
12 |
bool isOptionSignedInteger(OptionType::OptionType type){ |
|
14 |
✓✓✓✓ |
12 |
return type >= OptionType::CHAR && type <= OptionType::LONG; |
15 |
} |
||
16 |
|||
17 |
///Say if the option type is an unsigned integer |
||
18 |
/** @param type : type to be checked |
||
19 |
* @return true if type is an unsigned integer, false otherwise |
||
20 |
*/ |
||
21 |
9 |
bool isOptionUnsignedInteger(OptionType::OptionType type){ |
|
22 |
✓✓✓✗ |
9 |
return type >= OptionType::UCHAR && type <= OptionType::ULONG; |
23 |
} |
||
24 |
|||
25 |
///Say if the option type is an integer |
||
26 |
/** @param type : type to be checked |
||
27 |
* @return true if type is an integer, false otherwise |
||
28 |
*/ |
||
29 |
11 |
bool isOptionInteger(OptionType::OptionType type){ |
|
30 |
✓✓✓✓ |
11 |
return isOptionSignedInteger(type) || isOptionUnsignedInteger(type); |
31 |
} |
||
32 |
|||
33 |
///Say if the option type is a floating point |
||
34 |
/** @param type : type to be checked |
||
35 |
* @return true if type is a floating point, false otherwise |
||
36 |
*/ |
||
37 |
4 |
bool isOptionFloatingPoint(OptionType::OptionType type){ |
|
38 |
✓✓✓✗ |
4 |
return type >= OptionType::FLOAT && type <= OptionType::DOUBLE; |
39 |
} |
||
40 |
|||
41 |
///Say if the option is a filename, a drectory, both or a string |
||
42 |
/** @param type : type to be checked |
||
43 |
* @return true if type is a filename, a drectory, both or a string, false otherwise |
||
44 |
*/ |
||
45 |
31 |
bool isOptionStringFileDir(OptionType::OptionType type){ |
|
46 |
✓✓✓✓ ✓✓✓✓ |
31 |
return type == OptionType::STRING || type == OptionType::FILE_OR_DIR || type == OptionType::FILENAME || type == OptionType::DIRECTORY; |
47 |
} |
||
48 |
|||
49 |
///Say if two types are compatible |
||
50 |
/** @param typeFromParam : type from parameters user |
||
51 |
* @param typeFromType : type automatically determined with default value type |
||
52 |
* @return true if the two types are compatible, false otherwise |
||
53 |
*/ |
||
54 |
66 |
bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType){ |
|
55 |
✓✓ | 66 |
if(typeFromParam == typeFromType){return true;} |
56 |
//If we are waiting for a boolean, but we do not get one, => fail |
||
57 |
✗✓ | 18 |
if(typeFromParam == OptionType::BOOL){return false;} |
58 |
✓✓✓✗ ✓✓ |
18 |
if(isOptionStringFileDir(typeFromParam) && isOptionStringFileDir(typeFromType)){return true;} |
59 |
|||
60 |
✓✓✓✓ ✓✓ |
9 |
if(isOptionInteger(typeFromParam) && isOptionFloatingPoint(typeFromType)){return false;} |
61 |
|||
62 |
8 |
return true; |
|
63 |
} |
||
64 |
|||
65 |
///Convert the OptionType into string |
||
66 |
/** @param type : OptionType to be converted |
||
67 |
* @return string |
||
68 |
*/ |
||
69 |
85 |
std::string convertOptionTypeToString(OptionType::OptionType type){ |
|
70 |
✓✓✓✓ ✓✓✓✓ ✓✓✓✓ ✓✓✓✓ ✓ |
85 |
switch(type){ |
71 |
1 |
case OptionType::NONE: |
|
72 |
✓ | 1 |
return "NONE"; |
73 |
28 |
case OptionType::STRING: |
|
74 |
✓ | 28 |
return "STRING"; |
75 |
13 |
case OptionType::FILENAME: |
|
76 |
✓ | 13 |
return "FILENAME"; |
77 |
5 |
case OptionType::DIRECTORY: |
|
78 |
✓ | 5 |
return "DIRECTORY"; |
79 |
1 |
case OptionType::FILE_OR_DIR: |
|
80 |
✓ | 1 |
return "FILE_OR_DIR"; |
81 |
1 |
case OptionType::BOOL: |
|
82 |
✓ | 1 |
return "BOOL"; |
83 |
1 |
case OptionType::CHAR: |
|
84 |
✓ | 1 |
return "CHAR"; |
85 |
1 |
case OptionType::SHORT: |
|
86 |
✓ | 1 |
return "SHORT"; |
87 |
26 |
case OptionType::INT: |
|
88 |
✓ | 26 |
return "INT"; |
89 |
1 |
case OptionType::LONG: |
|
90 |
✓ | 1 |
return "LONG"; |
91 |
1 |
case OptionType::UCHAR: |
|
92 |
✓ | 1 |
return "UCHAR"; |
93 |
1 |
case OptionType::USHORT: |
|
94 |
✓ | 1 |
return "USHORT"; |
95 |
1 |
case OptionType::UINT: |
|
96 |
✓ | 1 |
return "UINT"; |
97 |
1 |
case OptionType::ULONG: |
|
98 |
✓ | 1 |
return "ULONG"; |
99 |
1 |
case OptionType::FLOAT: |
|
100 |
✓ | 1 |
return "FLOAT"; |
101 |
1 |
case OptionType::DOUBLE: |
|
102 |
✓ | 1 |
return "DOUBLE"; |
103 |
1 |
default: |
|
104 |
✓ | 1 |
return ""; |
105 |
} |
||
106 |
} |
||
107 |
|||
108 |
template<> |
||
109 |
104 |
OptionType::OptionType getOptionTypeFromType<std::string>(){return OptionType::STRING;} |
|
110 |
template<> |
||
111 |
1 |
OptionType::OptionType getOptionTypeFromType<bool>(){return OptionType::BOOL;} |
|
112 |
template<> |
||
113 |
1 |
OptionType::OptionType getOptionTypeFromType<char>(){return OptionType::CHAR;} |
|
114 |
template<> |
||
115 |
1 |
OptionType::OptionType getOptionTypeFromType<short>(){return OptionType::SHORT;} |
|
116 |
template<> |
||
117 |
3 |
OptionType::OptionType getOptionTypeFromType<int>(){return OptionType::INT;} |
|
118 |
template<> |
||
119 |
1 |
OptionType::OptionType getOptionTypeFromType<long>(){return OptionType::LONG;} |
|
120 |
template<> |
||
121 |
1 |
OptionType::OptionType getOptionTypeFromType<unsigned char>(){return OptionType::UCHAR;} |
|
122 |
template<> |
||
123 |
1 |
OptionType::OptionType getOptionTypeFromType<unsigned short>(){return OptionType::USHORT;} |
|
124 |
template<> |
||
125 |
1 |
OptionType::OptionType getOptionTypeFromType<unsigned int>(){return OptionType::UINT;} |
|
126 |
template<> |
||
127 |
1 |
OptionType::OptionType getOptionTypeFromType<unsigned long>(){return OptionType::ULONG;} |
|
128 |
template<> |
||
129 |
1 |
OptionType::OptionType getOptionTypeFromType<float>(){return OptionType::FLOAT;} |
|
130 |
template<> |
||
131 |
1 |
OptionType::OptionType getOptionTypeFromType<double>(){return OptionType::DOUBLE;} |
|
132 |
|||
133 |
|||
134 |
|||
135 |
|||
136 |
Generated by: GCOVR (Version 4.2) |