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_ABSTRACT_OPTION_HANDLER_H
36 #define D_ABSTRACT_OPTION_HANDLER_H
37 
38 #include "OptionHandler.h"
39 
40 namespace aria2 {
41 
42 class Option;
43 struct Pref;
44 
45 class AbstractOptionHandler : public OptionHandler {
46 protected:
47   PrefPtr pref_;
48 
49   const char* description_;
50 
51   std::string defaultValue_;
52 
53   OptionHandler::ARG_TYPE argType_;
54 
55   char shortName_;
56 
57   virtual void parseArg(Option& option, const std::string& arg) const = 0;
58 
59 public:
60   AbstractOptionHandler(PrefPtr pref, const char* description = NO_DESCRIPTION,
61                         const std::string& defaultValue = NO_DEFAULT_VALUE,
62                         ARG_TYPE argType = REQ_ARG, char shortName = 0);
63 
64   virtual ~AbstractOptionHandler();
65 
66   virtual void parse(Option& option,
67                      const std::string& arg) const CXX11_OVERRIDE;
68 
69   virtual bool hasTag(uint32_t tag) const CXX11_OVERRIDE;
70 
71   virtual void addTag(uint32_t tag) CXX11_OVERRIDE;
72 
73   virtual std::string toTagString() const CXX11_OVERRIDE;
74 
75   virtual const char* getName() const CXX11_OVERRIDE;
76 
getDescription()77   virtual const char* getDescription() const CXX11_OVERRIDE
78   {
79     return description_;
80   }
81 
getDefaultValue()82   virtual const std::string& getDefaultValue() const CXX11_OVERRIDE
83   {
84     return defaultValue_;
85   }
86 
getPref()87   virtual PrefPtr getPref() const CXX11_OVERRIDE { return pref_; }
88 
getShortName()89   virtual char getShortName() const CXX11_OVERRIDE { return shortName_; }
90 
getArgType()91   virtual OptionHandler::ARG_TYPE getArgType() const CXX11_OVERRIDE
92   {
93     return argType_;
94   }
95 
96   virtual bool isHidden() const CXX11_OVERRIDE;
97 
98   virtual void hide() CXX11_OVERRIDE;
99 
100   virtual bool getEraseAfterParse() const CXX11_OVERRIDE;
101 
102   virtual void setEraseAfterParse(bool f) CXX11_OVERRIDE;
103 
104   virtual bool getInitialOption() const CXX11_OVERRIDE;
105 
106   virtual void setInitialOption(bool f) CXX11_OVERRIDE;
107 
108   virtual bool getChangeOption() const CXX11_OVERRIDE;
109 
110   virtual void setChangeOption(bool f) CXX11_OVERRIDE;
111 
112   virtual bool getChangeOptionForReserved() const CXX11_OVERRIDE;
113 
114   virtual void setChangeOptionForReserved(bool f) CXX11_OVERRIDE;
115 
116   virtual bool getChangeGlobalOption() const CXX11_OVERRIDE;
117 
118   virtual void setChangeGlobalOption(bool f) CXX11_OVERRIDE;
119 
120   virtual bool getCumulative() const CXX11_OVERRIDE;
121 
122   virtual void setCumulative(bool f) CXX11_OVERRIDE;
123 
124   enum Flag {
125     FLAG_HIDDEN = 1,
126     FLAG_ERASE_AFTER_PARSE = 1 << 1,
127     FLAG_INITIAL_OPTION = 1 << 2,
128     FLAG_CHANGE_OPTION = 1 << 3,
129     FLAG_CHANGE_OPTION_FOR_RESERVED = 1 << 4,
130     FLAG_CHANGE_GLOBAL_OPTION = 1 << 5,
131     FLAG_CUMULATIVE = 1 << 6
132   };
133 
134 private:
135   // bitwise OR of (1 << HelpTag value) defined in help_tags.h.
136   uint32_t tags_;
137 
138   // bitwise OR of Flag values.
139   uint8_t flags_;
140 
141   void updateFlags(int flag, bool val);
142 };
143 
144 } // namespace aria2
145 
146 #endif // D_ABSTRACT_OPTION_HANDLER_H
147