OptionHandlerImpl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 "NameMatchOptionHandler.h"
  40. namespace aria2 {
  41. class Option;
  42. class NullOptionHandler : public OptionHandler {
  43. private:
  44. int id_;
  45. public:
  46. virtual ~NullOptionHandler();
  47. virtual bool canHandle(const std::string& optName);
  48. virtual void parse(Option& option, const std::string& arg);
  49. virtual bool hasTag(const std::string& tag) const;
  50. virtual void addTag(const std::string& tag);
  51. virtual std::string toTagString() const;
  52. virtual const std::string& getName() const;
  53. virtual const std::string& getDescription() const;
  54. virtual const std::string& getDefaultValue() const;
  55. virtual std::string createPossibleValuesString() const;
  56. virtual bool isHidden() const;
  57. virtual void hide();
  58. virtual OptionHandler::ARG_TYPE getArgType() const;
  59. virtual int getOptionID() const;
  60. virtual void setOptionID(int id);
  61. virtual char getShortName() const;
  62. virtual bool getEraseAfterParse() const;
  63. virtual void setEraseAfterParse(bool eraseAfterParse);
  64. };
  65. class BooleanOptionHandler : public NameMatchOptionHandler {
  66. public:
  67. BooleanOptionHandler(const std::string& optName,
  68. const std::string& description = NO_DESCRIPTION,
  69. const std::string& defaultValue = NO_DEFAULT_VALUE,
  70. OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
  71. char shortName = 0);
  72. virtual ~BooleanOptionHandler();
  73. virtual void parseArg(Option& option, const std::string& optarg);
  74. virtual std::string createPossibleValuesString() const;
  75. };
  76. class IntegerRangeOptionHandler : public NameMatchOptionHandler {
  77. private:
  78. int32_t min_;
  79. int32_t max_;
  80. public:
  81. IntegerRangeOptionHandler(const std::string& optName,
  82. const std::string& description,
  83. const std::string& defaultValue,
  84. int32_t min, int32_t max,
  85. char shortName = 0);
  86. virtual ~IntegerRangeOptionHandler();
  87. virtual void parseArg(Option& option, const std::string& optarg);
  88. virtual std::string createPossibleValuesString() const;
  89. };
  90. class NumberOptionHandler : public NameMatchOptionHandler {
  91. private:
  92. int64_t min_;
  93. int64_t max_;
  94. public:
  95. NumberOptionHandler(const std::string& optName,
  96. const std::string& description = NO_DESCRIPTION,
  97. const std::string& defaultValue = NO_DEFAULT_VALUE,
  98. int64_t min = -1,
  99. int64_t max = -1,
  100. char shortName = 0);
  101. virtual ~NumberOptionHandler();
  102. virtual void parseArg(Option& option, const std::string& optarg);
  103. void parseArg(Option& option, int64_t number);
  104. virtual std::string createPossibleValuesString() const;
  105. };
  106. class UnitNumberOptionHandler : public NumberOptionHandler {
  107. public:
  108. UnitNumberOptionHandler(const std::string& optName,
  109. const std::string& description = NO_DESCRIPTION,
  110. const std::string& defaultValue = NO_DEFAULT_VALUE,
  111. int64_t min = -1,
  112. int64_t max = -1,
  113. char shortName = 0);
  114. virtual ~UnitNumberOptionHandler();
  115. virtual void parseArg(Option& option, const std::string& optarg);
  116. };
  117. class FloatNumberOptionHandler : public NameMatchOptionHandler {
  118. private:
  119. double min_;
  120. double max_;
  121. public:
  122. FloatNumberOptionHandler(const std::string& optName,
  123. const std::string& description = NO_DESCRIPTION,
  124. const std::string& defaultValue = NO_DEFAULT_VALUE,
  125. double min = -1, double max = -1,
  126. char shortName = 0);
  127. virtual ~FloatNumberOptionHandler();
  128. virtual void parseArg(Option& option, const std::string& optarg);
  129. virtual std::string createPossibleValuesString() const;
  130. };
  131. class DefaultOptionHandler : public NameMatchOptionHandler {
  132. private:
  133. std::string possibleValuesString_;
  134. public:
  135. DefaultOptionHandler(const std::string& optName,
  136. const std::string& description = NO_DESCRIPTION,
  137. const std::string& defaultValue = NO_DEFAULT_VALUE,
  138. const std::string& possibleValuesString = A2STR::NIL,
  139. OptionHandler::ARG_TYPE argType = OptionHandler::REQ_ARG,
  140. char shortName = 0);
  141. virtual ~DefaultOptionHandler();
  142. virtual void parseArg(Option& option, const std::string& optarg);
  143. virtual std::string createPossibleValuesString() const;
  144. };
  145. class CumulativeOptionHandler : public NameMatchOptionHandler {
  146. private:
  147. std::string delim_;
  148. std::string possibleValuesString_;
  149. public:
  150. CumulativeOptionHandler(const std::string& optName,
  151. const std::string& description,
  152. const std::string& defaultValue,
  153. const std::string& delim,
  154. const std::string& possibleValuesString = A2STR::NIL,
  155. OptionHandler::ARG_TYPE argType =
  156. OptionHandler::REQ_ARG,
  157. char shortName = 0);
  158. virtual ~CumulativeOptionHandler();
  159. virtual void parseArg(Option& option, const std::string& optarg);
  160. virtual std::string createPossibleValuesString() const;
  161. };
  162. class IndexOutOptionHandler : public NameMatchOptionHandler {
  163. private:
  164. public:
  165. IndexOutOptionHandler(const std::string& optName,
  166. const std::string& description,
  167. char shortName = 0);
  168. virtual ~IndexOutOptionHandler();
  169. virtual void parseArg(Option& option, const std::string& optarg);
  170. virtual std::string createPossibleValuesString() const;
  171. };
  172. class ParameterOptionHandler : public NameMatchOptionHandler {
  173. private:
  174. std::vector<std::string> validParamValues_;
  175. public:
  176. ParameterOptionHandler(const std::string& optName,
  177. const std::string& description,
  178. const std::string& defaultValue,
  179. const std::vector<std::string>& validParamValues,
  180. char shortName = 0);
  181. ParameterOptionHandler(const std::string& optName,
  182. const std::string& description,
  183. const std::string& defaultValue,
  184. const std::string& validParamValue,
  185. char shortName = 0);
  186. ParameterOptionHandler(const std::string& optName,
  187. const std::string& description,
  188. const std::string& defaultValue,
  189. const std::string& validParamValue1,
  190. const std::string& validParamValue2,
  191. char shortName = 0);
  192. ParameterOptionHandler(const std::string& optName,
  193. const std::string& description,
  194. const std::string& defaultValue,
  195. const std::string& validParamValue1,
  196. const std::string& validParamValue2,
  197. const std::string& validParamValue3,
  198. char shortName = 0);
  199. virtual ~ParameterOptionHandler();
  200. virtual void parseArg(Option& option, const std::string& optarg);
  201. virtual std::string createPossibleValuesString() const;
  202. };
  203. class HostPortOptionHandler : public NameMatchOptionHandler {
  204. private:
  205. std::string hostOptionName_;
  206. std::string portOptionName_;
  207. public:
  208. HostPortOptionHandler(const std::string& optName,
  209. const std::string& description,
  210. const std::string& defaultValue,
  211. const std::string& hostOptionName,
  212. const std::string& portOptionName,
  213. char shortName = 0);
  214. virtual ~HostPortOptionHandler();
  215. virtual void parseArg(Option& option, const std::string& optarg);
  216. void setHostAndPort
  217. (Option& option, const std::string& hostname, uint16_t port);
  218. virtual std::string createPossibleValuesString() const;
  219. };
  220. class HttpProxyUserOptionHandler:public NameMatchOptionHandler {
  221. public:
  222. HttpProxyUserOptionHandler(const std::string& optName,
  223. const std::string& description,
  224. const std::string& defaultValue,
  225. char shortName = 0);
  226. virtual void parseArg(Option& option, const std::string& optarg);
  227. virtual std::string createPossibleValuesString() const;
  228. };
  229. class HttpProxyPasswdOptionHandler:public NameMatchOptionHandler {
  230. public:
  231. HttpProxyPasswdOptionHandler(const std::string& optName,
  232. const std::string& description,
  233. const std::string& defaultValue,
  234. char shortName = 0);
  235. virtual void parseArg(Option& option, const std::string& optarg);
  236. virtual std::string createPossibleValuesString() const;
  237. };
  238. class HttpProxyOptionHandler : public NameMatchOptionHandler {
  239. private:
  240. std::string proxyUserPref_;
  241. std::string proxyPasswdPref_;
  242. public:
  243. HttpProxyOptionHandler(const std::string& optName,
  244. const std::string& description,
  245. const std::string& defaultValue,
  246. char shortName = 0);
  247. virtual ~HttpProxyOptionHandler();
  248. virtual void parseArg(Option& option, const std::string& optarg);
  249. virtual std::string createPossibleValuesString() const;
  250. };
  251. class LocalFilePathOptionHandler : public NameMatchOptionHandler {
  252. private:
  253. bool acceptStdin_;
  254. public:
  255. LocalFilePathOptionHandler
  256. (const std::string& optName,
  257. const std::string& description = NO_DESCRIPTION,
  258. const std::string& defaultValue = NO_DEFAULT_VALUE,
  259. bool acceptStdin = false,
  260. char shortName = 0);
  261. virtual void parseArg(Option& option, const std::string& optarg);
  262. virtual std::string createPossibleValuesString() const;
  263. };
  264. class PrioritizePieceOptionHandler:public NameMatchOptionHandler {
  265. public:
  266. PrioritizePieceOptionHandler
  267. (const std::string& optName,
  268. const std::string& description = NO_DESCRIPTION,
  269. const std::string& defaultValue = NO_DEFAULT_VALUE,
  270. char shortName = 0);
  271. virtual void parseArg(Option& option, const std::string& optarg);
  272. virtual std::string createPossibleValuesString() const;
  273. };
  274. // This class is used to deprecate option and optionally handle its
  275. // option value using replacing option.
  276. class DeprecatedOptionHandler:public OptionHandler {
  277. private:
  278. SharedHandle<OptionHandler> depOptHandler_;
  279. SharedHandle<OptionHandler> repOptHandler_;
  280. public:
  281. // depOptHandler is deprecated option and repOptHandler is replacing
  282. // new option. If there is no replacing option, omit second
  283. // argument.
  284. DeprecatedOptionHandler
  285. (const SharedHandle<OptionHandler>& depOptHandler,
  286. const SharedHandle<OptionHandler>& repOptHandler =
  287. SharedHandle<OptionHandler>());
  288. virtual bool canHandle(const std::string& optName);
  289. virtual void parse(Option& option, const std::string& arg);
  290. virtual std::string createPossibleValuesString() const;
  291. virtual bool hasTag(const std::string& tag) const;
  292. virtual void addTag(const std::string& tag);
  293. virtual std::string toTagString() const;
  294. virtual const std::string& getName() const;
  295. virtual const std::string& getDescription() const;
  296. virtual const std::string& getDefaultValue() const;
  297. virtual bool isHidden() const;
  298. virtual void hide();
  299. virtual ARG_TYPE getArgType() const;
  300. virtual char getShortName() const;
  301. virtual int getOptionID() const;
  302. virtual void setOptionID(int id);
  303. virtual bool getEraseAfterParse() const;
  304. virtual void setEraseAfterParse(bool eraseAfterParse);
  305. };
  306. } // namespace aria2
  307. #endif // D_OPTION_HANDLER_IMPL_H