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

Describe a mode in the program arguments. More...

#include <OptionMode.h>

Public Member Functions

void addOption (const Option &option)
 Add an option into the OptionMode. More...
 
bool checkArgument () const
 Check the argument of the parser. More...
 
void clearOption ()
 Remove all the options of the OptionMode. More...
 
std::string & getName ()
 
const std::string & getName () const
 Get the name of the OptionMode. More...
 
void getPossibleMode (std::string &possibleOption, const std::string &cursorOption) const
 Get the possible mode. More...
 
void getPossibleOption (std::string &possibleOption, const std::string &cursorOption) const
 Get the possible options for the bash completion. More...
 
template<typename T >
bool getValue (T &value, const std::string &optionName) const
 Get the value of the option. More...
 
VecOptiongetVecOption ()
 
const VecOptiongetVecOption () const
 Get the vector of options of the OptionMode. More...
 
bool isCurrentlyParsed () const
 Say if the OptionMode is currently parsed (but maybe not totally) More...
 
bool isOptionExist (const std::string &optionName) const
 Say if the given option has been passed to the program. More...
 
bool isParsed () const
 Say if the OptionMode contains option which are parsed. More...
 
OptionModeoperator= (const OptionMode &other)
 Definition of equal operator of OptionMode. More...
 
 OptionMode (const OptionMode &other)
 Copy constructor of OptionMode. More...
 
 OptionMode (const std::string &name="")
 Default constructeur of OptionMode. More...
 
bool parseOption (ArgParser &parser)
 Parse the options in the current OptionMode. More...
 
bool parseOption (ArgParser &parser, Option *&partialOption)
 Parse the options in the current OptionMode. More...
 
void print () const
 Print the option of the mode. More...
 
void setEnableHelpOption (bool b)
 Set the attribtue which enables help option. More...
 
void setName (const std::string &name)
 Set the name of the OptionMode. More...
 
void setProgramVersion (const std::string &programVersion)
 Set the program version. More...
 
void setVecOption (const VecOption &vecOption)
 Set the vector of options of the OptionMode. More...
 
virtual ~OptionMode ()
 Destructeur of OptionMode. More...
 

Protected Member Functions

void copyOptionMode (const OptionMode &other)
 Copy function of OptionMode. More...
 

Private Member Functions

bool getOption (Option &option, const std::string &optionName) const
 Get the option with its name. More...
 
void initialisationOptionMode ()
 Initialisation function of the class OptionMode. More...
 
void iterGetPossibleOption (std::string &possibleOption, const std::string &cursorOption) const
 Iterates over the possible options of the current mode. More...
 

Private Attributes

bool p_enableHelpOption
 True to enable automatically the printing of the help option when the program is called with –help or -h. More...
 
bool p_isCurrentlyParsed
 True if the OptionMode is currently parsed but not totally. More...
 
bool p_isParsed
 Say if the mode contains options which are parsed. More...
 
std::string p_name
 name of the OptionMode More...
 
std::string p_programVersion
 Program version to be printed on –version or -v option. More...
 
VecOption p_vecOption
 Vector of all the options of the OptionMode. More...
 

Detailed Description

Describe a mode in the program arguments.

Definition at line 13 of file OptionMode.h.

Constructor & Destructor Documentation

◆ OptionMode() [1/2]

OptionMode::OptionMode ( const std::string &  name = "")

Default constructeur of OptionMode.

Parameters
name: name of the mode

Definition at line 15 of file OptionMode.cpp.

16  :p_name(name)
17 {
19 }

References initialisationOptionMode().

+ Here is the call graph for this function:

◆ OptionMode() [2/2]

OptionMode::OptionMode ( const OptionMode other)

Copy constructor of OptionMode.

Parameters
other: class to copy

Definition at line 24 of file OptionMode.cpp.

24  {
25  copyOptionMode(other);
26 }

References copyOptionMode().

+ Here is the call graph for this function:

◆ ~OptionMode()

OptionMode::~OptionMode ( )
virtual

Destructeur of OptionMode.

Definition at line 29 of file OptionMode.cpp.

29  {
30 
31 }

