00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023 #ifndef CLP_INCLUDED
00024 #define CLP_INCLUDED
00025
00026 #include <iostream>
00027 #include <map>
00028 #include <set>
00029 #include <vector>
00030
00031 class CLS{
00032 private:
00033 std::string _name;
00034 std::string _shortName;
00035 std::string _description;
00036 unsigned _numberOfSwitchArguments;
00037 std::vector<std::string> _switchArguments;
00038 bool _isSet;
00039
00040 public:
00041 CLS(std::string name, std::string shortName, std::string description, unsigned numberOfSwitchArguments);
00042 void setSwitch(void) { _isSet = true; }
00043 void addSwitchArgument(std::string argument) { _switchArguments.push_back(argument); }
00044 void resetSwitch() { _isSet = false; }
00045 unsigned getNumberOfSwitchArguments(void) { return _numberOfSwitchArguments; }
00046 bool isSet(void){ return _isSet; }
00047 std::string getSwitchArgument(unsigned index){ return _switchArguments[index]; }
00048 const std::string getDescription(void){ return _description; }
00049 const std::string getShortName(void){ return _shortName; }
00050 };
00051
00052 class CLP{
00053
00054 private:
00055 std::string _usage;
00056 std::map<std::string,std::string> _shortSwitchMapping;
00057 std::map<std::string, CLS> _switches;
00058 std::vector<std::string> _arguments;
00059 std::vector<std::string> _networkArguments;
00060 std::vector<std::string> _mysqlArguments;
00061 const static std::string _NETWORK_TYPE;
00062 const static std::string _NETWORK_TYPE_SECURE;
00063 const static std::string _MYSQL_TYPE;
00064 void _setSwitchArguments(std::string currentSwitch,int argc,char* argv[],int& currentIndex,CLS& cls);
00065 void _processMysqlArguments(std::string argument);
00066 std::string _getShortSwitchNameMapping(const std::string& shortName);
00067 bool _shortNameExists(const std::string& shortName);
00068
00069 public:
00070 void addUsage(const std::string usage);
00071 void addSwitch(std::string name,std::string shortName,std::string description,unsigned numberOfArguments=0);
00072 std::string getSwitchArgument(std::string name,unsigned index);
00073 bool parse(int argc,char* argv[]);
00074 bool hasSwitchSet(std::string name);
00075 const std::vector<std::string>& getArguments();
00076 const std::vector<std::string>& getNetworkArguments();
00077 const std::vector<std::string>& getMysqlArguments();
00078 bool hasMysqlArguments(){ if(_mysqlArguments.size()) return true; return false; }
00079
00080 void printHelp();
00081 void printArguments();
00082
00083 };
00084
00085 #endif