mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-10 12:49:08 -04:00
Mark getValue functions as const.
The various getValue functions should not modify the underlying class, so they have been turned into const. The only exception is ValueArg where a non-const version is kept for backward compatibility (it should be removed if we allow an API break). The other instances are safe since the return value is not changed and the new function signature is less restrictive.
This commit is contained in:
parent
b3f85f4965
commit
e006d96c53
@ -185,7 +185,7 @@ public:
|
|||||||
* Returns a vector of type T containing the values parsed from
|
* Returns a vector of type T containing the values parsed from
|
||||||
* the command line.
|
* the command line.
|
||||||
*/
|
*/
|
||||||
const std::vector<T>& getValue();
|
const std::vector<T>& getValue() const { return _values; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator over the values parsed from the command
|
* Returns an iterator over the values parsed from the command
|
||||||
@ -301,9 +301,6 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
_acceptsMultipleValues = true;
|
_acceptsMultipleValues = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
const std::vector<T>& MultiArg<T>::getValue() { return _values; }
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ class MultiSwitchArg : public SwitchArg
|
|||||||
/**
|
/**
|
||||||
* Returns int, the number of times the switch has been set.
|
* Returns int, the number of times the switch has been set.
|
||||||
*/
|
*/
|
||||||
int getValue();
|
int getValue() const { return _value; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shortID for this Arg.
|
* Returns the shortID for this Arg.
|
||||||
@ -150,8 +150,6 @@ _default( init )
|
|||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int MultiSwitchArg::getValue() { return _value; }
|
|
||||||
|
|
||||||
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
|
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
|
@ -111,7 +111,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns bool, whether or not the switch has been set.
|
* Returns bool, whether or not the switch has been set.
|
||||||
*/
|
*/
|
||||||
bool getValue() /* TODO(macbishop) should be const */;
|
bool getValue() const { return _value; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A SwitchArg can be used as a boolean, indicating
|
* A SwitchArg can be used as a boolean, indicating
|
||||||
@ -161,8 +161,6 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
|||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SwitchArg::getValue() { return _value; }
|
|
||||||
|
|
||||||
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||||
|
@ -220,13 +220,17 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns the value of the argument.
|
* Returns the value of the argument.
|
||||||
*/
|
*/
|
||||||
/* const */ T& getValue() /* TODO(macbishop): should be const */;
|
const T& getValue() const { return _value; }
|
||||||
|
|
||||||
|
// TODO(macbishop): Non-const variant is deprecated, don't
|
||||||
|
// use. Remove in next major.
|
||||||
|
T& getValue() { return _value; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ValueArg can be used as as its value type (T) This is the
|
* A ValueArg can be used as as its value type (T) This is the
|
||||||
* same as calling getValue()
|
* same as calling getValue()
|
||||||
*/
|
*/
|
||||||
operator const T&() const { return _value; }
|
operator const T&() const { return getValue(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialization of shortID.
|
* Specialization of shortID.
|
||||||
@ -321,13 +325,6 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
|||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of getValue().
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
T& ValueArg<T>::getValue() { return _value; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of processArg().
|
* Implementation of processArg().
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user