![]()
|
cmdoptns.hGo to the documentation of this file.00001 // Copyright (C) 2001 Gianni Mariani 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 // As a special exception to the GNU General Public License, permission is 00018 // granted for additional uses of the text contained in its release 00019 // of Common C++. 00020 // 00021 // The exception is that, if you link the Common C++ library with other 00022 // files to produce an executable, this does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public License. 00024 // Your use of that executable is in no way restricted on account of 00025 // linking the Common C++ library code into it. 00026 // 00027 // This exception does not however invalidate any other reasons why 00028 // the executable file might be covered by the GNU General Public License. 00029 // 00030 // This exception applies only to the code released under the 00031 // name Common C++. If you copy code from other releases into a copy of 00032 // Common C++, as the General Public License permits, the exception does 00033 // not apply to the code that you add in this way. To avoid misleading 00034 // anyone as to the status of such modified files, you must delete 00035 // this exception notice from them. 00036 // 00037 // If you write modifications of your own for Common C++, it is your choice 00038 // whether to permit this exception to apply to your modifications. 00039 // If you do not wish that, delete this exception notice. 00040 // 00041 00042 #ifndef __CCXX_CMDOPTNS_H__ 00043 #define __CCXX_CMDOPTNS_H__ 00044 00045 #include "config.h" 00046 00047 #ifdef HAVE_GETOPT_LONG 00048 00056 class CommandOption; 00057 class CommandOptionParse; 00058 00066 extern CommandOption * DefaultCommandOptionList; 00067 00078 class CommandOption { 00079 public: 00080 00085 const char * option_name; 00086 00091 const char * option_letter; 00092 00098 const char * description; 00099 00105 enum OptionType { 00109 HasArg, 00113 NoArg, 00117 Trailing, 00121 Collect 00122 }; 00123 00127 OptionType option_type; // HasArg, NoArg or Trailing 00128 00133 bool required; // Option is required - fail without it 00134 00139 CommandOption * next; 00140 00144 virtual ~CommandOption(); 00145 00157 CommandOption( 00158 const char * in_option_name, 00159 const char * in_option_letter, 00160 const char * in_description, 00161 OptionType in_option_type, 00162 bool in_required = false, 00163 CommandOption ** pp_next = & DefaultCommandOptionList 00164 ); 00165 00173 virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 ); 00174 00183 virtual void FoundOption( CommandOptionParse * cop, const char ** value, int num ); 00184 00191 virtual void ParseDone( CommandOptionParse * cop ); 00192 00200 virtual void PerformTask( CommandOptionParse * cop ); 00201 00208 virtual bool HasValue(); 00209 00210 }; 00211 00216 class CommandOptionWithArg : public CommandOption { 00217 public: 00218 00222 const char ** values; 00223 00227 int numvalue; 00228 00240 CommandOptionWithArg( 00241 const char * in_option_name, 00242 const char * in_option_letter, 00243 const char * in_description, 00244 OptionType in_option_type, 00245 bool in_required = false, 00246 CommandOption ** pp_next = & DefaultCommandOptionList 00247 ); 00248 00249 virtual ~CommandOptionWithArg(); 00250 00251 virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 ); 00252 virtual void FoundOption( CommandOptionParse * cop, const char ** value, int num ); 00253 virtual bool HasValue(); 00254 }; 00255 00259 class CommandOptionArg : public CommandOptionWithArg { 00260 public: 00261 00272 CommandOptionArg( 00273 const char * in_option_name, 00274 const char * in_option_letter, 00275 const char * in_description, 00276 bool in_required = false, 00277 CommandOption ** pp_next = & DefaultCommandOptionList 00278 ); 00279 00280 virtual ~CommandOptionArg(); 00281 00282 00283 }; 00284 00294 class CommandOptionRest : public CommandOptionWithArg { 00295 public: 00296 00307 CommandOptionRest( 00308 const char * in_option_name, 00309 const char * in_option_letter, 00310 const char * in_description, 00311 bool in_required = false, 00312 CommandOption ** pp_next = & DefaultCommandOptionList 00313 ); 00314 00315 }; 00316 00324 class CommandOptionCollect : public CommandOptionWithArg { 00325 public: 00326 00337 CommandOptionCollect( 00338 const char * in_option_name, 00339 const char * in_option_letter, 00340 const char * in_description, 00341 bool in_required = false, 00342 CommandOption ** pp_next = & DefaultCommandOptionList 00343 ); 00344 00345 }; 00346 00350 class CommandOptionNoArg : public CommandOption { 00351 public: 00352 00356 int numset; // The number of times this argument is set 00357 00368 CommandOptionNoArg( 00369 const char * in_option_name, 00370 const char * in_option_letter, 00371 const char * in_description, 00372 bool in_required = false, 00373 CommandOption ** pp_next = & DefaultCommandOptionList 00374 ); 00375 00379 virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 ); 00380 00381 }; 00382 00392 class CommandOptionParse { 00393 public: 00394 00398 virtual ~CommandOptionParse() = 0; 00399 00403 virtual bool ArgsHaveError() = 0; 00404 00408 virtual const char * PrintErrors() = 0; 00409 00413 virtual const char * PrintUsage() = 0; 00414 00419 virtual void RegisterError( const char * err_msg ) = 0; 00420 00425 virtual void PerformTask() = 0; 00426 00427 }; 00428 00437 CommandOptionParse * MakeCommandOptionParse( 00438 int argc, 00439 char ** argv, 00440 char * comment, 00441 CommandOption * options = DefaultCommandOptionList 00442 ); 00443 00444 00445 #endif 00446 #endif 00447 Generated at Fri Mar 23 10:47:54 2001 for CommonC++ by ![]() |