GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/OptionParser/src/ArgParser.cpp Lines: 65 65 100.0 %
Date: 2023-10-11 10:52:07 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
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
61
ArgParser::ArgParser(int argc, char** argv){
21
61
	initialisationArgParser();
22
61
	bool skipNext(false);
23
246
	for(int i(1); i < argc; ++i){
24
185
		if(skipNext){
25
22
			skipNext = false;
26
22
			continue;
27
		}
28
29
326
		std::string argument(argv[i]);
30

163
		if(isSameBegining(argument, "__bashcompletionmode=")){
31
44
			std::string cursorOptionValue(replaceStrInStr(argument, "__bashcompletionmode=", ""));
32
22
			p_cursorOption = cursorOptionValue;
33
22
			p_bashCompletionMode = true;
34

141
		}else if(isSameBegining(argument, "__bashcompletionmodeprev=")){
35
44
			std::string cursorOptionValue(replaceStrInStr(argument, "__bashcompletionmodeprev=", ""));
36
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
		}else{
40
119
			p_vecArg.push_back(argument);
41
		}
42
	}
43
61
}
44
45
///Copy constructor of ArgParser
46
/**	@param other : class to copy
47
*/
48
3
ArgParser::ArgParser(const ArgParser & other){
49
3
	copyArgParser(other);
50
3
}
51
52
///Destructeur of ArgParser
53
80
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
6
	for(PVecString::const_iterator it(p_vecArg.begin()); it != p_vecArg.end(); ++it){
69
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
117
void ArgParser::getNextOption(){
80
117
	++p_currentArg;
81
117
}
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
567
bool ArgParser::isEndOfOption() const{
87
567
	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
488
std::string & ArgParser::getCurrentOption(){
101
488
	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
59
bool ArgParser::isBashCompletionMode() const{
115
59
	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
65
void ArgParser::initialisationArgParser(){
144
65
	p_currentArg = 0lu;
145
65
	p_bashCompletionMode = false;
146
65
	p_cursorOption = "";
147
65
	p_prevCursorOption = "";
148
65
}
149
150
151
152
153