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

Describe the value of an option passed to a program. More...

#include <OptionValue.h>

Public Member Functions

void addValue (const PString &value)
 Add value of the OptionValue. More...
 
void bashCompletionValue (PString &strBashCompletion, const PString &cursorOption) const
 Print the possible value to the bash completion. More...
 
PVecStringgetDefaultValue ()
 Get the default value of the OptionValue. More...
 
const PVecStringgetDefaultValue () const
 Get the default value of the OptionValue. More...
 
PVecStringgetPossibleValue ()
 Get the possible values of the OptionValue. More...
 
const PVecStringgetPossibleValue () const
 Get the possible values of the OptionValue. More...
 
OptionType::OptionTypegetType ()
 Get the type of the OptionValue. More...
 
OptionType::OptionType getType () const
 Get the type of the OptionValue. More...
 
PVecStringgetValue ()
 Get the vector of values. More...
 
const PVecStringgetValue () const
 Get the vector of values. More...
 
template<typename T >
void getValue (std::vector< T > &vecValue, bool isParsed) const
 Get the value of the option. More...
 
template<typename T >
void getValue (T &value, bool isParsed) const
 Get the value of the option. More...
 
OptionValueoperator= (const OptionValue &other)
 Definition of equal operator of OptionValue. More...
 
 OptionValue (const OptionValue &other)
 Copy constructor of OptionValue. More...
 
 OptionValue (const PString &value, OptionType::OptionType type, const PVecString &vecDefaultValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const PString &value, OptionType::OptionType type, const PVecString &vecDefaultValue, const PVecString &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const PString &value, OptionType::OptionType type=OptionType::STRING)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const PVecString &vecValue, OptionType::OptionType type, const PVecString &vecDefaultValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const PVecString &vecValue, OptionType::OptionType type, const PVecString &vecDefaultValue, const PVecString &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const PVecString &vecValue, OptionType::OptionType type=OptionType::STRING)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (OptionType::OptionType type=OptionType::STRING)
 Default constructeur of OptionValue. More...
 
template<typename T >
void setDefaultValue (const std::vector< T > &value)
 Set the value in the OptionValue. More...
 
template<typename T >
void setDefaultValue (const T &value)
 Set the value in the OptionValue. More...
 
void setType (OptionType::OptionType type)
 Set the type of the OptionValue. More...
 
void setValue (const PString &value)
 Set the value of the OptionValue. More...
 
void setValue (const PVecString &value)
 Set the value of the OptionValue. More...
 
void setVecPossibleValue (const PVecString &vecPossibleValue)
 Set the vector of possible values. More...
 
virtual ~OptionValue ()
 Destructeur of OptionValue. More...
 

Protected Member Functions

void copyOptionValue (const OptionValue &other)
 Copy function of OptionValue. More...
 

Private Member Functions

template<typename T >
void checkTypeFromTemplate () const
 Check the type from the template. More...
 
