Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

cmdoptns.h

Go 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 
00047 #ifndef CCXX_CMDOPTNS_H_
00048 #define CCXX_CMDOPTNS_H_
00049 
00050 #ifndef CCXX_STRING_H_
00051 #include <cc++/string.h>
00052 #endif
00053 
00054 #ifdef  CCXX_NAMESPACES
00055 namespace ost {
00056 #endif
00057 
00058 class CommandOption;
00059 class CommandOptionParse;
00060 
00068 extern __EXPORT CommandOption * defaultCommandOptionList;
00069 
00080 class __EXPORT CommandOption {
00081 public:
00082 
00087         const char      * optionName;
00088 
00093         const char      * optionLetter;
00094 
00100         const char      * description;
00101 
00107         enum OptionType {
00111                 hasArg,
00115                 noArg,
00119                 trailing,
00123                 collect
00124         };
00125 
00129         OptionType        optionType;   // HasArg, NoArg or Trailing
00130 
00135         bool              required;             // Option is required - fail without it
00136 
00141         CommandOption   * next;
00142                 
00146         virtual ~CommandOption();
00147 
00159         CommandOption(
00160                 const char              * inOptionName,
00161                 const char              * inOptionLetter,
00162                 const char              * inDescription,
00163                 OptionType                inOptionType,
00164                 bool                      inRequired = false,
00165                 CommandOption  ** ppNext = & defaultCommandOptionList
00166         );
00167 
00175         virtual void foundOption( CommandOptionParse * cop, const char * value = 0 );
00176         
00185         virtual void foundOption( CommandOptionParse * cop, const char ** value, int num );
00186         
00193         virtual void parseDone( CommandOptionParse * cop );
00194         
00202         virtual void performTask( CommandOptionParse * cop );
00203 
00210         virtual bool hasValue();
00211         
00212 };
00213 
00218 class __EXPORT CommandOptionWithArg : public CommandOption {
00219 public:
00220 
00224         const char ** values;
00225 
00229         int                       numValue;
00230 
00242         CommandOptionWithArg(
00243                 const char              * inOptionName,
00244                 const char              * inOptionLetter,
00245                 const char              * inDescription,
00246                 OptionType                inOptionType,
00247                 bool                      inRequired = false,
00248                 CommandOption  ** ppNext = & defaultCommandOptionList
00249         );
00250 
00251         virtual ~CommandOptionWithArg();
00252         
00253         virtual void foundOption( CommandOptionParse * cop, const char * value = 0 );
00254         virtual void foundOption( CommandOptionParse * cop, const char ** value, int num );
00255         virtual bool hasValue();
00256 };
00257         
00261 class __EXPORT CommandOptionArg : public CommandOptionWithArg {
00262 public:
00263 
00274         CommandOptionArg(
00275                 const char              * inOptionName,
00276                 const char              * inOptionLetter,
00277                 const char              * inDescription,
00278                 bool                      inRequired = false,
00279                 CommandOption  ** ppNext = & defaultCommandOptionList
00280         );
00281 
00282         virtual ~CommandOptionArg();
00283 
00284 
00285 };
00286         
00296 class __EXPORT CommandOptionRest : public CommandOptionWithArg {
00297 public:
00298 
00309         CommandOptionRest(
00310                 const char              * inOptionName,
00311                 const char              * inOptionLetter,
00312                 const char              * inDescription,
00313                 bool                      inRequired = false,
00314                 CommandOption  ** ppNext = & defaultCommandOptionList
00315         );
00316 
00317 };
00318         
00326 class __EXPORT CommandOptionCollect : public CommandOptionWithArg {
00327 public:
00328 
00339         CommandOptionCollect(
00340                 const char              * inOptionName,
00341                 const char              * inOptionLetter,
00342                 const char              * inDescription,
00343                 bool                      inRequired = false,
00344                 CommandOption  ** ppNext = & defaultCommandOptionList
00345         );
00346 
00347 };
00348         
00352 class __EXPORT CommandOptionNoArg : public CommandOption {
00353 public:
00354 
00358         int                       numSet;       // The number of times this argument is set
00359 
00370         CommandOptionNoArg(
00371                 const char              * inOptionName,
00372                 const char              * inOptionLetter,
00373                 const char              * inDescription,
00374                 bool                      inRequired = false,
00375                 CommandOption  ** ppNext = & defaultCommandOptionList
00376         );
00377 
00381         virtual void foundOption( CommandOptionParse * cop, const char * value = 0 );
00382 
00383 };
00384 
00394 class __EXPORT CommandOptionParse {
00395 public:
00396 
00400         virtual ~CommandOptionParse() = 0;
00401 
00405         virtual bool argsHaveError() = 0;
00406 
00410         virtual const char * printErrors() = 0;
00411 
00415         virtual const char * printUsage() = 0;
00416 
00421         virtual void registerError( const char * errMsg ) = 0;
00422 
00427         virtual void performTask() = 0;
00428 
00429 };
00430 
00439 __EXPORT CommandOptionParse * makeCommandOptionParse(
00440         int                                argc,
00441         char                    ** argv,
00442         char                     * comment,
00443         CommandOption    * options = defaultCommandOptionList
00444 );
00445 
00446 #ifdef  CCXX_NAMESPACES
00447 }
00448 #endif
00449 
00450 #endif
00451 

Generated on Tue Jan 18 14:32:36 2005 for GNU CommonC++ by  doxygen 1.3.9.1