PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
ArgParser Class Reference

Parse the list of arguments passed to a program. More...

#include <ArgParser.h>

+ Collaboration diagram for ArgParser:

Public Member Functions

 ArgParser ()
 Default constructor of ArgParser. More...
 
 ArgParser (const ArgParser &other)
 Copy constructor of ArgParser. More...
 
 ArgParser (int argc, char **argv)
 Constructor with arguments passed to the program. More...
 
PStringgetCurrentOption ()
 Get the current option. More...
 
const PStringgetCurrentOption () const
 Get the current option. More...
 
const PStringgetCursorOption () const
 Get the cursor option given to the program, in bash completion mode. More...
 
size_t getNbArgument () const
 Get the number of arguments passed to the program. More...
 
void getNextOption ()
 Move to the next option. More...
 
const PStringgetPrevCursorOption () const
 Get the previous option before the cursor option. More...
 
PString getRemainingArgument ()
 Get all remaining arguments of the ArgParser. More...
 
bool isBashCompletionMode () const
 Say if the program is in bash completion mode. More...
 
bool isEndOfOption () const
 Say if is it the end of the options. More...
 
ArgParseroperator= (const ArgParser &other)
 Definition of equal operator of ArgParser. More...
 
void print () const
 Print all the input option. More...
 
void rewind ()
 Go bask to the first argument. More...
 
virtual ~ArgParser ()
 Destructeur of ArgParser. More...
 

Protected Member Functions

void copyArgParser (const ArgParser &other)
 Copy function of ArgParser. More...
 

Private Member Functions

void initialisationArgParser ()
 Initialisation function of the class ArgParser. More...
 

Private Attributes

bool p_bashCompletionMode
 Say if the program is in bash completion mode. More...
 
size_t p_currentArg
 Current argument to be parsed. More...
 
PString p_cursorOption
 Option which is typed right now, given to the program (in bash completion mode) More...
 
PString p_prevCursorOption
 Previous option before the cursor option. More...
 
PVecString p_vecArg
 Vector of arguments. More...
 

Detailed Description

Parse the list of arguments passed to a program.

Definition at line 13 of file ArgParser.h.

Constructor & Destructor Documentation

◆ ArgParser() [1/3]

ArgParser::ArgParser ( )

Default constructor of ArgParser.

Definition at line 11 of file ArgParser.cpp.

11  {
13 }
void initialisationArgParser()
Initialisation function of the class ArgParser.
Definition: ArgParser.cpp:154

References initialisationArgParser().

+ Here is the call graph for this function:

◆ ArgParser() [2/3]

ArgParser::ArgParser ( int  argc,
char **  argv 
)

Constructor with arguments passed to the program.

Parameters
argc: number of parameters passed to the program
argv: list of arguments passed to the program

Definition at line 19 of file ArgParser.cpp.

19  {
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 }
PVecString p_vecArg
Vector of arguments.
Definition: ArgParser.h:44
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
PString p_prevCursorOption
Previous option before the cursor option.
Definition: ArgParser.h:53
Extends the std::string.
Definition: PString.h:16

References initialisationArgParser(), PString::isSameBegining(), p_bashCompletionMode, p_cursorOption, p_prevCursorOption, p_vecArg, and PString::replace().

+ Here is the call graph for this function:

◆ ArgParser() [3/3]

ArgParser::ArgParser ( const ArgParser other)

Copy constructor of ArgParser.

Parameters
other: class to copy

Definition at line 46 of file ArgParser.cpp.

46  {
47  copyArgParser(other);
48 }
void copyArgParser(const ArgParser &other)
Copy function of ArgParser.
Definition: ArgParser.cpp:146

References copyArgParser().

+ Here is the call graph for this function:

◆ ~ArgParser()

ArgParser::~ArgParser ( )
virtual

Destructeur of ArgParser.

Definition at line 51 of file ArgParser.cpp.

51  {
52 
53 }

Member Function Documentation

◆ copyArgParser()

void ArgParser::copyArgParser ( const ArgParser other)
protected

Copy function of ArgParser.

Parameters
other: class to copy

Definition at line 146 of file ArgParser.cpp.

146  {
147  p_vecArg = other.p_vecArg;
148  p_currentArg = other.p_currentArg;
151 }
size_t p_currentArg
Current argument to be parsed.
Definition: ArgParser.h:46

References p_currentArg, p_cursorOption, p_prevCursorOption, and p_vecArg.

Referenced by ArgParser(), and operator=().

+ Here is the caller graph for this function:

◆ getCurrentOption() [1/2]

PString & ArgParser::getCurrentOption ( )

Get the current option.

Returns
current option

Definition at line 98 of file ArgParser.cpp.

98  {
99  return p_vecArg[p_currentArg];
100 }

References p_currentArg, and p_vecArg.

◆ getCurrentOption() [2/2]

const PString & ArgParser::getCurrentOption ( ) const

Get the current option.

Returns
current option

Definition at line 91 of file ArgParser.cpp.

91  {
92  return p_vecArg[p_currentArg];
93 }

References p_currentArg, and p_vecArg.

Referenced by OptionParser::getParserMode(), OptionParser::parseArgumentNormalUse(), OptionMode::parseOption(), Option::parsePartOption(), testArgParserArg(), and testConstGetCurrentOption().

+ Here is the caller graph for this function:

◆ getCursorOption()

const PString & ArgParser::getCursorOption ( ) const

Get the cursor option given to the program, in bash completion mode.

Returns
cursor option given to the program, in bash completion mode

Definition at line 119 of file ArgParser.cpp.

119  {
120  return p_cursorOption;
121 }

References p_cursorOption.

