00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SWORD_BASE_COMMANDLINEMANAGER_
00020 #define _SWORD_BASE_COMMANDLINEMANAGER_
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "base.CommandLineOptionBase.h"
00032 #include "base.CommandLineOption.h"
00033 #include "base.CommandLineFlag.h"
00034 #include <vector>
00035
00036 namespace sword {
00037
00039
00105 class SWORDDECL CommandLineManager {
00106 friend class CommandLineOptionBase;
00107 public:
00109
00121 CommandLineManager(
00122 const std::string &title,
00123 const std::string &version,
00124 const std::string ©right,
00125 const std::string &usage,
00126 int &argc,
00127 char **argv,
00128 bool fail=true);
00129
00131 void help(std::ostream &os) const;
00132
00134 void version(std::ostream &os) const;
00135
00137 bool wantHelp() const;
00138
00140 bool wantVersion() const;
00141
00143
00144 void process();
00145
00147 size_t size() const;
00148
00149 class ParsingException : public Exception {};
00150 class DuplicateOptionException : public Exception {};
00151
00152 private:
00153 std::string title_;
00154 std::string version_;
00155 std::string copyright_;
00156 std::string usage_;
00157 int &argc_;
00158 char **argv_;
00159 bool fail_;
00160
00161 typedef std::vector<CommandLineOptionBase*> Options;
00162 Options options_;
00163 std::string programName_;
00164
00165 CommandLineFlag<bool> optionHelp_;
00166 CommandLineFlag<bool> optionVersion_;
00167
00168 void add_(CommandLineOptionBase* option);
00169 void remove_(CommandLineOptionBase* option);
00170 void handleShortOption_(int &i);
00171 void handleLongOption_(int &i);
00172 void cleanup_();
00173
00174 private:
00175 CommandLineManager(const CommandLineManager &rhs);
00176 CommandLineManager &operator=(const CommandLineManager &rhs);
00177 };
00178
00179 }
00180
00181 #endif // _SWORD_BASE_COMMANDLINEMANAGER_