Made Pref::k_, OptionHandler::getName() and getDescription() const char*.

pull/2/head
Tatsuhiro Tsujikawa 2011-11-11 01:59:23 +09:00
parent 787bfd75da
commit 35a3f41346
13 changed files with 95 additions and 90 deletions

View File

@ -45,7 +45,7 @@ namespace aria2 {
AbstractOptionHandler::AbstractOptionHandler AbstractOptionHandler::AbstractOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
ARG_TYPE argType, ARG_TYPE argType,
char shortName) char shortName)
@ -89,7 +89,7 @@ std::string AbstractOptionHandler::toTagString() const
return strjoin(tags_.begin(), tags_.end(), ", "); return strjoin(tags_.begin(), tags_.end(), ", ");
} }
const std::string& AbstractOptionHandler::getName() const const char* AbstractOptionHandler::getName() const
{ {
return pref_->k; return pref_->k;
} }

View File

@ -50,7 +50,7 @@ class AbstractOptionHandler : public OptionHandler {
protected: protected:
const Pref* pref_; const Pref* pref_;
std::string description_; const char* description_;
std::string defaultValue_; std::string defaultValue_;
@ -73,7 +73,7 @@ protected:
virtual void parseArg(Option& option, const std::string& arg) = 0; virtual void parseArg(Option& option, const std::string& arg) = 0;
public: public:
AbstractOptionHandler(const Pref* pref, AbstractOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
ARG_TYPE argType = REQ_ARG, ARG_TYPE argType = REQ_ARG,
char shortName = 0); char shortName = 0);
@ -88,9 +88,9 @@ public:
virtual std::string toTagString() const; virtual std::string toTagString() const;
virtual const std::string& getName() const; virtual const char* getName() const;
virtual const std::string& getDescription() const virtual const char* getDescription() const
{ {
return description_; return description_;
} }

View File

