ARGParser.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 
00022 // ARGParser.h: interface for the ARGParser class.
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_)

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3