00001
00032 #ifndef LL_LLCOMMANDLINEPARSER_H
00033 #define LL_LLCOMMANDLINEPARSER_H
00034
00035 #include <boost/function/function1.hpp>
00036
00037
00038
00039
00040 namespace boost
00041 {
00042 namespace program_options
00043 {
00044 template <class charT> class basic_command_line_parser;
00045 typedef basic_command_line_parser<char> command_line_parser;
00046 }
00047 }
00048
00049
00054 class LLCommandLineParser
00055 {
00056 public:
00057 typedef std::vector< std::string > token_vector_t;
00058
00064 void addOptionDesc(
00065 const LLString& option_name,
00066 boost::function1<void, const token_vector_t&> notify_callback = 0,
00067 unsigned int num_tokens = 0,
00068 const LLString& description = LLString::null,
00069 const LLString& short_name = LLString::null,
00070 bool composing = false,
00071 bool positional = false,
00072 bool last_option = false);
00073
00077 bool parseCommandLine(int argc, char **argv);
00078
00082 bool parseCommandLineString(const std::string& str);
00083
00087 bool parseCommandLineFile(const std::basic_istream< char >& file);
00088
00094 void notify();
00095
00101 std::ostream& printOptionsDesc(std::ostream& os) const;
00102
00109 bool hasOption(const std::string& name) const;
00110 const token_vector_t& getOption(const std::string& name) const;
00111
00114 void printOptions() const;
00115
00118 const std::string& getErrorMessage() const { return mErrorMsg; }
00119
00129 typedef boost::function1<std::pair<std::string, std::string>, const std::string&> parser_func;
00130 void setCustomParser(parser_func f) { mExtraParser = f; }
00131
00132 private:
00133 bool parseAndStoreResults(boost::program_options::command_line_parser& clp);
00134 std::string mErrorMsg;
00135 parser_func mExtraParser;
00136 };
00137
00138 inline std::ostream& operator<<(std::ostream& out, const LLCommandLineParser& clp)
00139 {
00140 return clp.printOptionsDesc(out);
00141 }
00142
00143 class LLControlGroup;
00144
00151 class LLControlGroupCLP : public LLCommandLineParser
00152 {
00153 public:
00162 void configure(const LLString& config_filename,
00163 LLControlGroup* controlGroup);
00164 };
00165
00166 #endif // LL_LLCOMMANDLINEPARSER_H