1
/**********************************************************************
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
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.
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
***********************************************************************/
14
#ifndef __COMMANDLINE_H_
15
#define __COMMANDLINE_H_
35
vector<string> arguments;
47
// constructor with Help string
48
ArgumentInfo( const string & help) : argtyp(-2), numargs(1), argvar(NULL),
49
found(false), list(false), hasArgument(false),
53
typedef map<string, ArgumentInfo, less<string> > maptype;
66
void SetVariable(ArgumentInfo &, char[]);
70
CommandLine() { switches = 0; usage = NULL; arglist = ""; _exitOnError= false; }
71
CommandLine(bool exitOnError) { switches = 0; usage = NULL; arglist = ""; _exitOnError= exitOnError; }
72
virtual ~CommandLine() {}
74
// Switch/Flag with no Arguments
76
void AddFlag( const char *, bool &var, bool list = false );
77
void AddFlag( const char *, char *hlp, bool list = false );
79
// Switch/Flag followed by Multiple Arguments
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 );
87
// Switch/Flag followed by Single Argument (with default value)
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 );
95
int ProcessArguments( char *argv[], int argc );
96
int ProcessArguments( int argc, char *argv[] ) { return ProcessArguments(argv, argc); }
98
bool WasCalledWith(const char *);
99
bool HasArgument(const char *arg);
101
char *GetArgument(const char *,int i = 0);
102
char *GetArgList(void) { return (char *)arglist.c_str(); }
104
void SetUsageFunction(void (*fxn)(void));
105
virtual void Usage();
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);
114
bool getValue(const char *s, int &f);
115
bool getValue(const char *s, float &f);
116
bool getValue(const char *s, string &ret);