Member Function Documentation

◆ addOption()

void OptionMode::addOption ( const Option option)

Add an option into the OptionMode.

Parameters
optionoption to be added into the OptionMode

Definition at line 128 of file OptionMode.cpp.

128 {p_vecOption.push_back(option);}

References p_vecOption.

◆ checkArgument()

bool OptionMode::checkArgument ( ) const

Check the argument of the parser.

Returns
true if all the required arguments are set, false otherwise

Definition at line 166 of file OptionMode.cpp.

166  {
167  if(!p_isParsed){return true;}
168  bool isArgOk(true);
169  VecOption::const_iterator it(p_vecOption.begin());
170  while(it != p_vecOption.end() && isArgOk){
171  isArgOk = it->checkArgument();
172  ++it;
173  }
174  return isArgOk;
175 }

References p_isParsed, and p_vecOption.

◆ clearOption()

void OptionMode::clearOption ( )

Remove all the options of the OptionMode.

Definition at line 131 of file OptionMode.cpp.

131 {p_vecOption.clear();}

References p_vecOption.

◆ copyOptionMode()

void OptionMode::copyOptionMode ( const OptionMode other)
protected

Copy function of OptionMode.

Parameters
other: class to copy

Definition at line 236 of file OptionMode.cpp.

236  {
237  p_name = other.p_name;
238  p_vecOption = other.p_vecOption;
240  p_isParsed = other.p_isParsed;
243 }

References p_enableHelpOption, p_isCurrentlyParsed, p_isParsed, p_name, p_programVersion, and p_vecOption.

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

+ Here is the caller graph for this function:

◆ getName() [1/2]

std::string& OptionMode::getName ( )

◆ getName() [2/2]

std::string & OptionMode::getName ( ) const

Get the name of the OptionMode.

Returns
name of the OptionMode

Definition at line 146 of file OptionMode.cpp.

146 {return p_name;}

References p_name.

Referenced by OptionParser::parseArgumentNormalUse().

+ Here is the caller graph for this function:

◆ getOption()

bool OptionMode::getOption ( Option option,
const std::string &  optionName 
) const
private

Get the option with its name.

Parameters
[out]option: option if it has been found
optionName: name of the option to be searched
Returns
true if the option has been found, false otherwise

Definition at line 257 of file OptionMode.cpp.

257  {
258  VecOption::const_iterator it(p_vecOption.begin());
259  while(it != p_vecOption.end()){
260  if(it->getLongName() == optionName || it->getShortName() == optionName){
261  option = *it;
262  return true;
263  }
264  ++it;
265  }
266  return false;
267 }

References p_vecOption.

Referenced by getValue().

+ Here is the caller graph for this function:

◆ getPossibleMode()

void OptionMode::getPossibleMode ( std::string &  possibleOption,
const std::string &  cursorOption 
) const

Get the possible mode.

Parameters
[out]possibleOption: possible options for the bash completion
cursorOption: option of the cursor which is currently completed

Definition at line 225 of file OptionMode.cpp.

225  {
226  if(p_name != ""){
227  if(isSameBegining(p_name, cursorOption)){
228  possibleOption += p_name + " ";
229  }
230  }
231 }

References isSameBegining(), and p_name.

+ Here is the call graph for this function:

◆ getPossibleOption()

void OptionMode::getPossibleOption ( std::string &  possibleOption,
const std::string &  cursorOption 
) const

Get the possible options for the bash completion.

Parameters
[out]possibleOption: possible options for the bash completion
cursorOption: option of the cursor which is currently completed

Definition at line 210 of file OptionMode.cpp.

210  {
211  if(p_name != ""){
212  if(!p_isCurrentlyParsed){
213  if(isSameBegining(p_name, cursorOption)){
214  possibleOption += p_name + " ";
215  }
216  }
217  }
218  iterGetPossibleOption(possibleOption, cursorOption);
219 }

References isSameBegining(), iterGetPossibleOption(), p_isCurrentlyParsed, and p_name.

Referenced by OptionParser::getPossibleOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValue()

template<typename T >
bool OptionMode::getValue ( T &  value,
const std::string &  optionName 
) const

