PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
ArgParser Class Reference

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

#include <ArgParser.h>

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...
 
std::string & getCurrentOption ()
 
const std::string & getCurrentOption () const
 Get the current option. More...
 
const std::string & getCursorOption () 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 std::string & getPrevCursorOption () const
 Get the previous option before the cursor option. 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...
 
std::string p_cursorOption
 Option which is typed right now, given to the program (in bash completion mode) More...
 
std::string 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 16 of file ArgParser.h.

Constructor & Destructor Documentation

◆ ArgParser() [1/3]

ArgParser::ArgParser ( )

Default constructor of ArgParser.

Definition at line 12 of file ArgParser.cpp.

12  {
14 }

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 20 of file ArgParser.cpp.

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

References initialisationArgParser(), isSameBegining(), p_bashCompletionMode, p_cursorOption, p_prevCursorOption, p_vecArg, and replaceStrInStr().

+ 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 48 of file ArgParser.cpp.

48  {
49  copyArgParser(other);
50 }

References copyArgParser().

+ Here is the call graph for this function:

◆ ~ArgParser()

ArgParser::~ArgParser ( )
virtual

Destructeur of ArgParser.

Definition at line 53 of file ArgParser.cpp.

53  {
54 
55 }

Member Function Documentation

◆ copyArgParser()

void ArgParser::copyArgParser ( const ArgParser other)
protected

Copy function of ArgParser.

Parameters
other: class to copy

Definition at line 135 of file ArgParser.cpp.

135  {
136  p_vecArg = other.p_vecArg;
137  p_currentArg = other.p_currentArg;
140 }

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]

std::string& ArgParser::getCurrentOption ( )

◆ getCurrentOption() [2/2]

std::string & ArgParser::getCurrentOption ( ) const

Get the current option.

Returns
current option

Definition at line 93 of file ArgParser.cpp.

93  {
94  return p_vecArg[p_currentArg];
95 }

References p_currentArg, and p_vecArg.

Referenced by testArgParserArg(), and testConstGetCurrentOption().

+ Here is the caller graph for this function:

◆ getCursorOption()

const std::string & 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 121 of file ArgParser.cpp.

121  {
122  return p_cursorOption;
123 }

References p_cursorOption.

◆ 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 107 of file ArgParser.cpp.

107  {
108  return p_vecArg.size();
109 }

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 79 of file ArgParser.cpp.

79  {
80  ++p_currentArg;
81 }

References p_currentArg.

◆ getPrevCursorOption()

const std::string & ArgParser::getPrevCursorOption ( ) const

Get the previous option before the cursor option.

Returns
previous option before the cursor option

Definition at line 128 of file ArgParser.cpp.

128  {
129  return p_prevCursorOption;
130 }

References p_prevCursorOption.

◆ initialisationArgParser()

void ArgParser::initialisationArgParser ( )
private

Initialisation function of the class ArgParser.

Definition at line 143 of file ArgParser.cpp.

143  {
144  p_currentArg = 0lu;
145  p_bashCompletionMode = false;
146  p_cursorOption = "";
147  p_prevCursorOption = "";
148 }

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 114 of file ArgParser.cpp.

114  {
115  return p_bashCompletionMode;
116 }

References p_bashCompletionMode.

◆ 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 86 of file ArgParser.cpp.

86  {
87  return p_currentArg >= p_vecArg.size();
88 }

References p_currentArg, and p_vecArg.

◆ operator=()

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

Definition of equal operator of ArgParser.

Parameters
other: class to copy
Returns
copied class

Definition at line 61 of file ArgParser.cpp.

61  {
62  copyArgParser(other);
63  return *this;
64 }

References copyArgParser().

+ Here is the call graph for this function:

◆ print()

void ArgParser::print ( ) const

Print all the input option.

Definition at line 67 of file ArgParser.cpp.

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

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 74 of file ArgParser.cpp.

74  {
75  p_currentArg = 0lu;
76 }

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 50 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 48 of file ArgParser.h.

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

◆ p_cursorOption

std::string ArgParser::p_cursorOption
private

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

Definition at line 53 of file ArgParser.h.

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

◆ p_prevCursorOption

std::string ArgParser::p_prevCursorOption
private

Previous option before the cursor option.

Definition at line 55 of file ArgParser.h.

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

◆ p_vecArg

PVecString ArgParser::p_vecArg
private

Vector of arguments.

Definition at line 46 of file ArgParser.h.

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


The documentation for this class was generated from the following files:
ArgParser::copyArgParser
void copyArgParser(const ArgParser &other)
Copy function of ArgParser.
Definition: ArgParser.cpp:135
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::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
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::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::p_bashCompletionMode
bool p_bashCompletionMode
Say if the program is in bash completion mode.
Definition: ArgParser.h:50
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