00001 #pragma ident "$Id: CommandOptionParser.hpp 160 2006-09-29 14:51:56Z architest $"
00002
00003
00004
00010 #ifndef COMMANDOPTIONPARSER_HPP
00011 #define COMMANDOPTIONPARSER_HPP
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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "CommandOption.hpp"
00055
00056 #include <vector>
00057 #include <map>
00058 #include <ostream>
00059
00060 namespace gpstk
00061 {
00064
00092 class CommandOptionParser
00093 {
00094 public:
00097 typedef std::map<std::string, gpstk::CommandOption*> CommandOptionMap;
00098
00105 CommandOptionParser(const std::string& description,
00106 const CommandOptionVec optList =
00107 defaultCommandOptionList)
00108 : optionVec(optList), hasRequiredArguments(false),
00109 hasOptionalArguments(false), text(description)
00110
00111 {}
00112
00114 CommandOptionParser& addOption(gpstk::CommandOption& co)
00115 { optionVec.push_back(&co); return *this; }
00116
00118 void parseOptions(int argc, char* argv[]);
00119
00121 bool hasErrors() { return !errorStrings.empty(); }
00123 std::ostream& dumpErrors(std::ostream& out);
00124
00129 std::ostream& displayUsage(std::ostream& out, bool doPretty=true);
00130
00131 private:
00133 void resizeOptionArray(struct option* &oldArray, unsigned long& oldSize);
00134
00136 CommandOptionVec optionVec;
00138 std::vector<std::string> errorStrings;
00140
00141
00143 bool hasRequiredArguments;
00145 bool hasOptionalArguments;
00146
00148 std::string text;
00149
00151 std::string progName;
00152 };
00154 }
00155
00156 #endif