Get the value of the option.

Parameters
[out]value: value of the option
optionName: name of option to get the option
Returns
true on success, false otherwise

Definition at line 18 of file OptionMode_impl.h.

18  {
19  Option option;
20  if(!getOption(option, optionName)){return false;}
21  if(!option.isParsed() && option.isRequired()){
22  return false;
23  }
24  OptionValue & optionValue = option.getValue();
25  optionValue.getValue(value, option.isParsed());
26  return true;
27 }

References getOption(), OptionValue::getValue(), Option::getValue(), Option::isParsed(), and Option::isRequired().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVecOption() [1/2]

VecOption& OptionMode::getVecOption ( )

◆ getVecOption() [2/2]

VecOption & OptionMode::getVecOption ( ) const

Get the vector of options of the OptionMode.

Returns
vector of options of the OptionMode

Definition at line 156 of file OptionMode.cpp.

156 {return p_vecOption;}

References p_vecOption.

◆ initialisationOptionMode()

void OptionMode::initialisationOptionMode ( )
private

Initialisation function of the class OptionMode.

Definition at line 246 of file OptionMode.cpp.

246  {
247  p_isCurrentlyParsed = false;
248  p_isParsed = false;
249  p_enableHelpOption = false;
250 }

References p_enableHelpOption, p_isCurrentlyParsed, and p_isParsed.

Referenced by OptionMode().

+ Here is the caller graph for this function:

◆ isCurrentlyParsed()

bool OptionMode::isCurrentlyParsed ( ) const

Say if the OptionMode is currently parsed (but maybe not totally)

Returns
true if the OptionMode is currently parsed (but maybe not totally), false otherwise

Definition at line 180 of file OptionMode.cpp.

180  {
181  return p_isCurrentlyParsed;
182 }

References p_isCurrentlyParsed.

◆ isOptionExist()

bool OptionMode::isOptionExist ( const std::string &  optionName) const

Say if the given option has been passed to the program.

Parameters
[out]optionName: name of the option to be checked
Returns
true if hte option has been passed to the program, false if not

Definition at line 195 of file OptionMode.cpp.

195  {
196  VecOption::const_iterator it(p_vecOption.begin());
197  while(it != p_vecOption.end()){
198  if(it->getLongName() == optionName || it->getShortName() == optionName){
199  return it->isParsed();
200  }
201  ++it;
202  }
203  return false;
204 }

References p_vecOption.

Referenced by main().

+ Here is the caller graph for this function:

◆ isParsed()

bool OptionMode::isParsed ( ) const

Say if the OptionMode contains option which are parsed.

Returns
true if the OptionMode contains option which are parsed, false otherwise

Definition at line 187 of file OptionMode.cpp.

187  {
188  return p_isParsed;
189 }

References p_isParsed.

Referenced by main().

+ Here is the caller graph for this function:

◆ iterGetPossibleOption()

void OptionMode::iterGetPossibleOption ( std::string &  possibleOption,
const std::string &  cursorOption 
) const
private

Iterates over the possible options of the current mode.

Parameters
[out]possibleOption: possible options for the bash completion
cursorOption: option of the cursor which is currently completed

Definition at line 273 of file OptionMode.cpp.

273  {
274  for(VecOption::const_iterator it(p_vecOption.begin()); it != p_vecOption.end(); ++it){
275  it->getPossibleOption(possibleOption, cursorOption);
276  }
277 }

References p_vecOption.

Referenced by getPossibleOption().

+ Here is the caller graph for this function:

◆ operator=()

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

Definition of equal operator of OptionMode.

Parameters
other: class to copy
Returns
copied class

Definition at line 37 of file OptionMode.cpp.

37  {
38  copyOptionMode(other);
39  return *this;
40 }

References copyOptionMode().

+ Here is the call graph for this function:

◆ parseOption() [1/2]

bool OptionMode::parseOption ( ArgParser parser)

Parse the options in the current OptionMode.

Parameters
[out]parser: parser of option to be used
Returns
true on success, false otherwise This function, is called, knowing, the current OptionMode has to be parsed

