PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
ArgParser.cpp
Go to the documentation of this file.
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 
14 }
15 
17 
20 ArgParser::ArgParser(int argc, char** argv){
22  bool skipNext(false);
23  for(int i(1); i < argc; ++i){
24  if(skipNext){
25  skipNext = false;
26  continue;
27  }
28 
29  std::string argument(argv[i]);
30  if(isSameBegining(argument, "__bashcompletionmode=")){
31  std::string cursorOptionValue(replaceStrInStr(argument, "__bashcompletionmode=", ""));
32  p_cursorOption = cursorOptionValue;
33  p_bashCompletionMode = true;
34  }else if(isSameBegining(argument, "__bashcompletionmodeprev=")){
35  std::string cursorOptionValue(replaceStrInStr(argument, "__bashcompletionmodeprev=", ""));
36  p_prevCursorOption = cursorOptionValue;
37  p_bashCompletionMode = true;
38  skipNext = true; //The next arguments are the cursor option and the name of the program, we do not want it
39  }else{
40  p_vecArg.push_back(argument);
41  }
42  }
43 }
44 
46 
49  copyArgParser(other);
50 }
51 
54 
55 }
56 
58 
62  copyArgParser(other);
63  return *this;
64 }
65 
67 void ArgParser::print() const{
68  for(PVecString::const_iterator it(p_vecArg.begin()); it != p_vecArg.end(); ++it){
69  std::cout << "\t" << *it << std::endl;
70  }
71 }
72 
75  p_currentArg = 0lu;
76 }
77 
80  ++p_currentArg;
81 }
82 
84 
87  return p_currentArg >= p_vecArg.size();
88 }
89 
91 
93 const std::string & ArgParser::getCurrentOption() const{
94  return p_vecArg[p_currentArg];
95 }
96 
98 
100 std::string & ArgParser::getCurrentOption(){
101  return p_vecArg[p_currentArg];
102 }
103 
105 
108  return p_vecArg.size();
109 }
110 
112 
115  return p_bashCompletionMode;
116 }
117 
119 
121 const std::string & ArgParser::getCursorOption() const{
122  return p_cursorOption;
123 }
124 
126 
128 const std::string & ArgParser::getPrevCursorOption() const{
129  return p_prevCursorOption;
130 }
131 
133 
136  p_vecArg = other.p_vecArg;
137  p_currentArg = other.p_currentArg;
140 }
141 
144  p_currentArg = 0lu;
145  p_bashCompletionMode = false;
146  p_cursorOption = "";
147  p_prevCursorOption = "";
148 }
149 
150 
151 
152 
153 
ArgParser::copyArgParser
void copyArgParser(const ArgParser &other)
Copy function of ArgParser.
Definition: ArgParser.cpp:135
string_utils.h
ArgParser::initialisationArgParser
void initialisationArgParser()
Initialisation function of the class ArgParser.
Definition: ArgParser.cpp:143
ArgParser::p_vecArg
PVecString p_vecArg
Vector of arguments.
Definition: ArgParser.h:46
ArgParser::getPrevCursorOption
const std::string & getPrevCursorOption() const
Get the previous option before the cursor option.
Definition: ArgParser.cpp:128
ArgParser::getCurrentOption
const std::string & getCurrentOption() const
Get the current option.
Definition: ArgParser.cpp:93
ArgParser::p_prevCursorOption
std::string p_prevCursorOption
Previous option before the cursor option.
Definition: ArgParser.h:55
ArgParser::p_currentArg
size_t p_currentArg
Current argument to be parsed.
Definition: ArgParser.h:48
ArgParser.h
isSameBegining
bool isSameBegining(const std::string &str, const std::string &beginig)
Check if two string start the same way.
Definition: string_function.cpp:531
ArgParser::print
void print() const
Print all the input option.
Definition: ArgParser.cpp:67
ArgParser::getNbArgument
size_t getNbArgument() const
Get the number of arguments passed to the program.
Definition: ArgParser.cpp:107
ArgParser::isBashCompletionMode
bool isBashCompletionMode() const
Say if the program is in bash completion mode.
Definition: ArgParser.cpp:114
ArgParser::p_cursorOption
std::string p_cursorOption
Option which is typed right now, given to the program (in bash completion mode)
Definition: ArgParser.h:53
ArgParser::getCursorOption
const std::string & getCursorOption() const
Get the cursor option given to the program, in bash completion mode.
Definition: ArgParser.cpp:121
ArgParser::ArgParser
ArgParser()
Default constructor of ArgParser.
Definition: ArgParser.cpp:12
ArgParser::p_bashCompletionMode
bool p_bashCompletionMode
Say if the program is in bash completion mode.
Definition: ArgParser.h:50
ArgParser::isEndOfOption
bool isEndOfOption() const
Say if is it the end of the options.
Definition: ArgParser.cpp:86
replaceStrInStr
void replaceStrInStr(std::string &out, const std::string &src, const std::string &patern, const std::string &replace)
Replace a patern by an other in the input string.
Definition: string_function.cpp:272
ArgParser::rewind
void rewind()
Go bask to the first argument.
Definition: ArgParser.cpp:74
ArgParser::getNextOption
void getNextOption()
Move to the next option.
Definition: ArgParser.cpp:79
ArgParser::operator=
ArgParser & operator=(const ArgParser &other)
Definition of equal operator of ArgParser.
Definition: ArgParser.cpp:61
ArgParser
Parse the list of arguments passed to a program.
Definition: ArgParser.h:16
ArgParser::~ArgParser
virtual ~ArgParser()
Destructeur of ArgParser.
Definition: ArgParser.cpp:53