Directory: | ./ |
---|---|
File: | src/OptionType.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 64 | 64 | 100.0% |
Branches: | 66 | 74 | 89.2% |
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 | 5 | bool isOptionSignedInteger(OptionType::OptionType type){ | |
14 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
|
5 | 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 | 2 | bool isOptionUnsignedInteger(OptionType::OptionType type){ | |
22 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | 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 | 4 | bool isOptionInteger(OptionType::OptionType type){ | |
30 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
4 | 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 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
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 | 24 | bool isOptionStringFileDir(OptionType::OptionType type){ | |
46 |
8/8✓ Branch 0 taken 14 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 2 times.
|
24 | 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 | 38 | bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType){ | |
55 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 11 times.
|
38 | if(typeFromParam == typeFromType){return true;} |
56 | //If we are waiting for a boolean, but we do not get one, => fail | ||
57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if(typeFromParam == OptionType::BOOL){return false;} |
58 |
5/6✓ Branch 1 taken 9 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 2 times.
|
11 | if(isOptionStringFileDir(typeFromParam) && isOptionStringFileDir(typeFromType)){return true;} |
59 | |||
60 |
5/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
2 | if(isOptionInteger(typeFromParam) && isOptionFloatingPoint(typeFromType)){return false;} |
61 | |||
62 | 1 | return true; | |
63 | } | ||
64 | |||
65 | ///Convert the OptionType into string | ||
66 | /** @param type : OptionType to be converted | ||
67 | * @return string | ||
68 | */ | ||
69 | 91 | std::string convertOptionTypeToString(OptionType::OptionType type){ | |
70 |
17/17✓ Branch 0 taken 1 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 26 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
|
91 | switch(type){ |
71 | 1 | case OptionType::NONE: | |
72 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "NONE"; |
73 | 30 | case OptionType::STRING: | |
74 |
1/1✓ Branch 2 taken 30 times.
|
30 | return "STRING"; |
75 | 17 | case OptionType::FILENAME: | |
76 |
1/1✓ Branch 2 taken 17 times.
|
17 | return "FILENAME"; |
77 | 5 | case OptionType::DIRECTORY: | |
78 |
1/1✓ Branch 2 taken 5 times.
|
5 | return "DIRECTORY"; |
79 | 1 | case OptionType::FILE_OR_DIR: | |
80 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "FILE_OR_DIR"; |
81 | 1 | case OptionType::BOOL: | |
82 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "BOOL"; |
83 | 1 | case OptionType::CHAR: | |
84 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "CHAR"; |
85 | 1 | case OptionType::SHORT: | |
86 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "SHORT"; |
87 | 26 | case OptionType::INT: | |
88 |
1/1✓ Branch 2 taken 26 times.
|
26 | return "INT"; |
89 | 1 | case OptionType::LONG: | |
90 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "LONG"; |
91 | 1 | case OptionType::UCHAR: | |
92 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "UCHAR"; |
93 | 1 | case OptionType::USHORT: | |
94 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "USHORT"; |
95 | 1 | case OptionType::UINT: | |
96 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "UINT"; |
97 | 1 | case OptionType::ULONG: | |
98 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "ULONG"; |
99 | 1 | case OptionType::FLOAT: | |
100 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "FLOAT"; |
101 | 1 | case OptionType::DOUBLE: | |
102 |
1/1✓ Branch 2 taken 1 times.
|
1 | return "DOUBLE"; |
103 | 1 | default: | |
104 |
1/1✓ Branch 2 taken 1 times.
|
1 | return ""; |
105 | } | ||
106 | } | ||
107 | |||
108 | template<> | ||
109 | 77 | 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 | |||
137 |