diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llcommandlineparser.h | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/linden/indra/newview/llcommandlineparser.h b/linden/indra/newview/llcommandlineparser.h new file mode 100644 index 0000000..e281871 --- /dev/null +++ b/linden/indra/newview/llcommandlineparser.h | |||
@@ -0,0 +1,166 @@ | |||
1 | /** | ||
2 | * @file llcommandlineparser.h | ||
3 | * @brief LLCommandLineParser class declaration | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #ifndef LL_LLCOMMANDLINEPARSER_H | ||
33 | #define LL_LLCOMMANDLINEPARSER_H | ||
34 | |||
35 | #include <boost/function/function1.hpp> | ||
36 | |||
37 | // *NOTE:Mani The following is a forward decl of | ||
38 | // boost::program_options::command_line_parser | ||
39 | // "yay" c++! | ||
40 | namespace boost | ||
41 | { | ||
42 | namespace program_options | ||
43 | { | ||
44 | template <class charT> class basic_command_line_parser; | ||
45 | typedef basic_command_line_parser<char> command_line_parser; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | |||
50 | /** | ||
51 | * @class LLCommandLineParser | ||
52 | * @brief Handle defining and parsing the command line. | ||
53 | */ | ||
54 | class LLCommandLineParser | ||
55 | { | ||
56 | public: | ||
57 | typedef std::vector< std::string > token_vector_t; | ||
58 | |||
59 | /** | ||
60 | * @brief Add a value-less option to the command line description. | ||
61 | * @param option_name The long name of the cmd-line option. | ||
62 | * @param description The text description of the option usage. | ||
63 | */ | ||
64 | void addOptionDesc( | ||
65 | const LLString& option_name, | ||
66 | boost::function1<void, const token_vector_t&> notify_callback = 0, | ||
67 | unsigned int num_tokens = 0, | ||
68 | const LLString& description = LLString::null, | ||
69 | const LLString& short_name = LLString::null, | ||
70 | bool composing = false, | ||
71 | bool positional = false, | ||
72 | bool last_option = false); | ||
73 | |||
74 | /** | ||
75 | * @brief Parse the command line given by argc/argv. | ||
76 | */ | ||
77 | bool parseCommandLine(int argc, char **argv); | ||
78 | |||
79 | /** | ||
80 | * @brief Parse the command line contained by the given file. | ||
81 | */ | ||
82 | bool parseCommandLineString(const std::string& str); | ||
83 | |||
84 | /** | ||
85 | * @brief Parse the command line contained by the given file. | ||
86 | */ | ||
87 | bool parseCommandLineFile(const std::basic_istream< char >& file); | ||
88 | |||
89 | /** | ||
90 | * @brief Call callbacks associated with option descriptions. | ||
91 | * | ||
92 | * Use this to handle the results of parsing. | ||
93 | */ | ||
94 | void notify(); | ||
95 | |||
96 | /** @brief Print a description of the configured options. | ||
97 | * | ||
98 | * Use this to print a description of options to the | ||
99 | * given ostream. Useful for displaying usage info. | ||
100 | */ | ||
101 | std::ostream& printOptionsDesc(std::ostream& os) const; | ||
102 | |||
103 | /** @brief Manual option setting accessors. | ||
104 | * | ||
105 | * Use these to retrieve get the values set for an option. | ||
106 | * getOption will return an empty value if the option isn't | ||
107 | * set. | ||
108 | */ | ||
109 | bool hasOption(const std::string& name) const; | ||
110 | const token_vector_t& getOption(const std::string& name) const; | ||
111 | |||
112 | /** @brief Print the list of configured options. | ||
113 | */ | ||
114 | void printOptions() const; | ||
115 | |||
116 | /** @bried Get the error message, if it exists. | ||
117 | */ | ||
118 | const std::string& getErrorMessage() const { return mErrorMsg; } | ||
119 | |||
120 | /** @brief Add a custom parser func to the parser. | ||
121 | * | ||
122 | * Use this method to add a custom parser for parsing values | ||
123 | * the the simple parser may not handle. | ||
124 | * it will be applied to each parameter before the | ||
125 | * default parser gets a chance. | ||
126 | * The parser_func takes an input string, and should return a | ||
127 | * name/value pair as the result. | ||
128 | */ | ||
129 | typedef boost::function1<std::pair<std::string, std::string>, const std::string&> parser_func; | ||
130 | void setCustomParser(parser_func f) { mExtraParser = f; } | ||
131 | |||
132 | private: | ||
133 | bool parseAndStoreResults(boost::program_options::command_line_parser& clp); | ||
134 | std::string mErrorMsg; | ||
135 | parser_func mExtraParser; | ||
136 | }; | ||
137 | |||
138 | inline std::ostream& operator<<(std::ostream& out, const LLCommandLineParser& clp) | ||
139 | { | ||
140 | return clp.printOptionsDesc(out); | ||
141 | } | ||
142 | |||
143 | class LLControlGroup; | ||
144 | |||
145 | /** | ||
146 | * @class LLControlGroupCLP | ||
147 | * @brief Uses the CLP to configure an LLControlGroup | ||
148 | * | ||
149 | * | ||
150 | */ | ||
151 | class LLControlGroupCLP : public LLCommandLineParser | ||
152 | { | ||
153 | public: | ||
154 | /** | ||
155 | * @brief Configure the command line parser according the given config file. | ||
156 | * | ||
157 | * @param config_filename The name of the XML based LLSD config file. | ||
158 | * @param clp A reference to the command line parser object to configure. | ||
159 | * | ||
160 | * *FIX:Mani Specify config file format. | ||
161 | */ | ||
162 | void configure(const LLString& config_filename, | ||
163 | LLControlGroup* controlGroup); | ||
164 | }; | ||
165 | |||
166 | #endif // LL_LLCOMMANDLINEPARSER_H | ||