GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixOptionParser/src/ArgParser.cpp
Date: 2025-03-14 11:54:19
Exec Total Coverage
Lines: 75 75 100.0%
Branches: 43 43 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 #include <iostream>
8 #include "ArgParser.h"
9
10 ///Default constructor of ArgParser
11
2/2
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
4 ArgParser::ArgParser(){
12
1/1
✓ Branch 1 taken 4 times.
4 initialisationArgParser();
13 4 }
14
15 ///Constructor with arguments passed to the program
16 /** @param argc : number of parameters passed to the program
17 * @param argv : list of arguments passed to the program
18 */
19
2/2
✓ Branch 2 taken 69 times.
✓ Branch 5 taken 69 times.
69 ArgParser::ArgParser(int argc, char** argv){
20
1/1
✓ Branch 1 taken 69 times.
69 initialisationArgParser();
21 69 bool skipNext(false);
22
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 69 times.
288 for(int i(1); i < argc; ++i){
23
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 192 times.
219 if(skipNext){
24 27 skipNext = false;
25 27 continue;
26 }
27
1/1
✓ Branch 1 taken 192 times.
192 PString argument(argv[i]);
28
4/4
✓ Branch 1 taken 192 times.
✓ Branch 4 taken 192 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 165 times.
192 if(argument.isSameBegining("__bashcompletionmode=")){
29
3/3
✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
54 PString cursorOptionValue(argument.replace("__bashcompletionmode=", ""));
30
1/1
✓ Branch 1 taken 27 times.
27 p_cursorOption = cursorOptionValue;
31 27 p_bashCompletionMode = true;
32
4/4
✓ Branch 2 taken 165 times.
✓ Branch 5 taken 165 times.
✓ Branch 8 taken 27 times.
✓ Branch 9 taken 138 times.
192 }else if(argument.isSameBegining("__bashcompletionmodeprev=")){
33
3/3
✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
54 PString cursorOptionValue(argument.replace("__bashcompletionmodeprev=", ""));
34
1/1
✓ Branch 1 taken 27 times.
27 p_prevCursorOption = cursorOptionValue;
35 27 p_bashCompletionMode = true;
36 27 skipNext = true; //The next arguments are the cursor option and the name of the program, we do not want it
37 27 }else{
38
1/1
✓ Branch 1 taken 138 times.
138 p_vecArg.push_back(argument);
39 }
40 192 }
41 69 }
42
43 ///Copy constructor of ArgParser
44 /** @param other : class to copy
45 */
46
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 ArgParser::ArgParser(const ArgParser & other){
47
1/1
✓ Branch 1 taken 3 times.
3 copyArgParser(other);
48 3 }
49
50 ///Destructeur of ArgParser
51 84 ArgParser::~ArgParser(){
52
53 }
54
55 ///Definition of equal operator of ArgParser
56 /** @param other : class to copy
57 * @return copied class
58 */
59 3 ArgParser & ArgParser::operator = (const ArgParser & other){
60 3 copyArgParser(other);
61 3 return *this;
62 }
63
64 ///Print all the input option
65 4 void ArgParser::print() const{
66
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 for(PVecString::const_iterator it(p_vecArg.begin()); it != p_vecArg.end(); ++it){
67
3/3
✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
2 std::cout << "\t" << *it << std::endl;
68 }
69 4 }
70
71 ///Go bask to the first argument
72 3 void ArgParser::rewind(){
73 3 p_currentArg = 0lu;
74 3 }
75
76 ///Move to the next option
77 134 void ArgParser::getNextOption(){
78 134 ++p_currentArg;
79 134 }
80
81 ///Say if is it the end of the options
82 /** @return true if is it the end of the options, false if not
83 */
84 596 bool ArgParser::isEndOfOption() const{
85 596 return p_currentArg >= p_vecArg.size();
86 }
87
88 ///Get the current option
89 /** @return current option
90 */
91 1 const PString & ArgParser::getCurrentOption() const{
92 1 return p_vecArg[p_currentArg];
93 }
94
95 ///Get the current option
96 /** @return current option
97 */
98 550 PString & ArgParser::getCurrentOption(){
99 550 return p_vecArg[p_currentArg];
100 }
101
102 ///Get the number of arguments passed to the program
103 /** @return number of arguments passed to the program
104 */
105 5 size_t ArgParser::getNbArgument() const{
106 5 return p_vecArg.size();
107 }
108
109 ///Say if the program is in bash completion mode
110 /** @return true if the program is in bash completion mode, false if not
111 */
112 66 bool ArgParser::isBashCompletionMode() const{
113 66 return p_bashCompletionMode;
114 }
115
116 ///Get the cursor option given to the program, in bash completion mode
117 /** @return cursor option given to the program, in bash completion mode
118 */
119 27 const PString & ArgParser::getCursorOption() const{
120 27 return p_cursorOption;
121 }
122
123 ///Get the previous option before the cursor option
124 /** @return previous option before the cursor option
125 */
126 27 const PString & ArgParser::getPrevCursorOption() const{
127 27 return p_prevCursorOption;
128 }
129
130 ///Get all remaining arguments of the ArgParser
131 /** @return PString of all remaining arguments of the ArgParser
132 */
133 1 PString ArgParser::getRemainingArgument(){
134
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 PString remainingOpt, separator("");
135
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 for(size_t i(p_currentArg); i < p_vecArg.size(); ++i){
136
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 remainingOpt += separator + p_vecArg[i];
137
1/1
✓ Branch 1 taken 1 times.
1 separator = " ";
138 }
139 1 p_currentArg = p_vecArg.size();
140 2 return remainingOpt;
141 1 }
142
143 ///Copy function of ArgParser
144 /** @param other : class to copy
145 */
146 6 void ArgParser::copyArgParser(const ArgParser & other){
147 6 p_vecArg = other.p_vecArg;
148 6 p_currentArg = other.p_currentArg;
149 6 p_cursorOption = other.p_cursorOption;
150 6 p_prevCursorOption = other.p_prevCursorOption;
151 6 }
152
153 ///Initialisation function of the class ArgParser
154 73 void ArgParser::initialisationArgParser(){
155 73 p_currentArg = 0lu;
156 73 p_bashCompletionMode = false;
157 73 p_cursorOption = "";
158 73 p_prevCursorOption = "";
159 73 }
160
161
162
163
164
165