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