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
00026 #include <cctype>
00027 #include <map>
00028 #include <iostream>
00029 #include <sstream>
00030 #include <stdexcept>
00031 #include <string>
00032 #include <typeinfo>
00033 #include <utility>
00034 #include <vector>
00035
00036 namespace theplu {
00037 namespace yat {
00038 namespace utility {
00039
00040 class Option;
00041
00094 class CommandLine
00095 {
00096 public:
00102 CommandLine(std::string str="Available options are:");
00103
00107 virtual ~CommandLine(void);
00108
00112 void add(Option&);
00113
00120 void allow_free_args(size_t n);
00121
00127 const std::vector<std::string>& free_args(void) const;
00128
00134 void parse(int argc, char* argv[]);
00135
00143 bool parsed(void) const;
00144
00149 std::string program_name(void) const;
00150
00155 std::string try_help(void) const;
00156
00157 private:
00158 friend std::ostream& operator<<(std::ostream& os, const CommandLine& cl);
00159 void add_private(std::string, Option&);
00160 bool is_long_option(std::string str) const;
00161 bool is_short_option(std::string str) const;
00162 std::vector<std::string> split(std::string str, char del) const;
00163
00164 std::string description_;
00165 std::vector<std::string> free_arg_;
00166 size_t free_arg_max_;
00167 std::vector<Option*> options_;
00168 std::map<char, Option*> short_options_;
00169 std::map<std::string, Option*> long_options_;
00170 bool parsed_;
00171 std::string program_name_;
00172 };
00173
00190 std::ostream& operator<<(std::ostream&, const CommandLine&);
00191
00192 }}}
00193
00194 #endif