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

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

#include <OptionValue.h>

Public Member Functions

void addValue (const std::string &value)
 Add value of the OptionValue. More...
 
void bashCompletionValue (std::string &strBashCompletion, const std::string &cursorOption) const
 Print the possible value to the bash completion. More...
 
VecValuegetDefaultValue ()
 
const VecValuegetDefaultValue () const
 Get the default value of the OptionValue. More...
 
VecValuegetPossibleValue ()
 
const VecValuegetPossibleValue () const
 Get the possible values of the OptionValue. More...
 
OptionType::OptionTypegetType ()
 
OptionType::OptionType getType () const
 Get the type of the OptionValue. More...
 
VecValuegetValue ()
 
const VecValuegetValue () const
 Get the vector of values. More...
 
template<typename T >
void getValue (std::list< T > &vecValue, bool isParsed) const
 Get the value of the option. 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 std::string &value, OptionType::OptionType type, const VecValue &vecDefaultValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const std::string &value, OptionType::OptionType type, const VecValue &vecDefaultValue, const VecValue &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const std::string &value, OptionType::OptionType type=OptionType::STRING)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const VecValue &vecValue, OptionType::OptionType type, const VecValue &vecDefaultValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const VecValue &vecValue, OptionType::OptionType type, const VecValue &vecDefaultValue, const VecValue &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 
 OptionValue (const VecValue &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::list< T > &value)
 Set the value in the 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 std::string &value)
 Set the value of the OptionValue. More...
 
void setValue (const VecValue &value)
 Set the value of the OptionValue. 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 VecValue &vecValue, OptionType::OptionType type, const VecValue &vecDefaultValue, const VecValue &vecPossibleValue)
 Initialisation function of the class OptionValue. More...
 

Private Attributes

OptionType::OptionType p_type
 Type of the OptionValue. More...
 
VecValue p_vecDefaultValue
 Default value of the OptionValue. More...
 
VecValue p_vecPossibleValue
 Vector of the possible value for the OptionValue. More...
 
VecValue 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 20 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 13 of file OptionValue.cpp.

13  {
14  VecValue vecValue, vecDefaultValue, vecPossibleValue;
15  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
16 }

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [2/8]

