mirror of https://github.com/aria2/aria2
Handle OptionHandlers as raw pointer
parent
8fc5cdea02
commit
ae2e4cb7ff
|
@ -61,7 +61,7 @@ AbstractOptionHandler::AbstractOptionHandler
|
|||
|
||||
AbstractOptionHandler::~AbstractOptionHandler() {}
|
||||
|
||||
void AbstractOptionHandler::parse(Option& option, const std::string& arg)
|
||||
void AbstractOptionHandler::parse(Option& option, const std::string& arg) const
|
||||
{
|
||||
try {
|
||||
parseArg(option, arg);
|
||||
|
|
|
@ -54,7 +54,7 @@ protected:
|
|||
|
||||
char shortName_;
|
||||
|
||||
virtual void parseArg(Option& option, const std::string& arg) = 0;
|
||||
virtual void parseArg(Option& option, const std::string& arg) const = 0;
|
||||
public:
|
||||
AbstractOptionHandler(const Pref* pref,
|
||||
const char* description = NO_DESCRIPTION,
|
||||
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
virtual ~AbstractOptionHandler();
|
||||
|
||||
virtual void parse(Option& option, const std::string& arg);
|
||||
virtual void parse(Option& option, const std::string& arg) const;
|
||||
|
||||
virtual bool hasTag(uint32_t tag) const;
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class OptionHandler {
|
|||
public:
|
||||
virtual ~OptionHandler() {}
|
||||
|
||||
virtual void parse(Option& option, const std::string& arg) = 0;
|
||||
virtual void parse(Option& option, const std::string& arg) const = 0;
|
||||
|
||||
virtual std::string createPossibleValuesString() const = 0;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,15 +39,13 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "SharedHandle.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class OptionHandler;
|
||||
|
||||
class OptionHandlerFactory {
|
||||
public:
|
||||
static std::vector<SharedHandle<OptionHandler> > createOptionHandlers();
|
||||
static std::vector<OptionHandler*> createOptionHandlers();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -79,6 +79,7 @@ BooleanOptionHandler::BooleanOptionHandler
|
|||
BooleanOptionHandler::~BooleanOptionHandler() {}
|
||||
|
||||
void BooleanOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
if(optarg == "true" ||
|
||||
((argType_ == OptionHandler::OPT_ARG ||
|
||||
|
@ -115,7 +116,7 @@ IntegerRangeOptionHandler::IntegerRangeOptionHandler
|
|||
IntegerRangeOptionHandler::~IntegerRangeOptionHandler() {}
|
||||
|
||||
void IntegerRangeOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
SegList<int> sgl;
|
||||
util::parseIntSegments(sgl, optarg);
|
||||
|
@ -153,6 +154,7 @@ NumberOptionHandler::NumberOptionHandler
|
|||
NumberOptionHandler::~NumberOptionHandler() {}
|
||||
|
||||
void NumberOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
int64_t number;
|
||||
if(util::parseLLIntNoThrow(number, optarg)) {
|
||||
|
@ -162,7 +164,7 @@ void NumberOptionHandler::parseArg(Option& option, const std::string& optarg)
|
|||
}
|
||||
}
|
||||
|
||||
void NumberOptionHandler::parseArg(Option& option, int64_t number)
|
||||
void NumberOptionHandler::parseArg(Option& option, int64_t number) const
|
||||
{
|
||||
if((min_ == -1 || min_ <= number) && (max_ == -1 || number <= max_)) {
|
||||
option.put(pref_, util::itos(number));
|
||||
|
@ -214,7 +216,7 @@ UnitNumberOptionHandler::UnitNumberOptionHandler
|
|||
UnitNumberOptionHandler::~UnitNumberOptionHandler() {}
|
||||
|
||||
void UnitNumberOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
int64_t num = util::getRealSize(optarg);
|
||||
NumberOptionHandler::parseArg(option, num);
|
||||
|
@ -236,7 +238,7 @@ FloatNumberOptionHandler::FloatNumberOptionHandler
|
|||
FloatNumberOptionHandler::~FloatNumberOptionHandler() {}
|
||||
|
||||
void FloatNumberOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
double number = strtod(optarg.c_str(), 0);
|
||||
if((min_ < 0 || min_ <= number) && (max_ < 0 || number <= max_)) {
|
||||
|
@ -289,6 +291,7 @@ DefaultOptionHandler::DefaultOptionHandler
|
|||
DefaultOptionHandler::~DefaultOptionHandler() {}
|
||||
|
||||
void DefaultOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
option.put(pref_, optarg);
|
||||
}
|
||||
|
@ -315,7 +318,7 @@ CumulativeOptionHandler::CumulativeOptionHandler
|
|||
CumulativeOptionHandler::~CumulativeOptionHandler() {}
|
||||
|
||||
void CumulativeOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
std::string value = option.get(pref_);
|
||||
value += optarg;
|
||||
|
@ -339,6 +342,7 @@ IndexOutOptionHandler::IndexOutOptionHandler
|
|||
IndexOutOptionHandler::~IndexOutOptionHandler() {}
|
||||
|
||||
void IndexOutOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
// See optarg is in the fomrat of "INDEX=PATH"
|
||||
util::parseIndexPath(optarg);
|
||||
|
@ -365,6 +369,7 @@ ChecksumOptionHandler::ChecksumOptionHandler
|
|||
ChecksumOptionHandler::~ChecksumOptionHandler() {}
|
||||
|
||||
void ChecksumOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
std::pair<Scip, Scip> p;
|
||||
util::divide(p, optarg.begin(), optarg.end(), '=');
|
||||
|
@ -440,6 +445,7 @@ ParameterOptionHandler::ParameterOptionHandler
|
|||
ParameterOptionHandler::~ParameterOptionHandler() {}
|
||||
|
||||
void ParameterOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
std::vector<std::string>::const_iterator itr =
|
||||
std::find(validParamValues_.begin(), validParamValues_.end(), optarg);
|
||||
|
@ -488,6 +494,7 @@ HostPortOptionHandler::HostPortOptionHandler
|
|||
HostPortOptionHandler::~HostPortOptionHandler() {}
|
||||
|
||||
void HostPortOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
std::string uri = "http://";
|
||||
uri += optarg;
|
||||
|
@ -500,7 +507,7 @@ void HostPortOptionHandler::parseArg(Option& option, const std::string& optarg)
|
|||
}
|
||||
|
||||
void HostPortOptionHandler::setHostAndPort
|
||||
(Option& option, const std::string& hostname, uint16_t port)
|
||||
(Option& option, const std::string& hostname, uint16_t port) const
|
||||
{
|
||||
option.put(hostOptionName_, hostname);
|
||||
option.put(portOptionName_, util::uitos(port));
|
||||
|
@ -525,6 +532,7 @@ HttpProxyOptionHandler::HttpProxyOptionHandler
|
|||
HttpProxyOptionHandler::~HttpProxyOptionHandler() {}
|
||||
|
||||
void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
if(optarg.empty()) {
|
||||
option.put(pref_, optarg);
|
||||
|
@ -564,7 +572,7 @@ LocalFilePathOptionHandler::LocalFilePathOptionHandler
|
|||
{}
|
||||
|
||||
void LocalFilePathOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
if(acceptStdin_ && optarg == "-") {
|
||||
option.put(pref_, DEV_STDIN);
|
||||
|
@ -596,7 +604,7 @@ PrioritizePieceOptionHandler::PrioritizePieceOptionHandler
|
|||
{}
|
||||
|
||||
void PrioritizePieceOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
(Option& option, const std::string& optarg) const
|
||||
{
|
||||
// Parse optarg against empty FileEntry list to detect syntax
|
||||
// error.
|
||||
|
@ -612,12 +620,19 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const
|
|||
}
|
||||
|
||||
DeprecatedOptionHandler::DeprecatedOptionHandler
|
||||
(const SharedHandle<OptionHandler>& depOptHandler,
|
||||
const SharedHandle<OptionHandler>& repOptHandler)
|
||||
(OptionHandler* depOptHandler,
|
||||
const OptionHandler* repOptHandler)
|
||||
: depOptHandler_(depOptHandler), repOptHandler_(repOptHandler)
|
||||
{}
|
||||
|
||||
DeprecatedOptionHandler::~DeprecatedOptionHandler()
|
||||
{
|
||||
delete depOptHandler_;
|
||||
// We don't delete repOptHandler_.
|
||||
}
|
||||
|
||||
void DeprecatedOptionHandler::parse(Option& option, const std::string& arg)
|
||||
const
|
||||
{
|
||||
if(repOptHandler_) {
|
||||
A2_LOG_WARN(fmt(_("--%s option is deprecated. Use --%s option instead."),
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
|
||||
char shortName = 0);
|
||||
virtual ~BooleanOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -70,7 +70,7 @@ public:
|
|||
int32_t min, int32_t max,
|
||||
char shortName = 0);
|
||||
virtual ~IntegerRangeOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -87,8 +87,8 @@ public:
|
|||
char shortName = 0);
|
||||
virtual ~NumberOptionHandler();
|
||||
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
void parseArg(Option& option, int64_t number);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
void parseArg(Option& option, int64_t number) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
int64_t max = -1,
|
||||
char shortName = 0);
|
||||
virtual ~UnitNumberOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
};
|
||||
|
||||
class FloatNumberOptionHandler : public AbstractOptionHandler {
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
double min = -1, double max = -1,
|
||||
char shortName = 0);
|
||||
virtual ~FloatNumberOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
|
||||
char shortName = 0);
|
||||
virtual ~DefaultOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -148,7 +148,7 @@ public:
|
|||
OptionHandler::REQ_ARG,
|
||||
char shortName = 0);
|
||||
virtual ~CumulativeOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
const char* description,
|
||||
char shortName = 0);
|
||||
virtual ~IndexOutOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
const char* description,
|
||||
char shortName = 0);
|
||||
virtual ~ChecksumOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
@ -202,7 +202,7 @@ public:
|
|||
const std::string& validParamValue3,
|
||||
char shortName = 0);
|
||||
virtual ~ParameterOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -218,9 +218,9 @@ public:
|
|||
const Pref* portOptionName,
|
||||
char shortName = 0);
|
||||
virtual ~HostPortOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
void setHostAndPort
|
||||
(Option& option, const std::string& hostname, uint16_t port);
|
||||
(Option& option, const std::string& hostname, uint16_t port) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -234,7 +234,7 @@ public:
|
|||
const std::string& defaultValue,
|
||||
char shortName = 0);
|
||||
virtual ~HttpProxyOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -248,7 +248,7 @@ public:
|
|||
const std::string& defaultValue = NO_DEFAULT_VALUE,
|
||||
bool acceptStdin = false,
|
||||
char shortName = 0);
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -259,7 +259,7 @@ public:
|
|||
const char* description = NO_DESCRIPTION,
|
||||
const std::string& defaultValue = NO_DEFAULT_VALUE,
|
||||
char shortName = 0);
|
||||
virtual void parseArg(Option& option, const std::string& optarg);
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
};
|
||||
|
||||
|
@ -267,17 +267,17 @@ public:
|
|||
// option value using replacing option.
|
||||
class DeprecatedOptionHandler:public OptionHandler {
|
||||
private:
|
||||
SharedHandle<OptionHandler> depOptHandler_;
|
||||
SharedHandle<OptionHandler> repOptHandler_;
|
||||
OptionHandler* depOptHandler_;
|
||||
const OptionHandler* repOptHandler_;
|
||||
public:
|
||||
// depOptHandler is deprecated option and repOptHandler is replacing
|
||||
// new option. If there is no replacing option, omit second
|
||||
// argument.
|
||||
DeprecatedOptionHandler
|
||||
(const SharedHandle<OptionHandler>& depOptHandler,
|
||||
const SharedHandle<OptionHandler>& repOptHandler =
|
||||
SharedHandle<OptionHandler>());
|
||||
virtual void parse(Option& option, const std::string& arg);
|
||||
(OptionHandler* depOptHandler,
|
||||
const OptionHandler* repOptHandler = 0);
|
||||
virtual ~DeprecatedOptionHandler();
|
||||
virtual void parse(Option& option, const std::string& arg) const;
|
||||
virtual std::string createPossibleValuesString() const;
|
||||
virtual bool hasTag(uint32_t tag) const;
|
||||
virtual void addTag(uint32_t tag);
|
||||
|
|
|
@ -56,11 +56,14 @@
|
|||
namespace aria2 {
|
||||
|
||||
OptionParser::OptionParser()
|
||||
: handlers_(option::countOption()),
|
||||
: handlers_(option::countOption(), 0),
|
||||
shortOpts_(256)
|
||||
{}
|
||||
|
||||
OptionParser::~OptionParser() {}
|
||||
OptionParser::~OptionParser()
|
||||
{
|
||||
std::for_each(handlers_.begin(), handlers_.end(), Deleter());
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename InputIterator>
|
||||
|
@ -154,7 +157,7 @@ void OptionParser::parseArg
|
|||
if(c == -1) {
|
||||
break;
|
||||
}
|
||||
SharedHandle<OptionHandler> op;
|
||||
const OptionHandler* op = 0;
|
||||
if(c == 0) {
|
||||
op = findById(lopt);
|
||||
} else if(c != '?') {
|
||||
|
@ -181,7 +184,7 @@ void OptionParser::parseArg
|
|||
int ambiguous = 0;
|
||||
for(int i = 1, len = option::countOption(); i < len; ++i) {
|
||||
const Pref* pref = option::i2p(i);
|
||||
const SharedHandle<OptionHandler>& h = find(pref);
|
||||
const OptionHandler* h = find(pref);
|
||||
if(h && !h->isHidden()) {
|
||||
if(strcmp(pref->k, optstr) == 0) {
|
||||
// Exact match, this means getopt_long detected error
|
||||
|
@ -231,7 +234,7 @@ void OptionParser::parse(Option& option, std::istream& is) const
|
|||
}
|
||||
const Pref* pref =
|
||||
option::k2p(std::string(nv.first.first, nv.first.second));
|
||||
const SharedHandle<OptionHandler>& handler = find(pref);
|
||||
const OptionHandler* handler = find(pref);
|
||||
if(handler) {
|
||||
handler->parse(option, std::string(nv.second.first, nv.second.second));
|
||||
}
|
||||
|
@ -239,15 +242,15 @@ void OptionParser::parse(Option& option, std::istream& is) const
|
|||
}
|
||||
|
||||
void OptionParser::setOptionHandlers
|
||||
(const std::vector<SharedHandle<OptionHandler> >& handlers)
|
||||
(const std::vector<OptionHandler*>& handlers)
|
||||
{
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
for(std::vector<OptionHandler*>::const_iterator i =
|
||||
handlers.begin(), eoi = handlers.end(); i != eoi; ++i) {
|
||||
addOptionHandler(*i);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionParser::addOptionHandler(const SharedHandle<OptionHandler>& handler)
|
||||
void OptionParser::addOptionHandler(OptionHandler* handler)
|
||||
{
|
||||
size_t optId = handler->getPref()->i;
|
||||
assert(optId < handlers_.size());
|
||||
|
@ -259,7 +262,7 @@ void OptionParser::addOptionHandler(const SharedHandle<OptionHandler>& handler)
|
|||
|
||||
void OptionParser::parseDefaultValues(Option& option) const
|
||||
{
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
for(std::vector<OptionHandler*>::const_iterator i =
|
||||
handlers_.begin(), eoi = handlers_.end(); i != eoi; ++i) {
|
||||
if(*i && !(*i)->getDefaultValue().empty()) {
|
||||
(*i)->parse(option, (*i)->getDefaultValue());
|
||||
|
@ -267,11 +270,10 @@ void OptionParser::parseDefaultValues(Option& option) const
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<SharedHandle<OptionHandler> >
|
||||
OptionParser::findByTag(uint32_t tag) const
|
||||
std::vector<const OptionHandler*> OptionParser::findByTag(uint32_t tag) const
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > result;
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
std::vector<const OptionHandler*> result;
|
||||
for(std::vector<OptionHandler*>::const_iterator i =
|
||||
handlers_.begin(), eoi = handlers_.end(); i != eoi; ++i) {
|
||||
if(*i && !(*i)->isHidden() && (*i)->hasTag(tag)) {
|
||||
result.push_back(*i);
|
||||
|
@ -280,11 +282,11 @@ OptionParser::findByTag(uint32_t tag) const
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<SharedHandle<OptionHandler> >
|
||||
std::vector<const OptionHandler*>
|
||||
OptionParser::findByNameSubstring(const std::string& substring) const
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > result;
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
std::vector<const OptionHandler*> result;
|
||||
for(std::vector<OptionHandler*>::const_iterator i =
|
||||
handlers_.begin(), eoi = handlers_.end(); i != eoi; ++i) {
|
||||
if(*i && !(*i)->isHidden()) {
|
||||
size_t nameLen = strlen((*i)->getName());
|
||||
|
@ -298,10 +300,10 @@ OptionParser::findByNameSubstring(const std::string& substring) const
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<SharedHandle<OptionHandler> > OptionParser::findAll() const
|
||||
std::vector<const OptionHandler*> OptionParser::findAll() const
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > result;
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
std::vector<const OptionHandler*> result;
|
||||
for(std::vector<OptionHandler*>::const_iterator i =
|
||||
handlers_.begin(), eoi = handlers_.end(); i != eoi; ++i) {
|
||||
if(*i && !(*i)->isHidden()) {
|
||||
result.push_back(*i);
|
||||
|
@ -310,17 +312,17 @@ std::vector<SharedHandle<OptionHandler> > OptionParser::findAll() const
|
|||
return result;
|
||||
}
|
||||
|
||||
const SharedHandle<OptionHandler>& OptionParser::find(const Pref* pref) const
|
||||
const OptionHandler* OptionParser::find(const Pref* pref) const
|
||||
{
|
||||
return findById(pref->i);
|
||||
}
|
||||
|
||||
const SharedHandle<OptionHandler>& OptionParser::findById(size_t id) const
|
||||
const OptionHandler* OptionParser::findById(size_t id) const
|
||||
{
|
||||
if(id >= handlers_.size()) {
|
||||
return handlers_[0];
|
||||
}
|
||||
const SharedHandle<OptionHandler>& h = handlers_[id];
|
||||
const OptionHandler* h = handlers_[id];
|
||||
if(!h || h->isHidden()) {
|
||||
return handlers_[0];
|
||||
} else {
|
||||
|
@ -328,8 +330,7 @@ const SharedHandle<OptionHandler>& OptionParser::findById(size_t id) const
|
|||
}
|
||||
}
|
||||
|
||||
const SharedHandle<OptionHandler>& OptionParser::findByShortName
|
||||
(char shortName) const
|
||||
const OptionHandler* OptionParser::findByShortName(char shortName) const
|
||||
{
|
||||
size_t idx = static_cast<unsigned char>(shortName);
|
||||
return findById(shortOpts_[idx]);
|
||||
|
|
|
@ -51,7 +51,7 @@ struct Pref;
|
|||
|
||||
class OptionParser {
|
||||
private:
|
||||
std::vector<SharedHandle<OptionHandler> > handlers_;
|
||||
std::vector<OptionHandler*> handlers_;
|
||||
// Index of handler in handlers_ for option who has short option name.
|
||||
std::vector<size_t> shortOpts_;
|
||||
static SharedHandle<OptionParser> optionParser_;
|
||||
|
@ -70,29 +70,28 @@ public:
|
|||
void parseDefaultValues(Option& option) const;
|
||||
|
||||
void setOptionHandlers
|
||||
(const std::vector<SharedHandle<OptionHandler> >& handlers);
|
||||
(const std::vector<OptionHandler*>& handlers);
|
||||
|
||||
void addOptionHandler(const SharedHandle<OptionHandler>& handler);
|
||||
void addOptionHandler(OptionHandler* handler);
|
||||
|
||||
// Hidden options are not returned.
|
||||
std::vector<SharedHandle<OptionHandler> >
|
||||
findByTag(uint32_t tag) const;
|
||||
std::vector<const OptionHandler*> findByTag(uint32_t tag) const;
|
||||
|
||||
// Hidden options are not returned.
|
||||
std::vector<SharedHandle<OptionHandler> >
|
||||
std::vector<const OptionHandler*>
|
||||
findByNameSubstring(const std::string& substring) const;
|
||||
|
||||
// Hidden options are not returned.
|
||||
std::vector<SharedHandle<OptionHandler> > findAll() const;
|
||||
std::vector<const OptionHandler*> findAll() const;
|
||||
|
||||
// Hidden options are not returned.
|
||||
const SharedHandle<OptionHandler>& find(const Pref* pref) const;
|
||||
const OptionHandler* find(const Pref* pref) const;
|
||||
|
||||
// Hidden options are not returned.
|
||||
const SharedHandle<OptionHandler>& findById(size_t id) const;
|
||||
const OptionHandler* findById(size_t id) const;
|
||||
|
||||
// Hidden options are not returned.
|
||||
const SharedHandle<OptionHandler>& findByShortName(char shortName) const;
|
||||
const OptionHandler* findByShortName(char shortName) const;
|
||||
|
||||
static const SharedHandle<OptionParser>& getInstance();
|
||||
};
|
||||
|
|
|
@ -94,7 +94,7 @@ void gatherOption
|
|||
throw DL_ABORT_EX
|
||||
(fmt("We don't know how to deal with %s option", optionName.c_str()));
|
||||
}
|
||||
const SharedHandle<OptionHandler>& handler = optionParser->find(pref);
|
||||
const OptionHandler* handler = optionParser->find(pref);
|
||||
if(!handler || !pred(handler)) {
|
||||
// Just ignore the unacceptable options in this context.
|
||||
continue;
|
||||
|
@ -123,7 +123,7 @@ void RpcMethod::gatherRequestOption(Option* option, const Dict* optionsDict)
|
|||
{
|
||||
if(optionsDict) {
|
||||
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||
mem_fun_sh(&OptionHandler::getInitialOption),
|
||||
std::mem_fun(&OptionHandler::getInitialOption),
|
||||
option, optionParser_);
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ void RpcMethod::gatherChangeableOption(Option* option, const Dict* optionsDict)
|
|||
{
|
||||
if(optionsDict) {
|
||||
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||
mem_fun_sh(&OptionHandler::getChangeOption),
|
||||
std::mem_fun(&OptionHandler::getChangeOption),
|
||||
option, optionParser_);
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ void RpcMethod::gatherChangeableOptionForReserved
|
|||
{
|
||||
if(optionsDict) {
|
||||
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||
mem_fun_sh(&OptionHandler::getChangeOptionForReserved),
|
||||
std::mem_fun(&OptionHandler::getChangeOptionForReserved),
|
||||
option, optionParser_);
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ void RpcMethod::gatherChangeableGlobalOption
|
|||
{
|
||||
if(optionsDict) {
|
||||
gatherOption(optionsDict->begin(), optionsDict->end(),
|
||||
mem_fun_sh(&OptionHandler::getChangeGlobalOption),
|
||||
std::mem_fun(&OptionHandler::getChangeGlobalOption),
|
||||
option, optionParser_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1251,7 +1251,7 @@ void pushRequestOption
|
|||
{
|
||||
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
|
||||
const Pref* pref = option::i2p(i);
|
||||
const SharedHandle<OptionHandler>& h = oparser->find(pref);
|
||||
const OptionHandler* h = oparser->find(pref);
|
||||
if(h && h->getInitialOption() && option->defined(pref)) {
|
||||
dict->put(pref->k, option->get(pref));
|
||||
}
|
||||
|
@ -1284,7 +1284,7 @@ SharedHandle<ValueBase> GetGlobalOptionRpcMethod::process
|
|||
if(!e->getOption()->defined(pref)) {
|
||||
continue;
|
||||
}
|
||||
const SharedHandle<OptionHandler>& h = getOptionParser()->find(pref);
|
||||
const OptionHandler* h = getOptionParser()->find(pref);
|
||||
if(h) {
|
||||
result->put(pref->k, e->getOption()->get(pref));
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ bool writeOption(BufferedFile& fp, const SharedHandle<Option>& op)
|
|||
const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
|
||||
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
|
||||
const Pref* pref = option::i2p(i);
|
||||
const SharedHandle<OptionHandler>& h = oparser->find(pref);
|
||||
const OptionHandler* h = oparser->find(pref);
|
||||
if(h && h->getInitialOption() && op->defined(pref)) {
|
||||
if(h->getCumulative()) {
|
||||
const std::string& val = op->get(pref);
|
||||
|
|
|
@ -465,7 +465,7 @@ bool createRequestGroupFromUriListParser
|
|||
const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
|
||||
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
|
||||
const Pref* pref = option::i2p(i);
|
||||
const SharedHandle<OptionHandler>& h = oparser->find(pref);
|
||||
const OptionHandler* h = oparser->find(pref);
|
||||
if(h && h->getInitialOption() && tempOption.defined(pref)) {
|
||||
requestOption->put(pref, tempOption.get(pref));
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ void showCandidates
|
|||
std::vector<std::pair<int, const Pref*> > cands;
|
||||
for(int i = 1, len = option::countOption(); i < len; ++i) {
|
||||
const Pref* pref = option::i2p(i);
|
||||
const SharedHandle<OptionHandler>& h = parser->find(pref);
|
||||
const OptionHandler* h = parser->find(pref);
|
||||
if(!h || h->isHidden()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
|||
} catch(OptionHandlerException& e) {
|
||||
global::cerr()->printf(_("Parse error in %s"), cfname.c_str());
|
||||
global::cerr()->printf("\n%s", e.stackTrace().c_str());
|
||||
const SharedHandle<OptionHandler>& h = oparser->find(e.getPref());
|
||||
const OptionHandler* h = oparser->find(e.getPref());
|
||||
if(h) {
|
||||
global::cerr()->printf(_("Usage:"));
|
||||
global::cerr()->printf("\n%s\n", h->getDescription());
|
||||
|
@ -275,7 +275,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
|||
#endif // __MINGW32__
|
||||
} catch(OptionHandlerException& e) {
|
||||
global::cerr()->printf("%s", e.stackTrace().c_str());
|
||||
const SharedHandle<OptionHandler>& h = oparser->find(e.getPref());
|
||||
const OptionHandler* h = oparser->find(e.getPref());
|
||||
if(h) {
|
||||
global::cerr()->printf(_("Usage:"));
|
||||
global::cerr()->printf("\n");
|
||||
|
|
|
@ -93,7 +93,7 @@ void showUsage
|
|||
out->printf("\n");
|
||||
return;
|
||||
} else if(keyword[0] == '#') {
|
||||
std::vector<SharedHandle<OptionHandler> > handlers =
|
||||
std::vector<const OptionHandler*> handlers =
|
||||
keyword == STR_TAG_ALL ? oparser->findAll() :
|
||||
oparser->findByTag(idHelpTag(keyword.c_str()));
|
||||
if(keyword == STR_TAG_ALL) {
|
||||
|
@ -107,13 +107,13 @@ void showUsage
|
|||
out->printf("\n");
|
||||
out->printf(_("Options:"));
|
||||
out->printf("\n");
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
for(std::vector<const OptionHandler*>::const_iterator i =
|
||||
handlers.begin(), eoi = handlers.end(); i != eoi; ++i) {
|
||||
write(out, *(*i));
|
||||
out->printf("\n");
|
||||
}
|
||||
} else {
|
||||
std::vector<SharedHandle<OptionHandler> > handlers =
|
||||
std::vector<const OptionHandler*> handlers =
|
||||
oparser->findByNameSubstring(keyword);
|
||||
if(!handlers.empty()) {
|
||||
out->printf(_("Printing options whose name includes '%s'."),
|
||||
|
@ -121,7 +121,7 @@ void showUsage
|
|||
out->printf("\n");
|
||||
out->printf(_("Options:"));
|
||||
out->printf("\n");
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
for(std::vector<const OptionHandler*>::const_iterator i =
|
||||
handlers.begin(), eoi = handlers.end(); i != eoi; ++i) {
|
||||
write(out, *(*i));
|
||||
out->printf("\n");
|
||||
|
|
|
@ -310,16 +310,15 @@ void OptionHandlerTest::testHttpProxyOptionHandler()
|
|||
void OptionHandlerTest::testDeprecatedOptionHandler()
|
||||
{
|
||||
{
|
||||
DeprecatedOptionHandler handler
|
||||
(SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_TIMEOUT)));
|
||||
DeprecatedOptionHandler handler(new DefaultOptionHandler(PREF_TIMEOUT));
|
||||
Option option;
|
||||
handler.parse(option, "foo");
|
||||
CPPUNIT_ASSERT(!option.defined(PREF_TIMEOUT));
|
||||
}
|
||||
{
|
||||
DeprecatedOptionHandler handler
|
||||
(SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_TIMEOUT)),
|
||||
SharedHandle<OptionHandler>(new DefaultOptionHandler(PREF_DIR)));
|
||||
DefaultOptionHandler dir(PREF_DIR);
|
||||
DeprecatedOptionHandler handler(new DefaultOptionHandler(PREF_TIMEOUT),
|
||||
&dir);
|
||||
Option option;
|
||||
handler.parse(option, "foo");
|
||||
CPPUNIT_ASSERT(!option.defined(PREF_TIMEOUT));
|
||||
|
|
|
@ -35,27 +35,27 @@ public:
|
|||
{
|
||||
oparser_.reset(new OptionParser());
|
||||
|
||||
SharedHandle<OptionHandler> timeout
|
||||
OptionHandler* timeout
|
||||
(new DefaultOptionHandler(PREF_TIMEOUT, NO_DESCRIPTION, "ALPHA", "",
|
||||
OptionHandler::REQ_ARG, 'A'));
|
||||
timeout->addTag(TAG_BASIC);
|
||||
timeout->setEraseAfterParse(true);
|
||||
oparser_->addOptionHandler(timeout);
|
||||
|
||||
SharedHandle<OptionHandler> dir(new DefaultOptionHandler(PREF_DIR));
|
||||
OptionHandler* dir(new DefaultOptionHandler(PREF_DIR));
|
||||
dir->addTag(TAG_BASIC);
|
||||
dir->addTag(TAG_HTTP);
|
||||
dir->addTag(TAG_FILE);
|
||||
oparser_->addOptionHandler(dir);
|
||||
|
||||
SharedHandle<DefaultOptionHandler> daemon
|
||||
DefaultOptionHandler* daemon
|
||||
(new DefaultOptionHandler(PREF_DAEMON, NO_DESCRIPTION, "CHARLIE", "",
|
||||
OptionHandler::REQ_ARG, 'C'));
|
||||
daemon->hide();
|
||||
daemon->addTag(TAG_FILE);
|
||||
oparser_->addOptionHandler(daemon);
|
||||
|
||||
SharedHandle<OptionHandler> out
|
||||
OptionHandler* out
|
||||
(new UnitNumberOptionHandler(PREF_OUT, NO_DESCRIPTION, "1M",
|
||||
-1, -1, 'D'));
|
||||
out->addTag(TAG_FILE);
|
||||
|
@ -80,7 +80,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(OptionParserTest);
|
|||
|
||||
void OptionParserTest::testFindAll()
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > res = oparser_->findAll();
|
||||
std::vector<const OptionHandler*> res = oparser_->findAll();
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, res.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), std::string(res[0]->getName()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("dir"), std::string(res[1]->getName()));
|
||||
|
@ -89,8 +89,7 @@ void OptionParserTest::testFindAll()
|
|||
|
||||
void OptionParserTest::testFindByNameSubstring()
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > res =
|
||||
oparser_->findByNameSubstring("i");
|
||||
std::vector<const OptionHandler*> res = oparser_->findByNameSubstring("i");
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), std::string(res[0]->getName()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("dir"), std::string(res[1]->getName()));
|
||||
|
@ -98,8 +97,7 @@ void OptionParserTest::testFindByNameSubstring()
|
|||
|
||||
void OptionParserTest::testFindByTag()
|
||||
{
|
||||
std::vector<SharedHandle<OptionHandler> > res =
|
||||
oparser_->findByTag(TAG_FILE);
|
||||
std::vector<const OptionHandler*> res = oparser_->findByTag(TAG_FILE);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("dir"), std::string(res[0]->getName()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("out"), std::string(res[1]->getName()));
|
||||
|
@ -107,20 +105,20 @@ void OptionParserTest::testFindByTag()
|
|||
|
||||
void OptionParserTest::testFind()
|
||||
{
|
||||
const SharedHandle<OptionHandler>& dir = oparser_->find(PREF_DIR);
|
||||
const OptionHandler* dir = oparser_->find(PREF_DIR);
|
||||
CPPUNIT_ASSERT(dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("dir"), std::string(dir->getName()));
|
||||
|
||||
const SharedHandle<OptionHandler>& daemon = oparser_->find(PREF_DAEMON);
|
||||
const OptionHandler* daemon = oparser_->find(PREF_DAEMON);
|
||||
CPPUNIT_ASSERT(!daemon);
|
||||
|
||||
const SharedHandle<OptionHandler>& log = oparser_->find(PREF_LOG);
|
||||
const OptionHandler* log = oparser_->find(PREF_LOG);
|
||||
CPPUNIT_ASSERT(!log);
|
||||
}
|
||||
|
||||
void OptionParserTest::testFindByShortName()
|
||||
{
|
||||
const SharedHandle<OptionHandler>& timeout = oparser_->findByShortName('A');
|
||||
const OptionHandler* timeout = oparser_->findByShortName('A');
|
||||
CPPUNIT_ASSERT(timeout);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), std::string(timeout->getName()));
|
||||
|
||||
|
@ -129,8 +127,7 @@ void OptionParserTest::testFindByShortName()
|
|||
|
||||
void OptionParserTest::testFindById()
|
||||
{
|
||||
const SharedHandle<OptionHandler>& timeout =
|
||||
oparser_->findById(PREF_TIMEOUT->i);
|
||||
const OptionHandler* timeout = oparser_->findById(PREF_TIMEOUT->i);
|
||||
CPPUNIT_ASSERT(timeout);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), std::string(timeout->getName()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue