00001 /* 00002 00003 ************************************************************************* 00004 00005 ArmageTron -- Just another Tron Lightcycle Game in 3D. 00006 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) 00007 Copyright (C) 2004 Armagetron Advanced Team (http://sourceforge.net/projects/armagetronad/) 00008 00009 ************************************************************************** 00010 00011 This program is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License 00013 as published by the Free Software Foundation; either version 2 00014 of the License, or (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program; if not, write to the Free Software 00023 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 00025 *************************************************************************** 00026 00027 */ 00028 00029 #ifndef TCOMMANDLINE_H_INCLUDED 00030 #define TCOMMANDLINE_H_INCLUDED 00031 00032 // self include 00033 #ifndef TCOMMANDLINE_H_INCLUDED 00034 #include "tCommandLine.h" 00035 #endif 00036 00037 #include "tString.h" 00038 00039 #include "tLinkedList.h" 00040 00042 struct tCommandLineData 00043 { 00044 tString* programVersion_; 00045 tString name_; 00046 00047 bool Analyse(int argc,char **argv ); 00048 bool Execute(); 00049 00051 tCommandLineData() 00052 : doc_(false) 00053 { 00054 programVersion_ = NULL; 00055 } 00056 00057 private: 00058 bool doc_; 00059 }; 00060 00062 struct tCommandLineParser 00063 { 00064 public: 00065 bool GetSwitch( char const * option, char const * option_short=NULL ); 00066 bool GetOption( tString & target, char const * option, char const * option_short=NULL ); 00067 00068 bool End() const; 00069 00070 const char * Executable() const; 00071 const char * Current() const; 00072 void Advance(); 00073 00074 tCommandLineParser( int argc, char ** argv ); 00075 private: 00076 tCommandLineParser(); 00077 00078 const int argc; 00079 char * * argv; 00080 int index; 00081 }; 00082 00083 00085 class tCommandLineAnalyzer: public tListItem< tCommandLineAnalyzer > 00086 { 00087 public: 00088 tCommandLineAnalyzer(); 00089 ~tCommandLineAnalyzer(); 00090 00091 inline void Initialize( tCommandLineParser & parser ); 00092 inline bool Analyze( tCommandLineParser & parser ); 00093 inline void Help( std::ostream & s ); 00094 private: 00095 virtual void DoInitialize( tCommandLineParser & parser ); 00096 virtual bool DoAnalyze( tCommandLineParser & parser ) = 0; 00097 virtual void DoHelp( std::ostream & s ) = 0; 00098 }; 00099 00100 // ******************************************************************************************* 00101 // * 00102 // * Initialize 00103 // * 00104 // ******************************************************************************************* 00108 // ******************************************************************************************* 00109 00110 void tCommandLineAnalyzer::Initialize( tCommandLineParser & parser ) 00111 { 00112 DoInitialize( parser ); 00113 } 00114 00115 // ******************************************************************************************* 00116 // * 00117 // * Analyze 00118 // * 00119 // ******************************************************************************************* 00124 // ******************************************************************************************* 00125 00126 bool tCommandLineAnalyzer::Analyze( tCommandLineParser & parser ) 00127 { 00128 return DoAnalyze( parser ); 00129 } 00130 00131 // ******************************************************************************************* 00132 // * 00133 // * Help 00134 // * 00135 // ******************************************************************************************* 00139 // ******************************************************************************************* 00140 00141 void tCommandLineAnalyzer::Help( std::ostream & s ) 00142 { 00143 DoHelp( s ); 00144 } 00145 00146 #endif // TCOMMANDLINE_H_INCLUDED