Source: include/parameters.H


Annotated List
Files
Globals
Hierarchy
Index
/* -------------------------------------------------------------------------
   parameters.H - Class Which Handles Primary Parameter Parsing
   -------------------------------------------------------------------------
   Copyright (C) 2000 Eric R. Schendel
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               
   ------------------------------------------------------------------------- */

#ifndef PARAM_H
#define PARAM_H

#include <string>
#include <vector>

#include "status.H"

namespace GlobalParameters {

using namespace StatusMsgs;

const char GP_NULL[] = "";
const char GP_FILENAME[] = "cmdfile";

const char OPT_HELP[] = "-h";
const char OPT_VERBOSE[] = "-v";
const char OPT_VERSION[] = "-V";

const char OPTL_HELP[] = "--help";
const char OPTL_VERSION[] = "--version";

/***
 * Basic parameters class. This is a good place to have all general parsing
 * operations. Also, help and version parameters are handled by this class
 * mostly because all programs have them. All HpTrans programs and tools will
 * have parameters to specify log display levels, therefore all that
 * functionality will also be included in this class.
 */
class Parameters {

   public:

      Parameters();
      virtual ~Parameters() {; }

      /***
       * IMPORTANT TO FILL IN DESCRIPTION & RECOMMAND CALLING FIRST
       */
      virtual Error parseCommandLine(const int&, char**, const char** = 0,
                                     const char** = 0);

      virtual void setCmdFileName(string n) { name = n; }
      virtual void setVerboseLevel(const LogLevel);

      virtual string getCmdFileName() const { return name; }
      virtual LogLevel getLogLevel() const { return level; }
      virtual vector < string > getArguments() const { return arguments; }

      virtual bool isHelpSet() const { return help; }
      virtual bool isVersionSet() const { return version; }

      virtual void printHelp() const = 0;

   protected:

      bool get_option_arg(string&, const string, const int&, char**);
      bool check_bool_option(const char**, const int&, char**);

   private:

      static const char* GP_BASIC_OPTIONS[];
      static const char* GP_BASIC_HAVE_ARGS[];

      vector < string > arguments;

      string name;

      LogLevel level;

      bool help;
      bool version;

      Log log;

      Error parse_verbose(const int&, char**);
      Error validate_parameters(const int&, char**, const char**);
      Error parse_arguments(const int&, char**, const char**);

      bool check_valid_option(const string&, const char**);

      void parse_help(const int&, char**);
      void parse_version(const int&, char**);

};

}

#endif

Generated on Fri Mar 9 02:04:42 2001, using kdoc 2.0a43.