OptionValue::OptionValue ( const std::string &  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 22 of file OptionValue.cpp.

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

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [3/8]

OptionValue::OptionValue ( const VecValue 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 32 of file OptionValue.cpp.

32  {
33  VecValue vecDefaultValue, vecPossibleValue;
34  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
35 }

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [4/8]

OptionValue::OptionValue ( const std::string &  value,
OptionType::OptionType  type,
const VecValue 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 42 of file OptionValue.cpp.

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

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [5/8]

OptionValue::OptionValue ( const VecValue vecValue,
OptionType::OptionType  type,
const VecValue 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 53 of file OptionValue.cpp.

53  {
54  VecValue vecPossibleValue;
55  initialisationOptionValue(vecValue, type, vecDefaultValue, vecPossibleValue);
56 }

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [6/8]

OptionValue::OptionValue ( const std::string &  value,
OptionType::OptionType  type,
const VecValue vecDefaultValue,
const VecValue 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 64 of file OptionValue.cpp.

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

References initialisationOptionValue(), and createReleaseCurl::type.

+ Here is the call graph for this function:

◆ OptionValue() [7/8]

OptionValue::OptionValue ( const VecValue vecValue,
OptionType::OptionType  type,
const VecValue vecDefaultValue,
const VecValue 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 76 of file OptionValue.cpp.

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

References initialisationOptionValue(), and createReleaseCurl::type.

+ 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 84 of file OptionValue.cpp.

84  {
85  copyOptionValue(other);
86 }

References copyOptionValue().

+ Here is the call graph for this function:

◆ ~OptionValue()

OptionValue::~OptionValue ( )
virtual

Destructeur of OptionValue.

Definition at line 89 of file OptionValue.cpp.

89  {
90 
91 }

Member Function Documentation

◆ addValue()

void OptionValue::addValue ( const std::string &  value)

Add value of the OptionValue.

Parameters
value: value to be added

Definition at line 126 of file OptionValue.cpp.

126 {p_vecValue.push_back(value);}

References p_vecValue.

Referenced by Option::parsePartOption().

+ Here is the caller graph for this function:

◆ bashCompletionValue()

void OptionValue::bashCompletionValue ( std::string &  strBashCompletion,
const std::string &  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 172 of file OptionValue.cpp.

172  {
173 // std::cerr << "OptionValue::bashCompletionValue : cursorOption = '"<<cursorOption<<"'" << std::endl;
174  if(p_vecPossibleValue.size() != 0lu){ //If there is some possible values, we print them
175  for(VecValue::const_iterator it(p_vecPossibleValue.begin()); it != p_vecPossibleValue.end(); ++it){
176  strBashCompletion += " " + *it;
177  }
178  }else{
179  //Now, we can complete by respect to the expected type
181  strBashCompletion += path_completion_all(cursorOption);
182  }else if(p_type == OptionType::DIRECTORY){
183  strBashCompletion += path_completion_dirOnly(cursorOption);
184  }else{
185  strBashCompletion += convertOptionTypeToString(p_type);
186  }
187  }
188 }

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

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 105 of file OptionValue_impl.h.

105  {
106  OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
107  if(!isOptionTypeCompatible(p_type, optionTypeFromDefault)){
108  std::stringstream strError;
109  strError << "OptionValue::checkTypeFromTemplate : Incompatible types from parameters (" << convertOptionTypeToString(p_type) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
110  throw std::runtime_error(strError.str());
111  }
112 }

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 193 of file OptionValue.cpp.

193  {
194  p_vecValue = other.p_vecValue;
195  p_type = other.p_type;
198 }

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]

VecValue& OptionValue::getDefaultValue ( )

◆ getDefaultValue() [2/2]

VecValue & OptionValue::getDefaultValue ( ) const

Get the default value of the OptionValue.

Returns
default value of the OptionValue

Definition at line 151 of file OptionValue.cpp.

151 {return p_vecDefaultValue;}

References p_vecDefaultValue.

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

+ Here is the caller graph for this function:

◆ getPossibleValue() [1/2]

VecValue& OptionValue::getPossibleValue ( )

◆ getPossibleValue() [2/2]

VecValue & OptionValue::getPossibleValue ( ) const

Get the possible values of the OptionValue.

Returns
possible values of the OptionValue

Definition at line 161 of file OptionValue.cpp.

161 {return p_vecPossibleValue;}

References p_vecPossibleValue.

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

+ Here is the caller graph for this function:

◆ getType() [1/2]

OptionType::OptionType& OptionValue::getType ( )

◆ getType() [2/2]

OptionType::OptionType & OptionValue::getType ( ) const

Get the type of the OptionValue.

Returns
type of the OptionValue

Definition at line 141 of file OptionValue.cpp.

141 {return p_type;}

References p_type.

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

+ Here is the caller graph for this function:

◆ getValue() [1/5]

VecValue& OptionValue::getValue ( )

◆ getValue() [2/5]

VecValue & OptionValue::getValue ( ) const

Get the vector of values.

Returns
vector of values

Definition at line 131 of file OptionValue.cpp.

131 {return p_vecValue;}

References p_vecValue.

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

+ Here is the caller graph for this function:

◆ getValue() [3/5]

template<typename T >
void OptionValue::getValue ( std::list< 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 88 of file OptionValue_impl.h.

88  {
89  checkTypeFromTemplate<T>();
90  if(isParsed){
91  for(VecValue::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
92  vecValue.push_back(stringToValue<T>(*it));
93  }
94  }else{
95  for(VecValue::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
96  vecValue.push_back(stringToValue<T>(*it));
97  }
98  }
99 }

References p_vecDefaultValue, and p_vecValue.

◆ getValue() [4/5]

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 70 of file OptionValue_impl.h.

70  {
71  checkTypeFromTemplate<T>();
72  if(isParsed){
73  for(VecValue::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
74  vecValue.push_back(stringToValue<T>(*it));
75  }
76  }else{
77  for(VecValue::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
78  vecValue.push_back(stringToValue<T>(*it));
79  }
80  }
81 }

References p_vecDefaultValue, and p_vecValue.

◆ getValue() [5/5]

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 49 of file OptionValue_impl.h.

49  {
50  checkTypeFromTemplate<T>();
51  if(isParsed){
52  if(p_vecValue.size() > 1lu){
53  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
54  }
55  value = stringToValue<T>(p_vecValue.front());
56  }else{
57  if(p_vecDefaultValue.size() == 1lu){
58  value = stringToValue<T>(p_vecDefaultValue.front());
59  }else{
60  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
61  }
62  }
63 }

References p_vecDefaultValue, and p_vecValue.

◆ initialisationOptionValue()

void OptionValue::initialisationOptionValue ( const VecValue vecValue,
OptionType::OptionType  type,
const VecValue vecDefaultValue,
const VecValue 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 206 of file OptionValue.cpp.

206  {
207  p_vecValue = vecValue;
208  p_type = type;
209  p_vecDefaultValue = vecDefaultValue;
210  p_vecPossibleValue = vecPossibleValue;
211 }

References p_type, p_vecDefaultValue, p_vecPossibleValue, p_vecValue, and createReleaseCurl::type.

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 97 of file OptionValue.cpp.

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

References copyOptionValue().

+ Here is the call graph for this function:

◆ setDefaultValue() [1/3]

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

Set the value in the OptionValue.

Parameters
value: value of the OptionValue

Definition at line 36 of file OptionValue_impl.h.

36  {
37  VecValue vecValue;
38  for(typename std::list<T>::const_iterator it(value.begin()); it != value.end(); ++it){
39  vecValue.push_back(convertToString(*it));
40  }
41  p_vecDefaultValue = vecValue;
42 }

References convertToString(), and p_vecDefaultValue.

+ Here is the call graph for this function:

◆ setDefaultValue() [2/3]

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 28 of file OptionValue_impl.h.

28  {
29  p_vecDefaultValue = value;
30 }

References p_vecDefaultValue.

◆ setDefaultValue() [3/3]

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  std::string valueBinStr(convertToString(value));
19  VecValue vecValue;
20  vecValue.push_back(valueBinStr);
21  p_vecDefaultValue = vecValue;
22 }

References convertToString(), 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 105 of file OptionValue.cpp.

105  {
106  p_type = type;
107 }

References p_type, and createReleaseCurl::type.

Referenced by OptionParser::addOption().

+ Here is the caller graph for this function:

◆ setValue() [1/2]

void OptionValue::setValue ( const std::string &  value)

Set the value of the OptionValue.

Parameters
value: value to be set

Definition at line 112 of file OptionValue.cpp.

112  {
113  VecValue vecValue;
114  vecValue.push_back(value);
115  setValue(vecValue);
116 }

Referenced by testOptionValue().

+ Here is the caller graph for this function:

◆ setValue() [2/2]

void OptionValue::setValue ( const VecValue value)

Set the value of the OptionValue.

Parameters
value: value to be set

Definition at line 121 of file OptionValue.cpp.

121 {p_vecValue = value;}

References p_vecValue.

Member Data Documentation

◆ p_type

OptionType::OptionType OptionValue::p_type
private

◆ p_vecDefaultValue

VecValue OptionValue::p_vecDefaultValue
private

Default value of the OptionValue.

Definition at line 81 of file OptionValue.h.

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

◆ p_vecPossibleValue

VecValue OptionValue::p_vecPossibleValue
private

Vector of the possible value for the OptionValue.

Definition at line 83 of file OptionValue.h.

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

◆ p_vecValue

VecValue OptionValue::p_vecValue
private

Vector of the values of the OptionValue.

Definition at line 79 of file OptionValue.h.

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


The documentation for this class was generated from the following files:
convertToString
std::string convertToString(const T &val)
Convert a type into a string.
Definition: convertToString_impl.h:17
convertOptionTypeToString
std::string convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into string.
Definition: OptionType.cpp:69
path_completion_all
std::string path_completion_all(const std::string &basePath)
Return all path/files which match the basePath.
Definition: path_completion.cpp:41
OptionType::DIRECTORY
@ DIRECTORY
Definition: OptionType.h:27
OptionValue::p_type
OptionType::OptionType p_type
Type of the OptionValue.
Definition: OptionValue.h:77
path_completion_dirOnly
std::string path_completion_dirOnly(const std::string &basePath)
Return all directories only which match the basePath.
Definition: path_completion.cpp:87
OptionValue::initialisationOptionValue
void initialisationOptionValue(const VecValue &vecValue, OptionType::OptionType type, const VecValue &vecDefaultValue, const VecValue &vecPossibleValue)
Initialisation function of the class OptionValue.
Definition: OptionValue.cpp:206
OptionValue::p_vecDefaultValue
VecValue p_vecDefaultValue
Default value of the OptionValue.
Definition: OptionValue.h:81
isOptionTypeCompatible
bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType)
Say if two types are compatible.
Definition: OptionType.cpp:54
OptionType::FILE_OR_DIR
@ FILE_OR_DIR
Definition: OptionType.h:28
createReleaseCurl.type
type
Definition: createReleaseCurl.py:124
OptionValue::copyOptionValue
void copyOptionValue(const OptionValue &other)
Copy function of OptionValue.
Definition: OptionValue.cpp:193
OptionType::OptionType
OptionType
Definition: OptionType.h:19
OptionValue::p_vecValue
VecValue p_vecValue
Vector of the values of the OptionValue.
Definition: OptionValue.h:79
OptionValue::setValue
void setValue(const std::string &value)
Set the value of the OptionValue.
Definition: OptionValue.cpp:112
VecValue
std::vector< std::string > VecValue
Vector of values.
Definition: OptionValue.h:17
OptionValue::p_vecPossibleValue
VecValue p_vecPossibleValue
Vector of the possible value for the OptionValue.
Definition: OptionValue.h:83
OptionType::FILENAME
@ FILENAME
Definition: OptionType.h:26