FONTAINE
1.0
|
00001 00002 // 00003 // This file is part of the MADELINE 2 program 00004 // written by Edward H. Trager and Ritu Khanna 00005 // Copyright (c) 2005 by the 00006 // Regents of the University of Michigan. 00007 // All Rights Reserved. 00008 // 00009 // The latest version of this program is available from: 00010 // 00011 // http://eyegene.ophthy.med.umich.edu/madeline/ 00012 // 00013 // Released under the GNU General Public License. 00014 // A copy of the GPL is included in the distribution 00015 // package of this software, or see: 00016 // 00017 // http://www.gnu.org/copyleft/ 00018 // 00019 // ... for licensing details. 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) const{ return _description; } 00049 const std::string getShortName(void) const{ return _shortName; } 00050 }; 00051 00052 class CLP{ 00053 00054 private: 00055 00056 std::string _name; 00057 std::string _version; 00058 std::string _copyright; 00059 std::string _url; 00060 std::string _usage; 00061 00062 std::map<std::string,std::string> _shortSwitchMapping; 00063 std::map<std::string, CLS> _switches; 00064 std::vector<std::string> _arguments; 00065 std::vector<std::string> _networkArguments; 00066 std::vector<std::string> _mysqlArguments; 00067 const static std::string _NETWORK_TYPE; 00068 const static std::string _NETWORK_TYPE_SECURE; 00069 const static std::string _MYSQL_TYPE; 00070 void _setSwitchArguments(std::string currentSwitch,unsigned int argc,const char* argv[],unsigned int& currentIndex,CLS& cls); 00071 void _processMysqlArguments(std::string argument); 00072 std::string _getShortSwitchNameMapping(const std::string& shortName); 00073 bool _shortNameExists(const std::string& shortName); 00074 00075 public: 00076 00077 // CONSTRUCTOR: 00078 CLP(std::string name,std::string version,std::string copyright,std::string url,std::string usage); 00079 00080 void addUsage(const std::string usage); 00081 void addSwitch(std::string name,std::string shortName,std::string description,unsigned numberOfArguments=0); 00082 std::string getSwitchArgument(std::string name,unsigned index); 00083 bool parse(unsigned int argc,const char* argv[]); 00084 bool hasSwitchSet(std::string name); 00085 const std::vector<std::string>& getArguments(); 00086 const std::vector<std::string>& getNetworkArguments(); 00087 const std::vector<std::string>& getMysqlArguments(); 00088 bool hasMysqlArguments(){ if(_mysqlArguments.size()) return true; return false; } 00089 00090 void printCopyrightNotice() const; 00091 void printHelp() const; 00092 void printArguments() const; 00093 00094 }; 00095 00096 #endif