Program Listing for File multi_switch_arg.hpp
↰ Return to documentation for file (include/ecl/command_line/multi_switch_arg.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef TCLAP_MULTI_SWITCH_ARG_H
#define TCLAP_MULTI_SWITCH_ARG_H
#include <string>
#include <vector>
#include "switch_arg.hpp"
namespace ecl {
class MultiSwitchArg : public SwitchArg
{
protected:
int _value;
public:
MultiSwitchArg(const std::string& flag,
const std::string& name,
const std::string& desc,
int init = 0,
Visitor* v = NULL);
MultiSwitchArg(const std::string& flag,
const std::string& name,
const std::string& desc,
CmdLineInterface& parser,
int init = 0,
Visitor* v = NULL);
virtual bool processArg(int* i, std::vector<std::string>& args);
int getValue();
std::string shortID(const std::string& val) const;
std::string longID(const std::string& val) const;
};
//BEGIN MultiSwitchArg.cpp
inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
const std::string& name,
const std::string& desc,
int init,
Visitor* v )
: SwitchArg(flag, name, desc, false, v),
_value( init )
{ }
inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
const std::string& name,
const std::string& desc,
CmdLineInterface& parser,
int init,
Visitor* v )
: SwitchArg(flag, name, desc, false, v),
_value( init )
{
parser.add( this );
}
inline int MultiSwitchArg::getValue() { return _value; }
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
{
if ( _ignoreable && Arg::ignoreRest() )
return false;
if ( argMatches( args[*i] ))
{
// so the isSet() method will work
_alreadySet = true;
// Matched argument: increment value.
++_value;
_checkWithVisitor();
return true;
}
else if ( combinedSwitchesMatch( args[*i] ) )
{
// so the isSet() method will work
_alreadySet = true;
// Matched argument: increment value.
++_value;
// Check for more in argument and increment value.
while ( combinedSwitchesMatch( args[*i] ) )
++_value;
_checkWithVisitor();
return false;
}
else
return false;
}
inline std::string MultiSwitchArg::shortID(const std::string& val) const
{
std::string id = Arg::shortID() + " ... " + val;
return id;
}
inline std::string MultiSwitchArg::longID(const std::string& val) const
{
std::string id = Arg::longID() + " (accepted multiple times) " + val;
return id;
}
//END MultiSwitchArg.cpp
} // namespace ecl
#endif