~vcs-imports/openbabel/trunk

« back to all changes in this revision

Viewing changes to commandline.h

  • Committer: ghutchis
  • Date: 2001-11-27 18:50:36 UTC
  • Revision ID: svn-v4:86f38270-e075-4da6-bf68-7dcd545c500b:openbabel/trunk:46
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
 
3
 
 
4
This program is free software; you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation version 2 of the License.
 
7
 
 
8
This program is distributed in the hope that it will be useful,
 
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
GNU General Public License for more details.
 
12
***********************************************************************/
 
13
 
 
14
#ifndef __COMMANDLINE_H_
 
15
#define __COMMANDLINE_H_
 
16
 
 
17
#include <stdlib.h>
 
18
 
 
19
#include <string>
 
20
#include <vector>
 
21
#include <map>
 
22
 
 
23
using namespace std;
 
24
 
 
25
class ArgumentInfo
 
26
{
 
27
 public:
 
28
  int      argtyp;
 
29
  int      numargs;
 
30
  void    *argvar;
 
31
  bool     found;
 
32
  bool     list;
 
33
  bool     hasArgument;
 
34
  string   helpString;
 
35
  vector<string> arguments;
 
36
 
 
37
  ArgumentInfo() {
 
38
    numargs = 1;
 
39
    argvar  = NULL;
 
40
    argtyp  = -2;
 
41
    found   = false;
 
42
    list    = false;
 
43
    hasArgument = false;
 
44
    helpString= "";
 
45
  }
 
46
 
 
47
  // constructor with Help string 
 
48
  ArgumentInfo( const string & help) : argtyp(-2), numargs(1), argvar(NULL), 
 
49
                                found(false), list(false), hasArgument(false),
 
50
                                helpString(help) {}
 
51
};
 
52
 
 
53
typedef map<string, ArgumentInfo, less<string> > maptype;
 
54
 
 
55
class CommandLine
 
56
{
 
57
 protected:
 
58
  
 
59
  int argc, switches;
 
60
  char **argv;
 
61
  string arglist;
 
62
 
 
63
  maptype cmdline;
 
64
  void (*usage)(void);
 
65
  
 
66
  void SetVariable(ArgumentInfo &, char[]);
 
67
  bool _exitOnError;
 
68
 public:
 
69
  
 
70
  CommandLine() { switches = 0; usage = NULL; arglist = ""; _exitOnError= false; }
 
71
  CommandLine(bool exitOnError) { switches = 0; usage = NULL; arglist = ""; _exitOnError= exitOnError; }
 
72
  virtual ~CommandLine() {}
 
73
 
 
74
  // Switch/Flag with no Arguments
 
75
  
 
76
  void AddFlag( const char *, bool &var, bool list = false );
 
77
  void AddFlag( const char *, char *hlp, bool list = false );
 
78
 
 
79
  // Switch/Flag followed by Multiple Arguments
 
80
 
 
81
  void AddSwitch( const char *, int numargs,          bool list = false );
 
82
  void AddSwitch( const char *, vector<int>    &,     bool list = false );
 
83
  void AddSwitch( const char *, vector<float>  &,     bool list = false );
 
84
  void AddSwitch( const char *, vector<string> &,     bool list = false );
 
85
  void AddSwitch( const char *, void (*)(void *),     bool list = false );
 
86
 
 
87
  // Switch/Flag followed by Single Argument (with default value)
 
88
 
 
89
  void AddSwitch( const char *, bool   &, bool   def, bool list = false );
 
90
  void AddSwitch( const char *, int    &, int    def, bool list = false );
 
91
  void AddSwitch( const char *, float  &, float  def, bool list = false );
 
92
  void AddSwitch( const char *, char   *, char  *def, bool list = false );
 
93
  void AddSwitch( const char *, string &, string def, bool list = false );
 
94
 
 
95
  int ProcessArguments( char *argv[], int argc );
 
96
  int ProcessArguments( int argc, char *argv[] ) { return ProcessArguments(argv, argc); }
 
97
 
 
98
  bool WasCalledWith(const char *);
 
99
  bool HasArgument(const char *arg);
 
100
 
 
101
  char *GetArgument(const char *,int i = 0);
 
102
  char *GetArgList(void) { return (char *)arglist.c_str(); }
 
103
 
 
104
  void SetUsageFunction(void (*fxn)(void));
 
105
  virtual void Usage();
 
106
 
 
107
  // Add switched with help string
 
108
  void AddSwitch(const char *arg, string &var, string def, const char *help, bool list= false);
 
109
  void AddSwitch(const char *arg, int &var, int def, const char *help, bool list= false);
 
110
  void AddSwitch(const char *arg, float &var, float def, const char *help, bool list= false);
 
111
 
 
112
  void printHelp();
 
113
 
 
114
  bool getValue(const char *s, int &f);     
 
115
  bool getValue(const char *s, float &f);   
 
116
  bool getValue(const char *s, string &ret);
 
117
};
 
118
 
 
119
#endif
 
120