OptionHandlerImpl.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_OPTION_HANDLER_IMPL_H
  36. #define D_OPTION_HANDLER_IMPL_H
  37. #include "OptionHandler.h"
  38. #include <vector>
  39. #include "AbstractOptionHandler.h"
  40. #include "A2STR.h"
  41. namespace aria2 {
  42. class Option;
  43. struct Pref;
  44. class BooleanOptionHandler : public AbstractOptionHandler {
  45. public:
  46. BooleanOptionHandler(const Pref* pref,
  47. const char* description = NO_DESCRIPTION,
  48. const std::string& defaultValue = NO_DEFAULT_VALUE,
  49. OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
  50. char shortName = 0);
  51. virtual ~BooleanOptionHandler();
  52. virtual void parseArg(Option& option, const std::string& optarg) const;
  53. virtual std::string createPossibleValuesString() const;
  54. };
  55. class IntegerRangeOptionHandler : public AbstractOptionHandler {
  56. private:
  57. int32_t min_;
  58. int32_t max_;
  59. public:
  60. IntegerRangeOptionHandler(const Pref* pref,
  61. const char* description,
  62. const std::string& defaultValue,
  63. int32_t min, int32_t max,
  64. char shortName = 0);
  65. virtual ~IntegerRangeOptionHandler();
  66. virtual void parseArg(Option& option, const std::string& optarg) const;
  67. virtual std::string createPossibleValuesString() const;
  68. };
  69. class NumberOptionHandler : public AbstractOptionHandler {
  70. private:
  71. int64_t min_;
  72. int64_t max_;
  73. public:
  74. NumberOptionHandler(const Pref* pref,
  75. const char* description = NO_DESCRIPTION,
  76. const std::string& defaultValue = NO_DEFAULT_VALUE,
  77. int64_t min = -1,
  78. int64_t max = -1,
  79. char shortName = 0);
  80. virtual ~NumberOptionHandler();
  81. virtual void parseArg(Option& option, const std::string& optarg) const;
  82. void parseArg(Option& option, int64_t number) const;
  83. virtual std::string createPossibleValuesString() const;
  84. };
  85. class UnitNumberOptionHandler : public NumberOptionHandler {
  86. public:
  87. UnitNumberOptionHandler(const Pref* pref,
  88. const char* description = NO_DESCRIPTION,
  89. const std::string& defaultValue = NO_DEFAULT_VALUE,
  90. int64_t min = -1,
  91. int64_t max = -1,
  92. char shortName = 0);
  93. virtual ~UnitNumberOptionHandler();
  94. virtual void parseArg(Option& option, const std::string& optarg) const;
  95. };
  96. class FloatNumberOptionHandler : public AbstractOptionHandler {
  97. private:
  98. double min_;
  99. double max_;
  100. public:
  101. FloatNumberOptionHandler(const Pref* pref,
  102. const char* description = NO_DESCRIPTION,
  103. const std::string& defaultValue = NO_DEFAULT_VALUE,
  104. double min = -1, double max = -1,
  105. char shortName = 0);
  106. virtual ~FloatNumberOptionHandler();
  107. virtual void parseArg(Option& option, const std::string& optarg) const;
  108. virtual std::string createPossibleValuesString() const;
  109. };
  110. class DefaultOptionHandler : public AbstractOptionHandler {
  111. private:
  112. std::string possibleValuesString_;
  113. public:
  114. DefaultOptionHandler(const Pref* pref,
  115. const char* description = NO_DESCRIPTION,
  116. const std::string& defaultValue = NO_DEFAULT_VALUE,
  117. const std::string& possibleValuesString = A2STR::NIL,
  118. OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
  119. char shortName = 0);
  120. virtual ~DefaultOptionHandler();
  121. virtual void parseArg(Option& option, const std::string& optarg) const;
  122. virtual std::string createPossibleValuesString() const;
  123. };
  124. class CumulativeOptionHandler : public AbstractOptionHandler {
  125. private:
  126. std::string delim_;
  127. std::string possibleValuesString_;
  128. public:
  129. CumulativeOptionHandler(const Pref* pref,
  130. const char* description,
  131. const std::string& defaultValue,
  132. const std::string& delim,
  133. const std::string& possibleValuesString = A2STR::NIL,
  134. OptionHandler::ARG_TYPE argType =
  135. OptionHandler::REQ_ARG,
  136. char shortName = 0);
  137. virtual ~CumulativeOptionHandler();
  138. virtual void parseArg(Option& option, const std::string& optarg) const;
  139. virtual std::string createPossibleValuesString() const;
  140. };
  141. class IndexOutOptionHandler : public AbstractOptionHandler {
  142. public:
  143. IndexOutOptionHandler(const Pref* pref,
  144. const char* description,
  145. char shortName = 0);
  146. virtual ~IndexOutOptionHandler();
  147. virtual void parseArg(Option& option, const std::string& optarg) const;
  148. virtual std::string createPossibleValuesString() const;
  149. };
  150. #ifdef ENABLE_MESSAGE_DIGEST
  151. class ChecksumOptionHandler : public AbstractOptionHandler {
  152. public:
  153. ChecksumOptionHandler(const Pref* pref,
  154. const char* description,
  155. char shortName = 0);
  156. virtual ~ChecksumOptionHandler();
  157. virtual void parseArg(Option& option, const std::string& optarg) const;
  158. virtual std::string createPossibleValuesString() const;
  159. };
  160. #endif // ENABLE_MESSAGE_DIGEST
  161. class ParameterOptionHandler : public AbstractOptionHandler {
  162. private:
  163. std::vector<std::string> validParamValues_;
  164. public:
  165. ParameterOptionHandler(const Pref* pref,
  166. const char* description,
  167. const std::string& defaultValue,
  168. const std::vector<std::string>& validParamValues,
  169. char shortName = 0);
  170. ParameterOptionHandler(const Pref* pref,
  171. const char* description,
  172. const std::string& defaultValue,
  173. const std::string& validParamValue,
  174. char shortName = 0);
  175. ParameterOptionHandler(const Pref* pref,
  176. const char* description,
  177. const std::string& defaultValue,
  178. const std::string& validParamValue1,
  179. const std::string& validParamValue2,
  180. char shortName = 0);
  181. ParameterOptionHandler(const Pref* pref,
  182. const char* description,
  183. const std::string& defaultValue,
  184. const std::string& validParamValue1,
  185. const std::string& validParamValue2,
  186. const std::string& validParamValue3,
  187. char shortName = 0);
  188. virtual ~ParameterOptionHandler();
  189. virtual void parseArg(Option& option, const std::string& optarg) const;
  190. virtual std::string createPossibleValuesString() const;
  191. };
  192. class HostPortOptionHandler : public AbstractOptionHandler {
  193. private:
  194. const Pref* hostOptionName_;
  195. const Pref* portOptionName_;
  196. public:
  197. HostPortOptionHandler(const Pref* pref,
  198. const char* description,
  199. const std::string& defaultValue,
  200. const Pref* hostOptionName,
  201. const Pref* portOptionName,
  202. char shortName = 0);
  203. virtual ~HostPortOptionHandler();
  204. virtual void parseArg(Option& option, const std::string& optarg) const;
  205. void setHostAndPort
  206. (Option& option, const std::string& hostname, uint16_t port) const;
  207. virtual std::string createPossibleValuesString() const;
  208. };
  209. class HttpProxyOptionHandler : public AbstractOptionHandler {
  210. private:
  211. const Pref* proxyUserPref_;
  212. const Pref* proxyPasswdPref_;
  213. public:
  214. HttpProxyOptionHandler(const Pref* pref,
  215. const char* description,
  216. const std::string& defaultValue,
  217. char shortName = 0);
  218. virtual ~HttpProxyOptionHandler();
  219. virtual void parseArg(Option& option, const std::string& optarg) const;
  220. virtual std::string createPossibleValuesString() const;
  221. };
  222. class LocalFilePathOptionHandler : public AbstractOptionHandler {
  223. private:
  224. bool acceptStdin_;
  225. public:
  226. LocalFilePathOptionHandler
  227. (const Pref* pref,
  228. const char* description = NO_DESCRIPTION,
  229. const std::string& defaultValue = NO_DEFAULT_VALUE,
  230. bool acceptStdin = false,
  231. char shortName = 0);
  232. virtual void parseArg(Option& option, const std::string& optarg) const;
  233. virtual std::string createPossibleValuesString() const;
  234. };
  235. class PrioritizePieceOptionHandler:public AbstractOptionHandler {
  236. public:
  237. PrioritizePieceOptionHandler
  238. (const Pref* pref,
  239. const char* description = NO_DESCRIPTION,
  240. const std::string& defaultValue = NO_DEFAULT_VALUE,
  241. char shortName = 0);
  242. virtual void parseArg(Option& option, const std::string& optarg) const;
  243. virtual std::string createPossibleValuesString() const;
  244. };
  245. // This class is used to deprecate option and optionally handle its
  246. // option value using replacing option.
  247. class DeprecatedOptionHandler:public OptionHandler {
  248. private:
  249. OptionHandler* depOptHandler_;
  250. const OptionHandler* repOptHandler_;
  251. public:
  252. // depOptHandler is deprecated option and repOptHandler is replacing
  253. // new option. If there is no replacing option, omit second
  254. // argument.
  255. DeprecatedOptionHandler
  256. (OptionHandler* depOptHandler,
  257. const OptionHandler* repOptHandler = 0);
  258. virtual ~DeprecatedOptionHandler();
  259. virtual void parse(Option& option, const std::string& arg) const;
  260. virtual std::string createPossibleValuesString() const;
  261. virtual bool hasTag(uint32_t tag) const;
  262. virtual void addTag(uint32_t tag);
  263. virtual std::string toTagString() const;
  264. virtual const char* getName() const;
  265. virtual const char* getDescription() const;
  266. virtual const std::string& getDefaultValue() const;
  267. virtual bool isHidden() const;
  268. virtual void hide();
  269. virtual const Pref* getPref() const;
  270. virtual ARG_TYPE getArgType() const;
  271. virtual char getShortName() const;
  272. virtual bool getEraseAfterParse() const;
  273. virtual void setEraseAfterParse(bool eraseAfterParse);
  274. virtual bool getInitialOption() const;
  275. virtual void setInitialOption(bool f);
  276. virtual bool getChangeOption() const;
  277. virtual void setChangeOption(bool f);
  278. virtual bool getChangeOptionForReserved() const;
  279. virtual void setChangeOptionForReserved(bool f);
  280. virtual bool getChangeGlobalOption() const;
  281. virtual void setChangeGlobalOption(bool f);
  282. virtual bool getCumulative() const;
  283. virtual void setCumulative(bool f);
  284. };
  285. } // namespace aria2
  286. #endif // D_OPTION_HANDLER_IMPL_H