00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #if !defined(AFX_ARGPARSER_H__F5D7DE2F_967A_44B0_A2DF_423F96B02EC0__INCLUDED_)
00027 #define AFX_ARGPARSER_H__F5D7DE2F_967A_44B0_A2DF_423F96B02EC0__INCLUDED_
00028
00029 #include <list>
00030 #include <map>
00031 #include <string>
00032
00033 class ARGParserBoolI
00034 {
00035 public:
00036 virtual ~ARGParserBoolI() {}
00037 virtual bool setBoolArgument(bool value) = 0;
00038 };
00039
00040 class ARGParserIntI
00041 {
00042 public:
00043 virtual ~ARGParserIntI() {}
00044 virtual bool setIntArgument(int value) = 0;
00045 };
00046
00047 class ARGParserStringI
00048 {
00049 public:
00050 virtual ~ARGParserStringI() {}
00051 virtual bool setStringArgument(const char *value) = 0;
00052 };
00053
00054 class ARGParser
00055 {
00056 public:
00057 ARGParser();
00058 virtual ~ARGParser();
00059
00060 bool parse(char *lpCmdLine);
00061 bool parse(int argc,char *argv[]);
00062 void addEntry(char *cmd, char **destStr, char *help = "");
00063 void addEntry(char *cmd, int *destI, char *help = "");
00064 void addEntry(char *cmd, bool *destB, char *help = "");
00065
00066 void addEntry(char *cmd, ARGParserBoolI *destBool, char *help = "");
00067 void addEntry(char *cmd, ARGParserIntI *destInt, char *help = "");
00068 void addEntry(char *cmd, ARGParserStringI *destString, char *help = "");
00069
00070 void addNonParamEntry(char *cmd, ARGParserStringI *destString, char *help = "");
00071
00072 void showArgs(char *topString = NULL);
00073
00074 protected:
00075 struct Entry
00076 {
00077 Entry(ARGParserBoolI *destBoolArg = 0,
00078 ARGParserIntI *destIntArg = 0,
00079 ARGParserStringI *destStringArg = 0,
00080 char **destCArg = 0,
00081 int *destIArg = 0,
00082 bool *destBArg = 0,
00083 char *helpArg = "");
00084
00085 ARGParserBoolI *destBool;
00086 ARGParserIntI *destInt;
00087 ARGParserStringI *destString;
00088 char **destC;
00089 int *destI;
00090 bool *destB;
00091 std::string help;
00092 };
00093
00094 std::map<std::string, Entry> argMap_;
00095 std::map<std::string, Entry> nonParamMap_;
00096 void addNewEntry(char *cmd, ARGParser::Entry &entry);
00097 bool parseLineIntoStrings(char *line, std::list<std::string> &cmdLine);
00098 bool parseArg(ARGParser::Entry &newEntry, std::list<std::string> &cmdLine);
00099 };
00100
00101 #endif // !defined(AFX_ARGPARSER_H__F5D7DE2F_967A_44B0_A2DF_423F96B02EC0__INCLUDED_)