@ -41,7 +41,7 @@
namespace aria2 { namespace aria2 {
const std::string NO_DESCRIPTION(""); const char NO_DESCRIPTION[] = "";
const std::string NO_DEFAULT_VALUE(""); const std::string NO_DEFAULT_VALUE("");
const std::string PATH_TO_FILE("/path/to/file"); const std::string PATH_TO_FILE("/path/to/file");

View File

@ -46,7 +46,7 @@
namespace aria2 { namespace aria2 {
extern const std::string NO_DESCRIPTION; extern const char NO_DESCRIPTION[];
extern const std::string NO_DEFAULT_VALUE; extern const std::string NO_DEFAULT_VALUE;
extern const std::string PATH_TO_FILE; extern const std::string PATH_TO_FILE;
@ -72,9 +72,9 @@ public:
virtual std::string toTagString() const = 0; virtual std::string toTagString() const = 0;
virtual const std::string& getName() const = 0; virtual const char* getName() const = 0;
virtual const std::string& getDescription() const = 0; virtual const char* getDescription() const = 0;
virtual const std::string& getDefaultValue() const = 0; virtual const std::string& getDefaultValue() const = 0;

View File

@ -45,7 +45,7 @@ OptionHandlerException::OptionHandlerException
(const char* file, int line, (const char* file, int line,
const Pref* pref) const Pref* pref)
: RecoverableException : RecoverableException
(file, line, fmt(MESSAGE.c_str(), pref->k.c_str()), (file, line, fmt(MESSAGE.c_str(), pref->k),
error_code::OPTION_ERROR), error_code::OPTION_ERROR),
pref_(pref) pref_(pref)
{} {}
@ -55,7 +55,7 @@ OptionHandlerException::OptionHandlerException
const Pref* pref, const Pref* pref,
const Exception& cause) const Exception& cause)
: RecoverableException : RecoverableException
(file, line, fmt(MESSAGE.c_str(), pref->k.c_str()), (file, line, fmt(MESSAGE.c_str(), pref->k),
error_code::OPTION_ERROR, error_code::OPTION_ERROR,
cause), cause),
pref_(pref) pref_(pref)

View File

@ -36,6 +36,7 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstring>
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
@ -67,7 +68,7 @@ namespace aria2 {
BooleanOptionHandler::BooleanOptionHandler BooleanOptionHandler::BooleanOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
OptionHandler::ARG_TYPE argType, OptionHandler::ARG_TYPE argType,
char shortName) char shortName)
@ -100,7 +101,7 @@ std::string BooleanOptionHandler::createPossibleValuesString() const
IntegerRangeOptionHandler::IntegerRangeOptionHandler IntegerRangeOptionHandler::IntegerRangeOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
int32_t min, int32_t max, int32_t min, int32_t max,
char shortName) char shortName)
@ -138,7 +139,7 @@ std::string IntegerRangeOptionHandler::createPossibleValuesString() const
NumberOptionHandler::NumberOptionHandler NumberOptionHandler::NumberOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
int64_t min, int64_t min,
int64_t max, int64_t max,
@ -200,7 +201,7 @@ std::string NumberOptionHandler::createPossibleValuesString() const
UnitNumberOptionHandler::UnitNumberOptionHandler UnitNumberOptionHandler::UnitNumberOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
int64_t min, int64_t min,
int64_t max, int64_t max,
@ -220,7 +221,7 @@ void UnitNumberOptionHandler::parseArg
FloatNumberOptionHandler::FloatNumberOptionHandler FloatNumberOptionHandler::FloatNumberOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
double min, double min,
double max, double max,
@ -278,7 +279,7 @@ std::string FloatNumberOptionHandler::createPossibleValuesString() const
DefaultOptionHandler::DefaultOptionHandler DefaultOptionHandler::DefaultOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& possibleValuesString, const std::string& possibleValuesString,
OptionHandler::ARG_TYPE argType, OptionHandler::ARG_TYPE argType,
@ -302,7 +303,7 @@ std::string DefaultOptionHandler::createPossibleValuesString() const
CumulativeOptionHandler::CumulativeOptionHandler CumulativeOptionHandler::CumulativeOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& delim, const std::string& delim,
const std::string& possibleValuesString, const std::string& possibleValuesString,
@ -331,7 +332,7 @@ std::string CumulativeOptionHandler::createPossibleValuesString() const
IndexOutOptionHandler::IndexOutOptionHandler IndexOutOptionHandler::IndexOutOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, NO_DEFAULT_VALUE, : AbstractOptionHandler(pref, description, NO_DEFAULT_VALUE,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
@ -356,7 +357,7 @@ std::string IndexOutOptionHandler::createPossibleValuesString() const
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
ChecksumOptionHandler::ChecksumOptionHandler ChecksumOptionHandler::ChecksumOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, NO_DEFAULT_VALUE, : AbstractOptionHandler(pref, description, NO_DEFAULT_VALUE,
OptionHandler::REQ_ARG, shortName) OptionHandler::REQ_ARG, shortName)
@ -386,7 +387,7 @@ std::string ChecksumOptionHandler::createPossibleValuesString() const
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::vector<std::string>& validParamValues, const std::vector<std::string>& validParamValues,
char shortName) char shortName)
@ -397,7 +398,7 @@ ParameterOptionHandler::ParameterOptionHandler
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue, const std::string& validParamValue,
char shortName) char shortName)
@ -409,7 +410,7 @@ ParameterOptionHandler::ParameterOptionHandler
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
@ -423,7 +424,7 @@ ParameterOptionHandler::ParameterOptionHandler
ParameterOptionHandler::ParameterOptionHandler ParameterOptionHandler::ParameterOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
@ -471,7 +472,7 @@ std::string ParameterOptionHandler::createPossibleValuesString() const
HostPortOptionHandler::HostPortOptionHandler HostPortOptionHandler::HostPortOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const Pref* hostOptionName, const Pref* hostOptionName,
const Pref* portOptionName, const Pref* portOptionName,
@ -510,7 +511,7 @@ std::string HostPortOptionHandler::createPossibleValuesString() const
HttpProxyUserOptionHandler::HttpProxyUserOptionHandler HttpProxyUserOptionHandler::HttpProxyUserOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, defaultValue, : AbstractOptionHandler(pref, description, defaultValue,
@ -521,9 +522,9 @@ void HttpProxyUserOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
const char A2_USER[] = "-user"; const char A2_USER[] = "-user";
if(util::endsWith(pref_->k.begin(), pref_->k.end(), size_t kLen = strlen(pref_->k);
A2_USER, vend(A2_USER)-1)) { if(util::endsWith(pref_->k, pref_->k+kLen, A2_USER, vend(A2_USER)-1)) {
const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-5)); const Pref* proxyPref = option::k2p(std::string(pref_->k, kLen-5));
const std::string& olduri = option.get(proxyPref); const std::string& olduri = option.get(proxyPref);
if(!olduri.empty()) { if(!olduri.empty()) {
Request req; Request req;
@ -554,7 +555,7 @@ std::string HttpProxyUserOptionHandler::createPossibleValuesString() const
HttpProxyPasswdOptionHandler::HttpProxyPasswdOptionHandler HttpProxyPasswdOptionHandler::HttpProxyPasswdOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, defaultValue, : AbstractOptionHandler(pref, description, defaultValue,
@ -565,9 +566,9 @@ void HttpProxyPasswdOptionHandler::parseArg
(Option& option, const std::string& optarg) (Option& option, const std::string& optarg)
{ {
const char A2_PASSWD[] = "-passwd"; const char A2_PASSWD[] = "-passwd";
if(util::endsWith(pref_->k.begin(), pref_->k.end(), size_t kLen = strlen(pref_->k);
A2_PASSWD, vend(A2_PASSWD)-1)) { if(util::endsWith(pref_->k, pref_->k+kLen, A2_PASSWD, vend(A2_PASSWD)-1)) {
const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-7)); const Pref* proxyPref = option::k2p(std::string(pref_->k, kLen-7));
const std::string& olduri = option.get(proxyPref); const std::string& olduri = option.get(proxyPref);
if(!olduri.empty()) { if(!olduri.empty()) {
Request req; Request req;
@ -598,13 +599,13 @@ std::string HttpProxyPasswdOptionHandler::createPossibleValuesString() const
HttpProxyOptionHandler::HttpProxyOptionHandler HttpProxyOptionHandler::HttpProxyOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, defaultValue, : AbstractOptionHandler(pref, description, defaultValue,
OptionHandler::REQ_ARG, shortName), OptionHandler::REQ_ARG, shortName),
proxyUserPref_(option::k2p(pref->k+"-user")), proxyUserPref_(option::k2p(std::string(pref->k)+"-user")),
proxyPasswdPref_(option::k2p(pref->k+"-passwd")) proxyPasswdPref_(option::k2p(std::string(pref->k)+"-passwd"))
{} {}
HttpProxyOptionHandler::~HttpProxyOptionHandler() {} HttpProxyOptionHandler::~HttpProxyOptionHandler() {}
@ -657,7 +658,7 @@ std::string HttpProxyOptionHandler::createPossibleValuesString() const
LocalFilePathOptionHandler::LocalFilePathOptionHandler LocalFilePathOptionHandler::LocalFilePathOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
bool acceptStdin, bool acceptStdin,
char shortName) char shortName)
@ -691,7 +692,7 @@ std::string LocalFilePathOptionHandler::createPossibleValuesString() const
PrioritizePieceOptionHandler::PrioritizePieceOptionHandler PrioritizePieceOptionHandler::PrioritizePieceOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName) char shortName)
: AbstractOptionHandler(pref, description, defaultValue, : AbstractOptionHandler(pref, description, defaultValue,
@ -724,12 +725,12 @@ void DeprecatedOptionHandler::parse(Option& option, const std::string& arg)
{ {
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."),
depOptHandler_->getName().c_str(), depOptHandler_->getName(),
repOptHandler_->getName().c_str())); repOptHandler_->getName()));
repOptHandler_->parse(option, arg); repOptHandler_->parse(option, arg);
} else { } else {
A2_LOG_WARN(fmt(_("--%s option is deprecated."), A2_LOG_WARN(fmt(_("--%s option is deprecated."),
depOptHandler_->getName().c_str())); depOptHandler_->getName()));
} }
} }
@ -753,12 +754,12 @@ std::string DeprecatedOptionHandler::toTagString() const
return depOptHandler_->toTagString(); return depOptHandler_->toTagString();
} }
const std::string& DeprecatedOptionHandler::getName() const const char* DeprecatedOptionHandler::getName() const
{ {
return depOptHandler_->getName(); return depOptHandler_->getName();
} }
const std::string& DeprecatedOptionHandler::getDescription() const const char* DeprecatedOptionHandler::getDescription() const
{ {
return depOptHandler_->getDescription(); return depOptHandler_->getDescription();
} }

View File

@ -49,7 +49,7 @@ class Pref;
class BooleanOptionHandler : public AbstractOptionHandler { class BooleanOptionHandler : public AbstractOptionHandler {
public: public:
BooleanOptionHandler(const Pref* pref, BooleanOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG, OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
char shortName = 0); char shortName = 0);
@ -64,7 +64,7 @@ private:
int32_t max_; int32_t max_;
public: public:
IntegerRangeOptionHandler(const Pref* pref, IntegerRangeOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
int32_t min, int32_t max, int32_t min, int32_t max,
char shortName = 0); char shortName = 0);
@ -79,7 +79,7 @@ private:
int64_t max_; int64_t max_;
public: public:
NumberOptionHandler(const Pref* pref, NumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1, int64_t min = -1,
int64_t max = -1, int64_t max = -1,
@ -94,7 +94,7 @@ public:
class UnitNumberOptionHandler : public NumberOptionHandler { class UnitNumberOptionHandler : public NumberOptionHandler {
public: public:
UnitNumberOptionHandler(const Pref* pref, UnitNumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
int64_t min = -1, int64_t min = -1,
int64_t max = -1, int64_t max = -1,
@ -109,7 +109,7 @@ private:
double max_; double max_;
public: public:
FloatNumberOptionHandler(const Pref* pref, FloatNumberOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
double min = -1, double max = -1, double min = -1, double max = -1,
char shortName = 0); char shortName = 0);
@ -123,7 +123,7 @@ private:
std::string possibleValuesString_; std::string possibleValuesString_;
public: public:
DefaultOptionHandler(const Pref* pref, DefaultOptionHandler(const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
const std::string& defaultValue = NO_DEFAULT_VALUE, const std::string& defaultValue = NO_DEFAULT_VALUE,
const std::string& possibleValuesString = A2STR::NIL, const std::string& possibleValuesString = A2STR::NIL,
OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG, OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
@ -139,7 +139,7 @@ private:
std::string possibleValuesString_; std::string possibleValuesString_;
public: public:
CumulativeOptionHandler(const Pref* pref, CumulativeOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& delim, const std::string& delim,
const std::string& possibleValuesString = A2STR::NIL, const std::string& possibleValuesString = A2STR::NIL,
@ -154,7 +154,7 @@ public:
class IndexOutOptionHandler : public AbstractOptionHandler { class IndexOutOptionHandler : public AbstractOptionHandler {
public: public:
IndexOutOptionHandler(const Pref* pref, IndexOutOptionHandler(const Pref* pref,
const std::string& 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);
@ -165,7 +165,7 @@ public:
class ChecksumOptionHandler : public AbstractOptionHandler { class ChecksumOptionHandler : public AbstractOptionHandler {
public: public:
ChecksumOptionHandler(const Pref* pref, ChecksumOptionHandler(const Pref* pref,
const std::string& 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);
@ -178,23 +178,23 @@ private:
std::vector<std::string> validParamValues_; std::vector<std::string> validParamValues_;
public: public:
ParameterOptionHandler(const Pref* pref, ParameterOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::vector<std::string>& validParamValues, const std::vector<std::string>& validParamValues,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const Pref* pref, ParameterOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue, const std::string& validParamValue,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const Pref* pref, ParameterOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
char shortName = 0); char shortName = 0);
ParameterOptionHandler(const Pref* pref, ParameterOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const std::string& validParamValue1, const std::string& validParamValue1,
const std::string& validParamValue2, const std::string& validParamValue2,
@ -211,7 +211,7 @@ private:
const Pref* portOptionName_; const Pref* portOptionName_;
public: public:
HostPortOptionHandler(const Pref* pref, HostPortOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
const Pref* hostOptionName, const Pref* hostOptionName,
const Pref* portOptionName, const Pref* portOptionName,
@ -226,7 +226,7 @@ public:
class HttpProxyUserOptionHandler:public AbstractOptionHandler { class HttpProxyUserOptionHandler:public AbstractOptionHandler {
public: public:
HttpProxyUserOptionHandler(const Pref* pref, HttpProxyUserOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg); virtual void parseArg(Option& option, const std::string& optarg);
@ -236,7 +236,7 @@ public:
class HttpProxyPasswdOptionHandler:public AbstractOptionHandler { class HttpProxyPasswdOptionHandler:public AbstractOptionHandler {
public: public:
HttpProxyPasswdOptionHandler(const Pref* pref, HttpProxyPasswdOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
virtual void parseArg(Option& option, const std::string& optarg); virtual void parseArg(Option& option, const std::string& optarg);
@ -249,7 +249,7 @@ private:
const Pref* proxyPasswdPref_; const Pref* proxyPasswdPref_;
public: public:
HttpProxyOptionHandler(const Pref* pref, HttpProxyOptionHandler(const Pref* pref,
const std::string& description, const char* description,
const std::string& defaultValue, const std::string& defaultValue,
char shortName = 0); char shortName = 0);
virtual ~HttpProxyOptionHandler(); virtual ~HttpProxyOptionHandler();
@ -263,7 +263,7 @@ private:
public: public:
LocalFilePathOptionHandler LocalFilePathOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& description = NO_DESCRIPTION, const char* description = NO_DESCRIPTION,
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);
@ -275,7 +275,7 @@ class PrioritizePieceOptionHandler:public AbstractOptionHandler {
public: public:
PrioritizePieceOptionHandler PrioritizePieceOptionHandler
(const Pref* pref, (const Pref* pref,
const std::string& 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);
@ -301,8 +301,8 @@ public:
virtual bool hasTag(const std::string& tag) const; virtual bool hasTag(const std::string& tag) const;
virtual void addTag(const std::string& tag); virtual void addTag(const std::string& tag);
virtual std::string toTagString() const; virtual std::string toTagString() const;
virtual const std::string& getName() const; virtual const char* getName() const;
virtual const std::string& getDescription() const; virtual const char* getDescription() const;
virtual const std::string& getDefaultValue() const; virtual const std::string& getDefaultValue() const;
virtual bool isHidden() const; virtual bool isHidden() const;
virtual void hide(); virtual void hide();

View File

@ -83,9 +83,9 @@ void putOptions(struct option* longOpts, int* plopt,
for(; first != last; ++first) { for(; first != last; ++first) {
if(*first && !(*first)->isHidden()) { if(*first && !(*first)->isHidden()) {
#ifdef HAVE_OPTION_CONST_NAME #ifdef HAVE_OPTION_CONST_NAME
(*longOpts).name = (*first)->getName().c_str(); (*longOpts).name = (*first)->getName();
#else // !HAVE_OPTION_CONST_NAME #else // !HAVE_OPTION_CONST_NAME
(*longOpts).name = strdup((*first)->getName().c_str()); (*longOpts).name = strdup((*first)->getName());
#endif // !HAVE_OPTION_CONST_NAME #endif // !HAVE_OPTION_CONST_NAME
switch((*first)->getArgType()) { switch((*first)->getArgType()) {
case OptionHandler::REQ_ARG: case OptionHandler::REQ_ARG:
@ -146,7 +146,7 @@ void OptionParser::parseArg
handlers_.end()); handlers_.end());
int lopt; int lopt;
array_ptr<struct option> longOpts(new struct option[numPublicOption+1]); array_ptr<struct option> longOpts(new struct option[numPublicOption+1]);
putOptions(longOpts, &lopt,handlers_.begin(),handlers_.end()); putOptions(longOpts, &lopt, handlers_.begin(), handlers_.end());
std::string optstring = createOptstring(handlers_.begin(), handlers_.end()); std::string optstring = createOptstring(handlers_.begin(), handlers_.end());
while(1) { while(1) {
int c = getopt_long(argc, argv, optstring.c_str(), longOpts, 0); int c = getopt_long(argc, argv, optstring.c_str(), longOpts, 0);
@ -245,9 +245,13 @@ OptionParser::findByNameSubstring(const std::string& substring) const
std::vector<SharedHandle<OptionHandler> > result; std::vector<SharedHandle<OptionHandler> > result;
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i = for(std::vector<SharedHandle<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()) {
(*i)->getName().find(substring) != std::string::npos) { size_t nameLen = strlen((*i)->getName());
result.push_back(*i); if(std::search((*i)->getName(), (*i)->getName()+nameLen,
substring.begin(), substring.end()) !=
(*i)->getName()+nameLen) {
result.push_back(*i);
}
} }
} }
return result; return result;

View File

@ -91,12 +91,12 @@ bool writeOption(BufferedFile& fp, const SharedHandle<Option>& op)
false, false); false, false);
for(std::vector<std::string>::const_iterator j = v.begin(), for(std::vector<std::string>::const_iterator j = v.begin(),
eoj = v.end(); j != eoj; ++j) { eoj = v.end(); j != eoj; ++j) {
if(fp.printf(" %s=%s\n", pref->k.c_str(), (*j).c_str()) < 0) { if(fp.printf(" %s=%s\n", pref->k, (*j).c_str()) < 0) {
return false; return false;
} }
} }
} else { } else {
if(fp.printf(" %s=%s\n", pref->k.c_str(), op->get(pref).c_str()) < 0) { if(fp.printf(" %s=%s\n", pref->k, op->get(pref).c_str()) < 0) {
return false; return false;
} }
} }
@ -186,7 +186,7 @@ bool SessionSerializer::save(BufferedFile& fp) const
// PREF_PAUSE was removed from option, so save it here looking // PREF_PAUSE was removed from option, so save it here looking
// property separately. // property separately.
if((*itr)->isPauseRequested()) { if((*itr)->isPauseRequested()) {
if(fp.printf(" %s=true\n", PREF_PAUSE->k.c_str()) < 0) { if(fp.printf(" %s=true\n", PREF_PAUSE->k) < 0) {
return false; return false;
} }
} }

View File

@ -153,7 +153,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
e.stackTrace().c_str()); e.stackTrace().c_str());
const SharedHandle<OptionHandler>& h = oparser->find(e.getPref()); const SharedHandle<OptionHandler>& h = oparser->find(e.getPref());
if(h) { if(h) {
global::cerr()->printf("Usage:\n%s\n", h->getDescription().c_str()); global::cerr()->printf("Usage:\n%s\n", h->getDescription());
} }
exit(e.getErrorCode()); exit(e.getErrorCode());
} catch(Exception& e) { } catch(Exception& e) {

View File

@ -40,7 +40,7 @@
namespace aria2 { namespace aria2 {
Pref::Pref(const std::string& k, size_t i):k(k), i(i) {} Pref::Pref(const char* k, size_t i):k(k), i(i) {}
namespace { namespace {
@ -55,7 +55,7 @@ public:
{ {
return count_++; return count_++;
} }
Pref* makePref(const std::string& key) Pref* makePref(const char* key)
{ {
size_t id = nextId(); size_t id = nextId();
Pref* pref = new Pref(key, id); Pref* pref = new Pref(key, id);
@ -93,7 +93,7 @@ PrefFactory* getPrefFactory()
return pf; return pf;
} }
Pref* makePref(const std::string& key) Pref* makePref(const char* key)
{ {
return getPrefFactory()->makePref(key); return getPrefFactory()->makePref(key);
} }

View File

@ -41,9 +41,9 @@
namespace aria2 { namespace aria2 {
struct Pref { struct Pref {
Pref(const std::string& k, size_t i); Pref(const char* k, size_t i);
// Keyword, aka Option Name // Keyword, aka Option Name
std::string k; const char* k;
// Option ID // Option ID
size_t i; size_t i;
}; };

View File

@ -81,9 +81,9 @@ void OptionParserTest::testFindAll()
{ {
std::vector<SharedHandle<OptionHandler> > res = oparser_->findAll(); std::vector<SharedHandle<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"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"timeout", res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"dir", res[1]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("out"), res[2]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"out", res[2]->getName());
} }
void OptionParserTest::testFindByNameSubstring() void OptionParserTest::testFindByNameSubstring()
@ -91,8 +91,8 @@ void OptionParserTest::testFindByNameSubstring()
std::vector<SharedHandle<OptionHandler> > res = std::vector<SharedHandle<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"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"timeout", res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"dir", res[1]->getName());
} }
void OptionParserTest::testFindByTag() void OptionParserTest::testFindByTag()
@ -100,15 +100,15 @@ void OptionParserTest::testFindByTag()
std::vector<SharedHandle<OptionHandler> > res = std::vector<SharedHandle<OptionHandler> > res =
oparser_->findByTag("pineapple"); oparser_->findByTag("pineapple");
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("dir"), res[0]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"dir", res[0]->getName());
CPPUNIT_ASSERT_EQUAL(std::string("out"), res[1]->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"out", res[1]->getName());
} }
void OptionParserTest::testFind() void OptionParserTest::testFind()
{ {
const SharedHandle<OptionHandler>& dir = oparser_->find(PREF_DIR); const SharedHandle<OptionHandler>& dir = oparser_->find(PREF_DIR);
CPPUNIT_ASSERT(dir); CPPUNIT_ASSERT(dir);
CPPUNIT_ASSERT_EQUAL(std::string("dir"), dir->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"dir", dir->getName());
const SharedHandle<OptionHandler>& daemon = oparser_->find(PREF_DAEMON); const SharedHandle<OptionHandler>& daemon = oparser_->find(PREF_DAEMON);
CPPUNIT_ASSERT(!daemon); CPPUNIT_ASSERT(!daemon);
@ -121,7 +121,7 @@ void OptionParserTest::testFindByShortName()
{ {
const SharedHandle<OptionHandler>& timeout = oparser_->findByShortName('A'); const SharedHandle<OptionHandler>& timeout = oparser_->findByShortName('A');
CPPUNIT_ASSERT(timeout); CPPUNIT_ASSERT(timeout);
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), timeout->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"timeout", timeout->getName());
CPPUNIT_ASSERT(!oparser_->findByShortName('C')); CPPUNIT_ASSERT(!oparser_->findByShortName('C'));
} }
@ -131,7 +131,7 @@ void OptionParserTest::testFindById()
const SharedHandle<OptionHandler>& timeout = const SharedHandle<OptionHandler>& timeout =
oparser_->findById(PREF_TIMEOUT->i); oparser_->findById(PREF_TIMEOUT->i);
CPPUNIT_ASSERT(timeout); CPPUNIT_ASSERT(timeout);
CPPUNIT_ASSERT_EQUAL(std::string("timeout"), timeout->getName()); CPPUNIT_ASSERT_EQUAL((const char*)"timeout", timeout->getName());
CPPUNIT_ASSERT(!oparser_->findById(9999)); CPPUNIT_ASSERT(!oparser_->findById(9999));
} }