Referenced by OptionParser::parseArgumentBashCompletion().

+ Here is the caller graph for this function:

◆ getNbArgument()

size_t ArgParser::getNbArgument ( ) const

Get the number of arguments passed to the program.

Returns
number of arguments passed to the program

Definition at line 105 of file ArgParser.cpp.

105  {
106  return p_vecArg.size();
107 }

References p_vecArg.

Referenced by testArgParser(), and testArgParserArg().

+ Here is the caller graph for this function:

◆ getNextOption()

void ArgParser::getNextOption ( )

Move to the next option.

Definition at line 77 of file ArgParser.cpp.

77  {
78  ++p_currentArg;
79 }

References p_currentArg.

Referenced by OptionParser::getParserMode(), OptionParser::parseArgumentBashCompletion(), OptionMode::parseOption(), and Option::parsePartOption().

+ Here is the caller graph for this function:

◆ getPrevCursorOption()

const PString & ArgParser::getPrevCursorOption ( ) const

Get the previous option before the cursor option.

Returns
previous option before the cursor option

Definition at line 126 of file ArgParser.cpp.

126  {
127  return p_prevCursorOption;
128 }

References p_prevCursorOption.

Referenced by OptionParser::parseArgumentBashCompletion().

+ Here is the caller graph for this function:

◆ getRemainingArgument()

PString ArgParser::getRemainingArgument ( )

Get all remaining arguments of the ArgParser.

Returns
PString of all remaining arguments of the ArgParser

Definition at line 133 of file ArgParser.cpp.

133  {
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 }

References p_currentArg, and p_vecArg.

Referenced by OptionMode::parseOption(), and testRemaningArgument().

+ Here is the caller graph for this function:

◆ initialisationArgParser()

void ArgParser::initialisationArgParser ( )
private

Initialisation function of the class ArgParser.

Definition at line 154 of file ArgParser.cpp.

154  {
155  p_currentArg = 0lu;
156  p_bashCompletionMode = false;
157  p_cursorOption = "";
158  p_prevCursorOption = "";
159 }

References p_bashCompletionMode, p_currentArg, p_cursorOption, and p_prevCursorOption.

Referenced by ArgParser().

+ Here is the caller graph for this function:

◆ isBashCompletionMode()

bool ArgParser::isBashCompletionMode ( ) const

Say if the program is in bash completion mode.

Returns
true if the program is in bash completion mode, false if not

Definition at line 112 of file ArgParser.cpp.

112  {
113  return p_bashCompletionMode;
114 }

References p_bashCompletionMode.

Referenced by OptionParser::parseArgument().

+ Here is the caller graph for this function:

◆ isEndOfOption()

bool ArgParser::isEndOfOption ( ) const

Say if is it the end of the options.

Returns
true if is it the end of the options, false if not

Definition at line 84 of file ArgParser.cpp.

84  {
85  return p_currentArg >= p_vecArg.size();
86 }

References p_currentArg, and p_vecArg.

Referenced by OptionParser::parseArgumentBashCompletion(), OptionParser::parseArgumentNormalUse(), OptionMode::parseOption(), and Option::parsePartOption().

+ Here is the caller graph for this function:

◆ operator=()

ArgParser & ArgParser::operator= ( const ArgParser other)

Definition of equal operator of ArgParser.

Parameters
other: class to copy
Returns
copied class

Definition at line 59 of file ArgParser.cpp.

59  {
60  copyArgParser(other);
61  return *this;
62 }

References copyArgParser().

+ Here is the call graph for this function:

◆ print()

void ArgParser::print ( ) const

Print all the input option.

Definition at line 65 of file ArgParser.cpp.

65  {
66  for(PVecString::const_iterator it(p_vecArg.begin()); it != p_vecArg.end(); ++it){
67  std::cout << "\t" << *it << std::endl;
68  }
69 }

References p_vecArg.

Referenced by testArgParser(), and testArgParserArg().

+ Here is the caller graph for this function:

◆ rewind()

void ArgParser::rewind ( )

Go bask to the first argument.

Definition at line 72 of file ArgParser.cpp.

72  {
73  p_currentArg = 0lu;
74 }

References p_currentArg.

Referenced by testArgParser(), and testArgParserArg().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_bashCompletionMode

bool ArgParser::p_bashCompletionMode
private

Say if the program is in bash completion mode.

Definition at line 48 of file ArgParser.h.

Referenced by ArgParser(), initialisationArgParser(), and isBashCompletionMode().

◆ p_currentArg

size_t ArgParser::p_currentArg
private

Current argument to be parsed.

Definition at line 46 of file ArgParser.h.

Referenced by copyArgParser(), getCurrentOption(), getNextOption(), getRemainingArgument(), initialisationArgParser(), isEndOfOption(), and rewind().

◆ p_cursorOption

PString ArgParser::p_cursorOption
private

Option which is typed right now, given to the program (in bash completion mode)

Definition at line 51 of file ArgParser.h.

Referenced by ArgParser(), copyArgParser(), getCursorOption(), and initialisationArgParser().

◆ p_prevCursorOption

PString ArgParser::p_prevCursorOption
private

Previous option before the cursor option.

Definition at line 53 of file ArgParser.h.

Referenced by ArgParser(), copyArgParser(), getPrevCursorOption(), and initialisationArgParser().

◆ p_vecArg

PVecString ArgParser::p_vecArg
private

Vector of arguments.

Definition at line 44 of file ArgParser.h.

Referenced by ArgParser(), copyArgParser(), getCurrentOption(), getNbArgument(), getRemainingArgument(), isEndOfOption(), and print().


The documentation for this class was generated from the following files: