00001 #ifndef _theplu_yat_utility_commandline_
00002 #define _theplu_yat_utility_commandline_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <cctype>
00026 #include <map>
00027 #include <iosfwd>
00028 #include <sstream>
00029 #include <stdexcept>
00030 #include <string>
00031 #include <typeinfo>
00032 #include <utility>
00033 #include <vector>
00034
00035 namespace theplu {
00036 namespace yat {
00037 namespace utility {
00038
00039 class Option;
00040
00096 class CommandLine
00097 {
00098 public:
00104 CommandLine(std::string str="Available options are:");
00105
00109 virtual ~CommandLine(void);
00110
00114 void add(Option&);
00115
00122 void allow_free_args(size_t n);
00123
00129 const std::vector<std::string>& free_args(void) const;
00130
00141 void parse(int argc, char* argv[]);
00142
00150 bool parsed(void) const;
00151
00156 std::string program_name(void) const;
00157
00162 std::string try_help(void) const;
00163
00164 private:
00165 friend std::ostream& operator<<(std::ostream& os, const CommandLine& cl);
00166 void add_private(std::string, Option&);
00167 bool is_long_option(std::string str) const;
00168 bool is_short_option(std::string str) const;
00169 std::vector<std::string> split(std::string str, char del) const;
00170
00171 std::string description_;
00172 std::vector<std::string> free_arg_;
00173 size_t free_arg_max_;
00174 std::vector<Option*> options_;
00175 std::map<char, Option*> short_options_;
00176 std::map<std::string, Option*> long_options_;
00177 bool parsed_;
00178 std::string program_name_;
00179 };
00180
00199 std::ostream& operator<<(std::ostream&, const CommandLine&);
00200
00201 }}}
00202
00203 #endif