ESLA
Embeddable Scriting LAnguage
Stanford University, Rock Fracture Project research group
© 2003
00001 /************************************************************************* 00002 * ESLA: Embeddable Scripting LAnguage 00003 * Copyright (C) 2003 Frantz Maerten 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License as 00007 * published by the Free Software Foundation; either version 2 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * If you modify this software, you should contact the author, include 00011 * a notice giving the name of the person performing the modification, 00012 * the date of modification, and the reason for such modification. 00013 * 00014 * Note that the GNU General Public License does not permit 00015 * incorporating the Software into proprietary programs. 00016 * 00017 * Contact: Frantz Maerten 00018 * frantz@pangea.stanford.edu 00019 * 00020 * Dept. of Geological & Environmental Sciences 00021 * Stanford University 00022 * Stanford, CA 94305-2115 00023 * USA 00024 *************************************************************************/ 00025 00026 00027 #ifndef P3DTOOLS_BASIC_UTILS_COMMAND_ARGS_H__ 00028 #define P3DTOOLS_BASIC_UTILS_COMMAND_ARGS_H__ 00029 00030 #include "../esla_namespace.h" 00031 00032 BEGIN_LIB_NAMESPACE 00033 00037 class CommandArgs { 00038 public: 00039 CommandArgs(int argc, char** argv); 00040 CommandArgs(char* argv); 00041 ~CommandArgs(); 00042 00043 // return value is index of first excess argument 00044 int excess_arguments (); 00045 00046 // Set bounds for numerical arguments. If bounds are required, they must 00047 // be set for each argument. 00048 CommandArgs& min(double dValue); 00049 CommandArgs& max(double dValue); 00050 CommandArgs& inf(double dValue); 00051 CommandArgs& sup(double dValue); 00052 00053 // The return value of the following methods is the option index within 00054 // the argument array. Which means that if the methods return 0, the option 00055 // is not define within the command line arguments. 00056 // 00057 // Use the boolean methods for options which take no argument, for 00058 // example in 00059 // myprogram -debug -x 10 -y 20 filename 00060 // the option -debug has no argument. 00061 int get_bool(char* acName);// returns existence of option 00062 int get_bool(char* acName, bool& rbValue); 00063 int get_int(char* acName, int& riValue); 00064 int get_float(char* acName, float& rfValue); 00065 int get_double(char* acName, double& rdValue); 00066 int get_string(char* acName, char*& racValue); 00067 int get_filename(char*& racName); 00068 00069 // last error reporting 00070 const char* last_error(); 00071 00072 protected: 00073 // constructor support 00074 void initialize (); 00075 00076 // command line information 00077 int m_iQuantity; // number of arguments 00078 char** m_apcArgument; // argument list (array of strings) 00079 char* m_acCmdline; // argument list (single string) 00080 bool* m_abUsed; // keeps track of arguments already processed 00081 00082 // parameters for bounds checking 00083 double m_dSmall; // lower bound for numerical argument (min or inf) 00084 double m_dLarge; // upper bound for numerical argument (max or sup) 00085 bool m_bMinSet; // if true, compare: small <= arg 00086 bool m_bMaxSet; // if true, compare: arg <= large 00087 bool m_bInfSet; // if true, compare: small < arg 00088 bool m_bSupSet; // if true, compare: arg < large 00089 00090 // last error strings 00091 const char* m_acLastError; 00092 static char ms_acOptionNotFound[]; 00093 static char ms_acArgumentRequired[]; 00094 static char ms_acArgumentOutOfRange[]; 00095 static char ms_acFilenameNotFound[]; 00096 }; 00097 00098 END_LIB_NAMESPACE 00099 00100 #endif 00101 00102 00103 00104