00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__CommandLine_H__
00010 #define __libutilxx__sella__util__CommandLine_H__
00011
00012 #include "../../common.h"
00013
00014 #include "CommandLineOption.h"
00015
00016 #include <stdio.h>
00017 #include <getopt.h>
00018 #include <values.h>
00019
00020 #include <exception>
00021 #include <string>
00022 #include <list>
00023 #include <map>
00024
00025 namespace sella {
00026 namespace util {
00027 class CommandLine;
00028 }
00029 }
00030
00031 class sella::util::CommandLine {
00032 public:
00033 CommandLine(int argc, char **argv) throw ();
00034
00035 CommandLine(const CommandLine ©) throw ();
00036 virtual ~CommandLine() throw ();
00037
00038 public:
00039 CommandLine& operator=(const CommandLine &other) throw ();
00040
00041 public:
00042 void add(char opt, const std::string &option, const std::string &usage, const std::string &label = "", const std::string &value = "") throw ();
00043 void add(char opt, const std::string &option, const std::string &usage, const std::string &label, long value, long min = MINLONG, long max = MINLONG) throw ();
00044 void add(const CommandLineOption &option = CommandLineOption()) throw ();
00045 void add(const std::string &argument, const std::string &usage) throw ();
00046
00047 std::map<std::string, std::string> parse(FILE *stream) const throw ();
00048 void usage(FILE *stream, int result = 0) const throw ();
00049
00050 protected:
00051 struct option build(char tag, const std::string &name, bool argument) const throw ();
00052 const std::string tag(char tag, bool argument) const throw ();
00053
00054 private:
00055 int argc;
00056 char **argv;
00057
00058 std::list<CommandLineOption> option;
00059 std::list<std::pair<std::string, std::string>> argument;
00060
00061 size_t width;
00062 };
00063
00064 #endif
00065
00066
00067
00068