00001
00002 #ifndef getopt_doc_HEADER
00003 #define getopt_doc_HEADER
00004
00005 #ifdef HAVE_CONFIG_H
00006 #include <config.h>
00007 #endif
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <string>
00040 #include <vector>
00041
00042 namespace hudson {
00043 struct CommandLine;
00044
00045 struct OptionSet {
00046 OptionSet();
00047 ~OptionSet();
00048
00049
00050
00051 void addFlag(
00052 const std::string& name,
00053 const std::string& description,
00054 bool *output);
00055
00056
00057 void addOption(
00058 const std::string& name,
00059 const std::string& variable_description,
00060 const std::string& description,
00061 std::string *output);
00062
00063
00064 void addIntOption(
00065 const std::string& name,
00066 const std::string& variable_description,
00067 const std::string& description,
00068 int *output);
00069
00070
00071 void addFloatOption(
00072 const std::string& name,
00073 const std::string& variable_description,
00074 const std::string& description,
00075 double *output
00076 );
00077
00078
00079 void addSynonym(
00080 const std::string& canonical,
00081 const std::string& alternate);
00082
00083
00084
00085 void addSpacer(const std::string& message);
00086
00087 void print();
00088
00089 private:
00090 friend struct CommandLine;
00091 struct guts;
00092 guts *guts_;
00093 };
00094
00095 struct CommandLine {
00096 typedef std::vector<std::string> Arguments;
00097
00098 CommandLine(const OptionSet&, int argc, const char * const *argv);
00099 CommandLine(const OptionSet&, const Arguments&);
00100 const Arguments& getArguments() const { return args; }
00101
00102 bool hasNext() { return !done; }
00103 bool readNext();
00104 bool process() {
00105 bool ok = true;
00106 while(hasNext()) {
00107 bool success = readNext();
00108 ok = success && ok;
00109 }
00110 return ok;
00111 }
00112
00113 unsigned index() { return current_index; }
00114
00115 void printUsageAndExit(int exitval, const std::string& arguments,
00116 const std::string& description);
00117
00118 private:
00119 void checkNext();
00120 bool interpret(const std::string& option);
00121
00122 Arguments args;
00123 const OptionSet& opts;
00124 unsigned current_index;
00125 bool done;
00126 };
00127 };
00128
00129
00130
00131 #endif