Definition at line 47 of file OptionMode.cpp.

47  {
48  if(parser.isEndOfOption()){return true;}
49 
50  p_isParsed = true;
51  p_isCurrentlyParsed = true;
52  bool isSearch(true);
53  VecOption::iterator it(p_vecOption.begin());
54  while(isSearch && it != p_vecOption.end() && !parser.isEndOfOption()){
56  if(parser.getCurrentOption() == "--help" || parser.getCurrentOption() == "-h"){
57  print();
58  exit(0);
59  }
60  }
61  if(p_programVersion != ""){
62  if(parser.getCurrentOption() == "--version" || parser.getCurrentOption() == "-v"){
63  std::cout << "Program version : " << p_programVersion << std::endl;
64  exit(0);
65  }
66  }
67  isSearch = !it->parseOption(parser);
68  ++it;
69  }
70  p_isParsed |= !isSearch;
71  return !isSearch;
72 }

References p_enableHelpOption, p_isCurrentlyParsed, p_isParsed, p_programVersion, p_vecOption, createReleaseCurl::parser, and print().

Referenced by OptionParser::parseArgumentNormalUse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseOption() [2/2]

bool OptionMode::parseOption ( ArgParser parser,
Option *&  partialOption 
)

Parse the options in the current OptionMode.

Parameters
[out]parser: parser of option to be used
[out]partialOption: pointer to an option partially parsed
Returns
true on success, false otherwise

Definition at line 79 of file OptionMode.cpp.

79  {
80  if(parser.isEndOfOption()){return true;}
81  if(p_name != ""){ //If the mode has no name, it is the default mode
82  if(p_name != parser.getCurrentOption()){return false;}
83  p_isParsed = true;
84  parser.getNextOption();
85  }
86  p_isCurrentlyParsed = true;
87  partialOption = NULL;
88  bool isSearch(true);
89  VecOption::iterator it(p_vecOption.begin());
90  while(isSearch && it != p_vecOption.end() && !parser.isEndOfOption()){
91  try{
92  isSearch = !it->parseOption(parser);
93  }catch(const std::runtime_error & e){
94  partialOption = &(*it);
95  isSearch = false;
96  }
97  ++it;
98  }
99  p_isParsed |= !isSearch;
100  return !isSearch;
101 }

References p_isCurrentlyParsed, p_isParsed, p_name, p_vecOption, and createReleaseCurl::parser.

◆ print()

void OptionMode::print ( ) const

Print the option of the mode.

Definition at line 104 of file OptionMode.cpp.

104  {
105  std::string indentation("\t");
106  if(p_name != ""){
107  cout << "\tMode '" << p_name << "' :" << endl;
108  indentation += "\t";
109  }
110  for(VecOption::const_iterator it(p_vecOption.begin()); it != p_vecOption.end(); ++it){
111  it->print(indentation);
112  }
113 }

References p_name, and p_vecOption.

Referenced by main(), parseOption(), and printConstParser().

+ Here is the caller graph for this function:

◆ setEnableHelpOption()

void OptionMode::setEnableHelpOption ( bool  b)

Set the attribtue which enables help option.

Parameters
b: true to enable help option, false otherwise

Definition at line 136 of file OptionMode.cpp.

136 {p_enableHelpOption = b;}

References p_enableHelpOption.

Referenced by OptionParser::addMode().

+ Here is the caller graph for this function:

◆ setName()

void OptionMode::setName ( const std::string &  name)

Set the name of the OptionMode.

Parameters
name: name of the OptionMode

Definition at line 118 of file OptionMode.cpp.

118 {p_name = name;}

References p_name.

◆ setProgramVersion()

void OptionMode::setProgramVersion ( const std::string &  programVersion)

Set the program version.

Parameters
programVersion: version of the program

Definition at line 141 of file OptionMode.cpp.

141 {p_programVersion = programVersion;}

References p_programVersion.

Referenced by OptionParser::addMode().

+ Here is the caller graph for this function:

◆ setVecOption()

void OptionMode::setVecOption ( const VecOption vecOption)

Set the vector of options of the OptionMode.

