command_line.h

Go to the documentation of this file.
00001 #ifndef COMMAND_LINE_CLASS
00002 #define COMMAND_LINE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 * Name   : command_line                                                       *
00007 * Author : Chris Koeritz                                                      *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00019 
00037 #include "opsysdll.h"
00038 
00039 #include <basis/object_base.h>
00040 
00041 // forward:
00042 class filename;
00043 class internal_cmd_line_array_of_parms;
00044 
00046 
00047 class OPSYSTEM_CLASS_STYLE command_parameter
00048 : public virtual object_base
00049 {
00050 public:
00051   enum parameter_types { VALUE, CHAR_FLAG, STRING_FLAG, BOGUS_ITEM };
00052 
00053   command_parameter(parameter_types type = BOGUS_ITEM);
00055 
00056   command_parameter(parameter_types type, const istring &text);
00058 
00061   command_parameter(const command_parameter &to_copy);
00062 
00063   ~command_parameter();
00064 
00065   IMPLEMENT_CLASS_NAME("command_parameter");
00066 
00067   command_parameter &operator =(const command_parameter &to_copy);
00068 
00069   inline parameter_types type() const { return _type; }
00071   inline void type(parameter_types new_type) { _type = new_type; }
00073 
00074   const istring &text() const;
00076   void text(const istring &new_text);
00078 
00079 private:
00080   parameter_types _type;
00081   istring *_text;
00082 };
00083 
00085 
00086 class OPSYSTEM_CLASS_STYLE command_line
00087 {
00088 public:
00089   command_line(int argc, char *argv[]);
00091 
00096   command_line(const istring &to_parse);
00098 
00103   virtual ~command_line();
00104 
00105   IMPLEMENT_CLASS_NAME("command_line");
00106 
00107   filename program_name() const;
00109 
00110   static void separate_command_line(const istring &cmd_line, istring &app,
00111           istring &parms);
00113 
00121   int entries() const;
00123 
00126   const command_parameter &get(int field) const;
00128 
00131   bool zap(int field);
00133 
00136   // note: in the following, if "case_sense" is true, then the searches are
00137   //       case-sensitive.  otherwise, case of the flags is not a concern.
00138   //       the returned values always retain the original case.
00139 
00140   bool find(char option_character, int &index, bool case_sense = true) const;
00142 
00145   bool find(const istring &option_string, int &index,
00146           bool case_sense = true) const;
00148 
00149   bool get_value(char option_character, istring &value,
00150           bool case_sense = true) const;
00152 
00157   bool get_value(const istring &option_string, istring &value,
00158           bool case_sense = true) const;
00160 
00161 //is this useful?  it's kind of like what we need for special flags (like
00162 //  -fgob.h, where gob.h is a value parameter) but needs to terminate
00163 //differently for that to work.
00164   istring gather(int &index) const;
00166 
00176   istring text_form() const;
00178 
00179   static string_array get_command_line();
00181 
00185 private:
00186   internal_cmd_line_array_of_parms *_implementation;  
00187   filename *_program_name;  
00188 
00189   void parse_string_array(const string_array &to_parse);
00191 
00192   // forbidden:
00193   command_line(const command_line &to_copy);
00194   command_line &operator =(const command_line &to_copy);
00195 
00196   static const command_parameter &cmdline_blank_parm();
00197 };
00198 
00199 #endif
00200 

Generated on Fri Nov 28 04:29:21 2008 for HOOPLE Libraries by  doxygen 1.5.1