PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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 "ArgParser.h"
9 
13 }
14 
16 
19 ArgParser::ArgParser(int argc, char** argv){
21  bool skipNext(false);
22  for(int i(1); i < argc; ++i){
23  if(skipNext){
24  skipNext = false;
25  continue;
26  }
27  PString argument(argv[i]);
28  if(argument.isSameBegining("__bashcompletionmode=")){
29  PString cursorOptionValue(argument.replace("__bashcompletionmode=", ""));
30  p_cursorOption = cursorOptionValue;
31  p_bashCompletionMode = true;
32  }else if(argument.isSameBegining("__bashcompletionmodeprev=")){
33  PString cursorOptionValue(argument.replace("__bashcompletionmodeprev=", ""));
34  p_prevCursorOption = cursorOptionValue;
35  p_bashCompletionMode = true;
36  skipNext = true; //The next arguments are the cursor option and the name of the program, we do not want it
37  }else{
38  p_vecArg.push_back(argument);
39  }
40  }
41 }
42 
44 
47  copyArgParser(other);
48 }
49 
52 
53 }
54 
56 
60  copyArgParser(other);
61  return *this;
62 }
63 
65 void ArgParser::print() const{
66  for(PVecString::const_iterator it(p_vecArg.begin()); it != p_vecArg.end(); ++it){
67  std::cout << "\t" << *it << std::endl;
68  }
69 }
70 
73  p_currentArg = 0lu;
74 }
75 
78  ++p_currentArg;
79 }
80 
82 
85  return p_currentArg >= p_vecArg.size();
86 }
87 
89 
92  return p_vecArg[p_currentArg];
93 }
94 
96 
99  return p_vecArg[p_currentArg];
100 }
101 
103 
106  return p_vecArg.size();
107 }
108 
110 
113  return p_bashCompletionMode;
114 }
115 
117 
120  return p_cursorOption;
121 }
122 
124 
127  return p_prevCursorOption;
128 }
129 
131 
134  PString remainingOpt, separator("");
135  for(size_t i(p_currentArg); i < p_vecArg.size(); ++i){
136  remainingOpt += separator + p_vecArg[i];
137  separator = " ";
138  }
139  p_currentArg = p_vecArg.size();
140  return remainingOpt;
141 }
142 
144 
147  p_vecArg = other.p_vecArg;
148  p_currentArg = other.p_currentArg;
151 }
152 
155  p_currentArg = 0lu;
156  p_bashCompletionMode = false;
157  p_cursorOption = "";
158  p_prevCursorOption = "";
159 }
160 
161 
162 
163 
164 
Parse the list of arguments passed to a program.
Definition: ArgParser.h:13
virtual ~ArgParser()
Destructeur of ArgParser.
Definition: ArgParser.cpp:51
ArgParser & operator=(const ArgParser &other)
Definition of equal operator of ArgParser.
Definition: ArgParser.cpp:59
void print() const
Print all the input option.
Definition: ArgParser.cpp:65
const PString & getCurrentOption() const
Get the current option.
Definition: ArgParser.cpp:91
size_t p_currentArg
Current argument to be parsed.
Definition: ArgParser.h:46
PVecString p_vecArg
Vector of arguments.
Definition: ArgParser.h:44
const PString & getCursorOption() const
Get the cursor option given to the program, in bash completion mode.
Definition: ArgParser.cpp:119
void rewind()
Go bask to the first argument.
Definition: ArgParser.cpp:72
bool isBashCompletionMode() const
Say if the program is in bash completion mode.
Definition: ArgParser.cpp:112
void copyArgParser(const ArgParser &other)
Copy function of ArgParser.
Definition: ArgParser.cpp:146
void getNextOption()
Move to the next option.
Definition: ArgParser.cpp:77
const PString & getPrevCursorOption() const
Get the previous option before the cursor option.
Definition: ArgParser.cpp:126
ArgParser()
Default constructor of ArgParser.
Definition: ArgParser.cpp:11
PString p_cursorOption
Option which is typed right now, given to the program (in bash completion mode)
Definition: ArgParser.h:51
bool p_bashCompletionMode
Say if the program is in bash completion mode.
Definition: ArgParser.h:48
size_t getNbArgument() const
Get the number of arguments passed to the program.
Definition: ArgParser.cpp:105
PString p_prevCursorOption
Previous option before the cursor option.
Definition: ArgParser.h:53
bool isEndOfOption() const
Say if is it the end of the options.
Definition: ArgParser.cpp:84
PString getRemainingArgument()
Get all remaining arguments of the ArgParser.
Definition: ArgParser.cpp:133
void initialisationArgParser()
Initialisation function of the class ArgParser.
Definition: ArgParser.cpp:154
Extends the std::string.
Definition: PString.h:16
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
Definition: PString.cpp:306