Parameters
vecOption: vector of options of the OptionMode

Definition at line 123 of file OptionMode.cpp.

123 {p_vecOption = vecOption;}

References p_vecOption.

Member Data Documentation

◆ p_enableHelpOption

bool OptionMode::p_enableHelpOption
private

True to enable automatically the printing of the help option when the program is called with –help or -h.

Definition at line 71 of file OptionMode.h.

Referenced by copyOptionMode(), initialisationOptionMode(), parseOption(), and setEnableHelpOption().

◆ p_isCurrentlyParsed

bool OptionMode::p_isCurrentlyParsed
private

True if the OptionMode is currently parsed but not totally.

Definition at line 67 of file OptionMode.h.

Referenced by copyOptionMode(), getPossibleOption(), initialisationOptionMode(), isCurrentlyParsed(), and parseOption().

◆ p_isParsed

bool OptionMode::p_isParsed
private

Say if the mode contains options which are parsed.

Definition at line 69 of file OptionMode.h.

Referenced by checkArgument(), copyOptionMode(), initialisationOptionMode(), isParsed(), and parseOption().

◆ p_name

std::string OptionMode::p_name
private

name of the OptionMode

Definition at line 63 of file OptionMode.h.

Referenced by copyOptionMode(), getName(), getPossibleMode(), getPossibleOption(), parseOption(), print(), and setName().

◆ p_programVersion

std::string OptionMode::p_programVersion
private

Program version to be printed on –version or -v option.

Definition at line 73 of file OptionMode.h.

Referenced by copyOptionMode(), parseOption(), and setProgramVersion().

◆ p_vecOption

VecOption OptionMode::p_vecOption
private

The documentation for this class was generated from the following files:
Option::isRequired
bool isRequired() const
Get if the option is required.
Definition: Option.cpp:212
OptionMode::p_isCurrentlyParsed
bool p_isCurrentlyParsed
True if the OptionMode is currently parsed but not totally.
Definition: OptionMode.h:67
OptionMode::iterGetPossibleOption
void iterGetPossibleOption(std::string &possibleOption, const std::string &cursorOption) const
Iterates over the possible options of the current mode.
Definition: OptionMode.cpp:273
OptionMode::p_name
std::string p_name
name of the OptionMode
Definition: OptionMode.h:63
OptionMode::p_isParsed
bool p_isParsed
Say if the mode contains options which are parsed.
Definition: OptionMode.h:69
Option::isParsed
bool isParsed() const
Say if the Option has been parsed or not.
Definition: Option.cpp:242
Option::getValue
const OptionValue & getValue() const
Get the value of the Option.
Definition: Option.cpp:202
OptionMode::p_vecOption
VecOption p_vecOption
Vector of all the options of the OptionMode.
Definition: OptionMode.h:65
OptionMode::getOption
bool getOption(Option &option, const std::string &optionName) const
Get the option with its name.
Definition: OptionMode.cpp:257
OptionMode::print
void print() const
Print the option of the mode.
Definition: OptionMode.cpp:104
isSameBegining
bool isSameBegining(const std::string &str, const std::string &beginig)
Check if two string start the same way.
Definition: string_function.cpp:531
createReleaseCurl.parser
parser
Definition: createReleaseCurl.py:123
OptionMode::initialisationOptionMode
void initialisationOptionMode()
Initialisation function of the class OptionMode.
Definition: OptionMode.cpp:246
Option
Definition: Option.h:13
OptionMode::p_programVersion
std::string p_programVersion
Program version to be printed on –version or -v option.
Definition: OptionMode.h:73
OptionMode::p_enableHelpOption
bool p_enableHelpOption
True to enable automatically the printing of the help option when the program is called with –help or...
Definition: OptionMode.h:71
OptionValue::getValue
const VecValue & getValue() const
Get the vector of values.
Definition: OptionValue.cpp:131
OptionValue
Describe the value of an option passed to a program.
Definition: OptionValue.h:20
OptionMode::copyOptionMode
void copyOptionMode(const OptionMode &other)
Copy function of OptionMode.
Definition: OptionMode.cpp:236