void initialisationOptionValue (const PVecString &vecValue, OptionType::OptionType type, const PVecString &vecDefaultValue, const PVecString &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 

Private Attributes

OptionType::OptionType p_type
 Type of the OptionValue. More...
 
PVecString p_vecDefaultValue
 Default value of the OptionValue. More...
 
PVecString p_vecPossibleValue
 Vector of the possible value for the OptionValue. More...
 
PVecString p_vecValue
 Vector of the values of the OptionValue. More...
 

Detailed Description

Describe the value of an option passed to a program.

Definition at line 16 of file OptionValue.h.

Constructor & Destructor Documentation

◆ OptionValue() [1/8]

OptionValue::OptionValue ( OptionType::OptionType  type = OptionType::STRING)

Default constructeur of OptionValue.

Parameters
type: type of the OptionValue

Definition at line 14 of file OptionValue.cpp.

14  {
15  PVecString vecValue, vecDefaultValue, vecPossibleValue;
16  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
17 }
std::vector< PString > PVecString
Definition: PString.h:96
void initialisationOptionValue(const PVecString &vecValue, OptionType::OptionType type, const PVecString &vecDefaultValue, const PVecString &vecPossibleValue)
Initialisation function of the class OptionValue.

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [2/8]

OptionValue::OptionValue ( const PString value,
OptionType::OptionType  type = OptionType::STRING 
)

Initialisation function of the class OptionValue.

Parameters
value: value of the OptionValue
type: type of the OptionValue

Definition at line 23 of file OptionValue.cpp.

23  {
24  PVecString vecValue, vecDefaultValue, vecPossibleValue;
25  vecValue.push_back(value);
26  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
27 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [3/8]

OptionValue::OptionValue ( const PVecString vecValue,
OptionType::OptionType  type = OptionType::STRING 
)

Initialisation function of the class OptionValue.

Parameters
vecValue: vector of values of the OptionValue
type: type of the OptionValue

Definition at line 33 of file OptionValue.cpp.

33  {
34  PVecString vecDefaultValue, vecPossibleValue;
35  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
36 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [4/8]

OptionValue::OptionValue ( const PString value,
OptionType::OptionType  type,
const PVecString vecDefaultValue 
)

Initialisation function of the class OptionValue.

Parameters
value: value of the OptionValue
type: type of the OptionValue
vecDefaultValue: default value of the OptionValue

Definition at line 43 of file OptionValue.cpp.

43  {
44  PVecString vecValue, vecPossibleValue;
45  vecValue.push_back(value);
46  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
47 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [5/8]

OptionValue::OptionValue ( const PVecString vecValue,
OptionType::OptionType  type,
const PVecString vecDefaultValue 
)

Initialisation function of the class OptionValue.

Parameters
vecValue: vector of values of the OptionValue
type: type of the OptionValue
vecDefaultValue: default value of the OptionValue

Definition at line 54 of file OptionValue.cpp.

54  {
55  PVecString vecPossibleValue;
56  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
57 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [6/8]

OptionValue::OptionValue ( const PString value,
OptionType::OptionType  type,
const PVecString vecDefaultValue,
const PVecString vecPossibleValue 
)

Initialisation function of the class OptionValue.

Parameters
value: value of the OptionValue
type: type of the OptionValue
vecDefaultValue: default value of the OptionValue
vecPossibleValue: vector of the possible values for the OptionValue

Definition at line 65 of file OptionValue.cpp.

65  {
66  PVecString vecValue;
67  vecValue.push_back(value);
68  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
69 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [7/8]

OptionValue::OptionValue ( const PVecString vecValue,
OptionType::OptionType  type,
const PVecString vecDefaultValue,
const PVecString vecPossibleValue 
)

Initialisation function of the class OptionValue.

Parameters
vecValue: vector of values of the OptionValue
type: type of the OptionValue
vecDefaultValue: default value of the OptionValue
vecPossibleValue: vector of the possible values for the OptionValue

Definition at line 77 of file OptionValue.cpp.

77  {
78  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
79 }

References initialisationOptionValue().

+ Here is the call graph for this function:

◆ OptionValue() [8/8]

OptionValue::OptionValue ( const OptionValue other)

Copy constructor of OptionValue.

Parameters
other: class to copy

Definition at line 85 of file OptionValue.cpp.

85  {
86  copyOptionValue(other);
87 }
void copyOptionValue(const OptionValue &other)
Copy function of OptionValue.

References copyOptionValue().

+ Here is the call graph for this function:

◆ ~OptionValue()

OptionValue::~OptionValue ( )
virtual

Destructeur of OptionValue.

Definition at line 90 of file OptionValue.cpp.

90  {
91 
92 }

Member Function Documentation

◆ addValue()

void OptionValue::addValue ( const PString value)

Add value of the OptionValue.

Parameters
value: value to be added

Definition at line 127 of file OptionValue.cpp.

127 {p_vecValue.push_back(value);}
PVecString p_vecValue
Vector of the values of the OptionValue.
Definition: OptionValue.h:73

References p_vecValue.

Referenced by Option::parsePartOption().

+ Here is the caller graph for this function:

◆ bashCompletionValue()

void OptionValue::bashCompletionValue ( PString strBashCompletion,
const PString cursorOption 
) const

Print the possible value to the bash completion.

Parameters
[out]strBashCompletion: string of all possible choices
cursorOption: option of the cursor which is currently completed

Definition at line 178 of file OptionValue.cpp.

178  {
179 // std::cerr << "OptionValue::bashCompletionValue : cursorOption = '"<<cursorOption<<"'" << std::endl;
180  if(p_vecPossibleValue.size() != 0lu){ //If there is some possible values, we print them
181  strBashCompletion += value_completion(cursorOption, p_vecPossibleValue);
182  }else{
183  //Now, we can complete by respect to the expected type
185  strBashCompletion += path_completion_all(cursorOption);
186  }else if(p_type == OptionType::DIRECTORY){
187  strBashCompletion += path_completion_dirOnly(cursorOption);
188  }else{
189  strBashCompletion += convertOptionTypeToString(p_type);
190  }
191  }
192 }
PString convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into PString.
Definition: OptionType.cpp:69
PVecString p_vecPossibleValue
Vector of the possible value for the OptionValue.
Definition: OptionValue.h:77
OptionType::OptionType p_type
Type of the OptionValue.
Definition: OptionValue.h:71
PPath path_completion_dirOnly(const PPath &basePath)
Return all directories only which match the basePath.
PPath path_completion_all(const PPath &basePath)
Return all path/files which match the basePath.
PString value_completion(const PString &baseValue, const PVecString &vecPossibleValue)
Complete the given value.

References convertOptionTypeToString(), OptionType::DIRECTORY, OptionType::FILE_OR_DIR, OptionType::FILENAME, p_type, p_vecPossibleValue, path_completion_all(), path_completion_dirOnly(), and value_completion().

Referenced by Option::getPossibleValue().

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

◆ checkTypeFromTemplate()

template<typename T >
void OptionValue::checkTypeFromTemplate
private

Check the type from the template.

Throw exception if there is an incompatibility

Definition at line 76 of file OptionValue_impl.h.

76  {
77  OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
78  if(!isOptionTypeCompatible(p_type, optionTypeFromDefault)){
79  std::stringstream strError;
80  strError << "OptionValue::checkTypeFromTemplate : Incompatible types from parameters (" << convertOptionTypeToString(p_type) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
81  throw std::runtime_error(strError.str());
82  }
83 }
bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType)
Say if two types are compatible.
Definition: OptionType.cpp:54

References convertOptionTypeToString(), isOptionTypeCompatible(), and p_type.

+ Here is the call graph for this function:

◆ copyOptionValue()

void OptionValue::copyOptionValue ( const OptionValue other)
protected

Copy function of OptionValue.

Parameters
other: class to copy

Definition at line 197 of file OptionValue.cpp.

197  {
198  p_vecValue = other.p_vecValue;
199  p_type = other.p_type;
202 }
PVecString p_vecDefaultValue
Default value of the OptionValue.
Definition: OptionValue.h:75

References p_type, p_vecDefaultValue, p_vecPossibleValue, and p_vecValue.

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

+ Here is the caller graph for this function:

◆ getDefaultValue() [1/2]

PVecString & OptionValue::getDefaultValue ( )

Get the default value of the OptionValue.

Returns
default value of the OptionValue

Definition at line 162 of file OptionValue.cpp.

162 {return p_vecDefaultValue;}

References p_vecDefaultValue.

◆ getDefaultValue() [2/2]

const PVecString & OptionValue::getDefaultValue ( ) const

Get the default value of the OptionValue.

Returns
default value of the OptionValue

Definition at line 157 of file OptionValue.cpp.

157 {return p_vecDefaultValue;}

References p_vecDefaultValue.

Referenced by Option::print(), and testOptionValue().

+ Here is the caller graph for this function:

◆ getPossibleValue() [1/2]

PVecString & OptionValue::getPossibleValue ( )

Get the possible values of the OptionValue.

Returns
possible values of the OptionValue

Definition at line 172 of file OptionValue.cpp.

172 {return p_vecPossibleValue;}

References p_vecPossibleValue.

◆ getPossibleValue() [2/2]

const PVecString & OptionValue::getPossibleValue ( ) const

Get the possible values of the OptionValue.

Returns
possible values of the OptionValue

Definition at line 167 of file OptionValue.cpp.

167 {return p_vecPossibleValue;}

References p_vecPossibleValue.

Referenced by Option::print(), and testOptionValue().

+ Here is the caller graph for this function:

◆ getType() [1/2]

OptionType::OptionType & OptionValue::getType ( )

Get the type of the OptionValue.

Returns
type of the OptionValue

Definition at line 152 of file OptionValue.cpp.

152 {return p_type;}

References p_type.

◆ getType() [2/2]

OptionType::OptionType OptionValue::getType ( ) const

Get the type of the OptionValue.

Returns
type of the OptionValue

Definition at line 147 of file OptionValue.cpp.

147 {return p_type;}

References p_type.

Referenced by Option::checkArgument(), Option::parsePartOption(), Option::print(), and testOptionValue().

+ Here is the caller graph for this function:

◆ getValue() [1/4]

PVecString & OptionValue::getValue ( )

Get the vector of values.

Returns
vector of values

Definition at line 142 of file OptionValue.cpp.

142 {return p_vecValue;}

References p_vecValue.

◆ getValue() [2/4]

const PVecString & OptionValue::getValue ( ) const

Get the vector of values.

Returns
vector of values

Definition at line 137 of file OptionValue.cpp.

137 {return p_vecValue;}

References p_vecValue.

Referenced by OptionMode::getValue(), printValueOfOpt(), printValueOfOptConst(), and testOptionValue().

+ Here is the caller graph for this function:

◆ getValue() [3/4]

template<typename T >
void OptionValue::getValue ( std::vector< T > &  vecValue,
bool  isParsed 
) const

Get the value of the option.

Parameters
[out]vecValue: value of the option
isParsed: true if the option is parsed, false if not

Definition at line 59 of file OptionValue_impl.h.

59  {
60  checkTypeFromTemplate<T>();
61  if(isParsed){
62  for(PVecString::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
63  vecValue.push_back(stringToValue<T>(*it));
64  }
65  }else{
66  for(PVecString::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
67  vecValue.push_back(stringToValue<T>(*it));
68  }
69  }
70 }

References p_vecDefaultValue, and p_vecValue.

◆ getValue() [4/4]

template<typename T >
void OptionValue::getValue ( T &  value,
bool  isParsed 
) const

Get the value of the option.

Parameters
[out]value: value of the option
isParsed: true if the option is parsed, false if not

Definition at line 38 of file OptionValue_impl.h.

38  {
39  checkTypeFromTemplate<T>();
40  if(isParsed){
41  if(p_vecValue.size() > 1lu){
42  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
43  }
44  value = stringToValue<T>(p_vecValue.front());
45  }else{
46  if(p_vecDefaultValue.size() == 1lu){
47  value = stringToValue<T>(p_vecDefaultValue.front());
48  }else{
49  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
50  }
51  }
52 }

References p_vecDefaultValue, and p_vecValue.

◆ initialisationOptionValue()

void OptionValue::initialisationOptionValue ( const PVecString vecValue,
OptionType::OptionType  type,
const PVecString vecDefaultValue,
const PVecString vecPossibleValue 
)
private

Initialisation function of the class OptionValue.

Parameters
vecValue: vector of values of the OptionValue
type: type of the OptionValue
vecDefaultValue: default value of the OptionValue
vecPossibleValue: vector of the possible values for the OptionValue

Definition at line 210 of file OptionValue.cpp.

210  {
211  p_vecValue = vecValue;
212  p_type = type;
213  p_vecDefaultValue = vecDefaultValue;
214  p_vecPossibleValue = vecPossibleValue;
215 }

References p_type, p_vecDefaultValue, p_vecPossibleValue, and p_vecValue.

Referenced by OptionValue().

+ Here is the caller graph for this function:

◆ operator=()

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

Definition of equal operator of OptionValue.

Parameters
other: class to copy
Returns
copied class

Definition at line 98 of file OptionValue.cpp.

98  {
99  copyOptionValue(other);
100  return *this;
101 }

References copyOptionValue().

+ Here is the call graph for this function:

◆ setDefaultValue() [1/2]

template<typename T >
void OptionValue::setDefaultValue ( const std::vector< T > &  value)

Set the value in the OptionValue.

Parameters
value: value of the OptionValue

Definition at line 29 of file OptionValue_impl.h.

29  {
30  p_vecDefaultValue = value;
31 }

References p_vecDefaultValue.

◆ setDefaultValue() [2/2]

template<typename T >
void OptionValue::setDefaultValue ( const T &  value)

Set the value in the OptionValue.

Parameters
value: value of the OptionValue

Definition at line 17 of file OptionValue_impl.h.

17  {
18  PString valueBinStr;
19  valueBinStr.fromValue(value);
20  PVecString vecValue;
21  vecValue.push_back(valueBinStr);
22  p_vecDefaultValue = vecValue;
23 }
Extends the std::string.
Definition: PString.h:16
PString & fromValue(const T &other)
Convert a value to a PString.
Definition: PString_impl.h:36

References PString::fromValue(), and p_vecDefaultValue.

Referenced by OptionParser::addOption().

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

◆ setType()

void OptionValue::setType ( OptionType::OptionType  type)

Set the type of the OptionValue.

Parameters
type: type of the OptionValue

Definition at line 106 of file OptionValue.cpp.

106  {
107  p_type = type;
108 }

References p_type.

Referenced by OptionParser::addOption().

+ Here is the caller graph for this function:

◆ setValue() [1/2]

void OptionValue::setValue ( const PString value)

Set the value of the OptionValue.

Parameters
value: value to be set

Definition at line 113 of file OptionValue.cpp.

113  {
114  PVecString vecValue;
115  vecValue.push_back(value);
116  setValue(vecValue);
117 }
void setValue(const PString &value)
Set the value of the OptionValue.

Referenced by testOptionValue().

+ Here is the caller graph for this function:

◆ setValue() [2/2]

void OptionValue::setValue ( const PVecString value)

Set the value of the OptionValue.

Parameters
value: value to be set

Definition at line 122 of file OptionValue.cpp.

122 {p_vecValue = value;}

References p_vecValue.

◆ setVecPossibleValue()

void OptionValue::setVecPossibleValue ( const PVecString vecPossibleValue)

Set the vector of possible values.

Parameters
vecPossibleValue: vector of possible values

Definition at line 132 of file OptionValue.cpp.

132 {p_vecPossibleValue = vecPossibleValue;}

References p_vecPossibleValue.

Referenced by OptionParser::addOption().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_type

OptionType::OptionType OptionValue::p_type
private

◆ p_vecDefaultValue

PVecString OptionValue::p_vecDefaultValue
private

Default value of the OptionValue.

Definition at line 75 of file OptionValue.h.

Referenced by copyOptionValue(), getDefaultValue(), getValue(), initialisationOptionValue(), and setDefaultValue().

◆ p_vecPossibleValue

PVecString OptionValue::p_vecPossibleValue
private

Vector of the possible value for the OptionValue.

Definition at line 77 of file OptionValue.h.

Referenced by bashCompletionValue(), copyOptionValue(), getPossibleValue(), initialisationOptionValue(), and setVecPossibleValue().

◆ p_vecValue

PVecString OptionValue::p_vecValue
private

Vector of the values of the OptionValue.

Definition at line 73 of file OptionValue.h.

Referenced by addValue(), copyOptionValue(), getValue(), initialisationOptionValue(), and setValue().


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