PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
OptionMode Class Reference

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

#include <OptionMode.h>

+ Collaboration diagram for OptionMode:

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...
 
const PStringgetExtraArgument () const
 Get Extra argument. More...
 
PStringgetName ()
 Get the name of the OptionMode. More...
 
const PStringgetName () const
 Get the name of the OptionMode. More...
 
void getPossibleMode (PString &possibleOption, const PString &cursorOption) const
 Get the possible mode. More...
 
void getPossibleOption (PString &possibleOption, const PString &cursorOption) const
 Get the possible options for the bash completion. More...
 
template<typename T >
bool getValue (T &value, const PString &optionName) const
 Get the value of the option. More...
 
VecOptiongetVecOption ()
 Get the vector of options of the OptionMode. More...
 
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 PString &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 PString &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 PString &name)
 Set the name of the OptionMode. More...
 
void setProgramVersion (const PString &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 PString &optionName) const
 Get the option with its name. More...
 
void initialisationOptionMode ()
 Initialisation function of the class OptionMode. More...
 
void iterGetPossibleOption (PString &possibleOption, const PString &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...
 
PString p_extraArgument
 Extra argument passed to the OptionMode. 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...
 
PString p_name
 name of the OptionMode More...
 
PString 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 PString name = "")

Default constructeur of OptionMode.

Parameters
name: name of the mode

Definition at line 12 of file OptionMode.cpp.

13  :p_name(name)
14 {
16 }
void initialisationOptionMode()
Initialisation function of the class OptionMode.
Definition: OptionMode.cpp:262
PString p_name
name of the OptionMode
Definition: OptionMode.h:60

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 21 of file OptionMode.cpp.

21  {
22  copyOptionMode(other);
23 }
void copyOptionMode(const OptionMode &other)
Copy function of OptionMode.
Definition: OptionMode.cpp:251

References copyOptionMode().

+ Here is the call graph for this function:

◆ ~OptionMode()

OptionMode::~OptionMode ( )
virtual

Destructeur of OptionMode.

Definition at line 26 of file OptionMode.cpp.

26  {
27 
28 }

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 136 of file OptionMode.cpp.

136 {p_vecOption.push_back(option);}
VecOption p_vecOption
Vector of all the options of the OptionMode.
Definition: OptionMode.h:62

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 174 of file OptionMode.cpp.

174  {
175  if(!p_isParsed){return true;}
176  bool isArgOk(true);
177  VecOption::const_iterator it(p_vecOption.begin());
178  while(it != p_vecOption.end() && isArgOk){
179  isArgOk = it->checkArgument();
180  ++it;
181  }
182  return isArgOk;
183 }
bool p_isParsed
Say if the mode contains options which are parsed.
Definition: OptionMode.h:66

References p_isParsed, and p_vecOption.

◆ clearOption()

void OptionMode::clearOption ( )

Remove all the options of the OptionMode.

Definition at line 139 of file OptionMode.cpp.

