GCC Code Coverage Report


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