Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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 
00042 #ifndef __CCXX_CMDOPTNS_H__
00043 #define __CCXX_CMDOPTNS_H__
00044 
00045 #ifndef __CCXX_CONFIG_H__
00046 #include <cc++/config.h>
00047 #endif
00048 
00049 #ifdef  __NAMESPACES__
00050 namespace ost {
00051 #endif
00052 
00053 #ifdef HAVE_GETOPT_LONG
00054 
00062 class CommandOption;
00063 class CommandOptionParse;
00064 
00072 extern CommandOption * DefaultCommandOptionList;
00073 
00084 class CommandOption {
00085 public:
00086 
00091         const char      * option_name;
00092         
00097         const char      * option_letter;
00098 
00104         const char      * description;
00105 
00111         enum OptionType {
00115                 HasArg,
00119                 NoArg,
00123                 Trailing,
00127                 Collect
00128         };
00129 
00133         OptionType        option_type;  // HasArg, NoArg or Trailing
00134 
00139         bool              required;             // Option is required - fail without it
00140 
00145         CommandOption   * next;
00146                 
00150         virtual ~CommandOption();
00151 
00163         CommandOption(
00164                 const char              * in_option_name,
00165                 const char              * in_option_letter,
00166                 const char              * in_description,
00167                 OptionType                in_option_type,
00168                 bool                      in_required = false,
00169                 CommandOption  ** pp_next = & DefaultCommandOptionList
00170         );
00171 
00179         virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 );
00180         
00189         virtual void FoundOption( CommandOptionParse * cop, const char ** value, int num );
00190         
00197         virtual void ParseDone( CommandOptionParse * cop );
00198         
00206         virtual void PerformTask( CommandOptionParse * cop );
00207 
00214         virtual bool HasValue();
00215         
00216 };
00217 
00222 class CommandOptionWithArg : public CommandOption {
00223 public:
00224 
00228         const char ** values;
00229 
00233         int                       numvalue;
00234 
00246         CommandOptionWithArg(
00247                 const char              * in_option_name,
00248                 const char              * in_option_letter,
00249                 const char              * in_description,
00250                 OptionType                in_option_type,
00251                 bool                      in_required = false,
00252                 CommandOption  ** pp_next = & DefaultCommandOptionList
00253         );
00254 
00255         virtual ~CommandOptionWithArg();
00256         
00257         virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 );
00258         virtual void FoundOption( CommandOptionParse * cop, const char ** value, int num );
00259         virtual bool HasValue();
00260 };
00261         
00265 class CommandOptionArg : public CommandOptionWithArg {
00266 public:
00267 
00278         CommandOptionArg(
00279                 const char              * in_option_name,
00280                 const char              * in_option_letter,
00281                 const char              * in_description,
00282                 bool                      in_required = false,
00283                 CommandOption  ** pp_next = & DefaultCommandOptionList
00284         );
00285 
00286         virtual ~CommandOptionArg();
00287         
00288 
00289 };
00290         
00300 class CommandOptionRest : public CommandOptionWithArg {
00301 public:
00302 
00313         CommandOptionRest(
00314                 const char              * in_option_name,
00315                 const char              * in_option_letter,
00316                 const char              * in_description,
00317                 bool                      in_required = false,
00318                 CommandOption  ** pp_next = & DefaultCommandOptionList
00319         );
00320 
00321 };
00322         
00330 class CommandOptionCollect : public CommandOptionWithArg {
00331 public:
00332 
00343         CommandOptionCollect(
00344                 const char              * in_option_name,
00345                 const char              * in_option_letter,
00346                 const char              * in_description,
00347                 bool                      in_required = false,
00348                 CommandOption  ** pp_next = & DefaultCommandOptionList
00349         );
00350 
00351 };
00352         
00356 class CommandOptionNoArg : public CommandOption {
00357 public:
00358 
00362         int                       numset;       // The number of times this argument is set
00363 
00374         CommandOptionNoArg(
00375                 const char              * in_option_name,
00376                 const char              * in_option_letter,
00377                 const char              * in_description,
00378                 bool                      in_required = false,
00379                 CommandOption  ** pp_next = & DefaultCommandOptionList
00380         );
00381 
00385         virtual void FoundOption( CommandOptionParse * cop, const char * value = 0 );
00386 
00387 };
00388 
00398 class CommandOptionParse {
00399 public:
00400 
00404         virtual ~CommandOptionParse() = 0;
00405 
00409         virtual bool ArgsHaveError() = 0;
00410 
00414         virtual const char * PrintErrors() = 0;
00415 
00419         virtual const char * PrintUsage() = 0;
00420 
00425         virtual void RegisterError( const char * err_msg ) = 0;
00426 
00431         virtual void PerformTask() = 0;
00432 
00433 };
00434 
00443 CommandOptionParse * MakeCommandOptionParse(
00444         int                                argc,
00445         char                    ** argv,
00446         char                     * comment,
00447         CommandOption    * options = DefaultCommandOptionList
00448 );
00449 #endif
00450 
00451 #ifdef  __NAMESPACES__
00452 };
00453 #endif
00454 
00455 #endif
00456 

Generated at Tue Nov 20 12:34:33 2001 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001