139 {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 251 of file OptionMode.cpp.

251  {
252  p_name = other.p_name;
253  p_vecOption = other.p_vecOption;
255  p_isParsed = other.p_isParsed;
259 }
bool p_isCurrentlyParsed
True if the OptionMode is currently parsed but not totally.
Definition: OptionMode.h:64
PString p_extraArgument
Extra argument passed to the OptionMode.
Definition: OptionMode.h:72
bool p_enableHelpOption
True to enable automatically the printing of the help option when the program is called with –help or...
Definition: OptionMode.h:68
PString p_programVersion
Program version to be printed on –version or -v option.
Definition: OptionMode.h:70

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

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

+ Here is the caller graph for this function:

◆ getExtraArgument()

const PString & OptionMode::getExtraArgument ( ) const

Get Extra argument.

Returns
get the extra arguments of the OptionMode

Definition at line 202 of file OptionMode.cpp.

202  {
203  return p_extraArgument;
204 }

References p_extraArgument.

◆ getName() [1/2]

PString & OptionMode::getName ( )

Get the name of the OptionMode.

Returns
name of the OptionMode

Definition at line 159 of file OptionMode.cpp.

159 {return p_name;}

References p_name.

◆ getName() [2/2]

const PString & OptionMode::getName ( ) const

Get the name of the OptionMode.

Returns
name of the OptionMode

Definition at line 154 of file OptionMode.cpp.

154 {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 PString 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 273 of file OptionMode.cpp.

273  {
274  VecOption::const_iterator it(p_vecOption.begin());
275  while(it != p_vecOption.end()){
276  if(it->getLongName() == optionName || it->getShortName() == optionName){
277  option = *it;
278  return true;
279  }
280  ++it;
281  }
282  return false;
283 }

References p_vecOption.

Referenced by getValue().

+ Here is the caller graph for this function:

◆ getPossibleMode()

void OptionMode::getPossibleMode ( PString possibleOption,
const PString 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 240 of file OptionMode.cpp.

240  {
241  if(p_name != ""){
242  if(p_name.isSameBegining(cursorOption)){
243  possibleOption += p_name + " ";
244  }
245  }
246 }
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
Definition: PString.cpp:306

References PString::isSameBegining(), and p_name.

+ Here is the call graph for this function:

◆ getPossibleOption()

void OptionMode::getPossibleOption ( PString possibleOption,
const PString 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 225 of file OptionMode.cpp.

225  {
226  if(p_name != ""){
227  if(!p_isCurrentlyParsed){
228  if(p_name.isSameBegining(cursorOption)){
229  possibleOption += p_name + " ";
230  }
231  }
232  }
233  iterGetPossibleOption(possibleOption, cursorOption);
234 }
void iterGetPossibleOption(PString &possibleOption, const PString &cursorOption) const
Iterates over the possible options of the current mode.
Definition: OptionMode.cpp:289

References PString::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 PString 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 }
bool getOption(Option &option, const PString &optionName) const
Get the option with its name.
Definition: OptionMode.cpp:273
Describe the value of an option passed to a program.
Definition: OptionValue.h:16
const PVecString & getValue() const
Get the vector of values.
Describes an option passed to a program.
Definition: Option.h:14
const OptionValue & getValue() const
Get the value of the Option.
Definition: Option.cpp:209
bool isParsed() const
Say if the Option has been parsed or not.
Definition: Option.cpp:249
bool isRequired() const
Get if the option is required.
Definition: Option.cpp:219

References getOption(), Option::getValue(), OptionValue::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 ( )

Get the vector of options of the OptionMode.

Returns
vector of options of the OptionMode

Definition at line 169 of file OptionMode.cpp.

169 {return p_vecOption;}

References p_vecOption.

◆ getVecOption() [2/2]

const VecOption & OptionMode::getVecOption ( ) const

Get the vector of options of the OptionMode.

Returns
vector of options of the OptionMode

Definition at line 164 of file OptionMode.cpp.

164 {return p_vecOption;}

References p_vecOption.

◆ initialisationOptionMode()

void OptionMode::initialisationOptionMode ( )
private

Initialisation function of the class OptionMode.

Definition at line 262 of file OptionMode.cpp.

262  {
263  p_isCurrentlyParsed = false;
264  p_isParsed = false;
265  p_enableHelpOption = false;
266 }

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 188 of file OptionMode.cpp.

188  {
189  return p_isCurrentlyParsed;
190 }

References p_isCurrentlyParsed.

◆ isOptionExist()

bool OptionMode::isOptionExist ( const PString 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 210 of file OptionMode.cpp.

210  {
211  VecOption::const_iterator it(p_vecOption.begin());
212  while(it != p_vecOption.end()){
213  if(it->getLongName() == optionName || it->getShortName() == optionName){
214  return it->isParsed();
215  }
216  ++it;
217  }
218  return false;
219 }

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 195 of file OptionMode.cpp.

195  {
196  return p_isParsed;
197 }

References p_isParsed.

Referenced by main().

+ Here is the caller graph for this function:

◆ iterGetPossibleOption()

void OptionMode::iterGetPossibleOption ( PString possibleOption,
const PString 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 289 of file OptionMode.cpp.

289  {
290  for(VecOption::const_iterator it(p_vecOption.begin()); it != p_vecOption.end(); ++it){
291  it->getPossibleOption(possibleOption, cursorOption);
292  }
293 }

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 34 of file OptionMode.cpp.

34  {
35  copyOptionMode(other);
36  return *this;
37 }

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 44 of file OptionMode.cpp.

44  {
45  p_isParsed = true;
46  if(parser.isEndOfOption()){return true;}
47 
48  if(p_vecOption.size() == 0lu){ //If the OptionMode does not have Option we get the rest of passed extra arguments, they could be used later
50  return true;
51  }
52 
53  p_isCurrentlyParsed = true;
54  bool isSearch(true);
55  VecOption::iterator it(p_vecOption.begin());
56  while(isSearch && it != p_vecOption.end() && !parser.isEndOfOption()){
57  if(parser.getCurrentOption() == "--"){ //If we get a --, then the other arguments do not concern us
58  parser.getNextOption(); //Let's get the ext option, because we do not care about --
59  //Let's put them in the p_extraArgument
61  }
63  if(parser.getCurrentOption() == "--help" || parser.getCurrentOption() == "-h"){
64  print();
65  exit(0);
66  }
67  }
68  if(p_programVersion != ""){
69  if(parser.getCurrentOption() == "--version" || parser.getCurrentOption() == "-v"){
70  std::cout << "Program version : " << p_programVersion << std::endl;
71  exit(0);
72  }
73  }
74 
75  isSearch = !it->parseOption(parser);
76  ++it;
77  }
78  p_isParsed |= !isSearch;
79  return !isSearch;
80 }
const PString & getCurrentOption() const
Get the current option.
Definition: ArgParser.cpp:91
void getNextOption()
Move to the next option.
Definition: ArgParser.cpp:77
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 print() const
Print the option of the mode.
Definition: OptionMode.cpp:112

References ArgParser::getCurrentOption(), ArgParser::getNextOption(), ArgParser::getRemainingArgument(), ArgParser::isEndOfOption(), p_enableHelpOption, p_extraArgument, p_isCurrentlyParsed, p_isParsed, p_programVersion, p_vecOption, 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 87 of file OptionMode.cpp.

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

References ArgParser::getCurrentOption(), ArgParser::getNextOption(), ArgParser::isEndOfOption(), p_isCurrentlyParsed, p_isParsed, p_name, and p_vecOption.

+ Here is the call graph for this function:

◆ print()

void OptionMode::print ( ) const

Print the option of the mode.

Definition at line 112 of file OptionMode.cpp.

112  {
113  PString indentation("\t");
114  if(p_name != ""){
115  std::cout << "\tMode '" << p_name << "' :" << std::endl;
116  indentation += "\t";
117  }
118  for(VecOption::const_iterator it(p_vecOption.begin()); it != p_vecOption.end(); ++it){
119  it->print(indentation);
120  }
121 }
Extends the std::string.
Definition: PString.h:16

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 144 of file OptionMode.cpp.

144 {p_enableHelpOption = b;}

References p_enableHelpOption.

Referenced by OptionParser::addMode().

+ Here is the caller graph for this function:

◆ setName()

void OptionMode::setName ( const PString name)

Set the name of the OptionMode.

Parameters
name: name of the OptionMode

Definition at line 126 of file OptionMode.cpp.

126 {p_name = name;}

References p_name.

◆ setProgramVersion()

void OptionMode::setProgramVersion ( const PString programVersion)

Set the program version.

Parameters
programVersion: version of the program

Definition at line 149 of file OptionMode.cpp.

149 {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 131 of file OptionMode.cpp.

131 {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 68 of file OptionMode.h.

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

◆ p_extraArgument

PString OptionMode::p_extraArgument
private

Extra argument passed to the OptionMode.

Definition at line 72 of file OptionMode.h.

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

◆ p_isCurrentlyParsed

bool OptionMode::p_isCurrentlyParsed
private

True if the OptionMode is currently parsed but not totally.

Definition at line 64 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 66 of file OptionMode.h.

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

◆ p_name

PString OptionMode::p_name
private

name of the OptionMode

Definition at line 60 of file OptionMode.h.

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

◆ p_programVersion

PString OptionMode::p_programVersion
private

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

Definition at line 70 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: