00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __UT_Args_H__
00021 #define __UT_Args_H__
00022
00023 #include "UT_API.h"
00024 #include <stdlib.h>
00025 #include <SYS/SYS_Types.h>
00026 #include "UT_WorkArgs.h"
00027 #include "UT_Assert.h"
00028
00029 #define UT_MAX_OPTIONS 4 // A maximum of three args following
00030
00031 class UT_WorkBuffer;
00032 class UT_String;
00033
00034 class UT_API UT_Args {
00035 public:
00036 UT_Args();
00037 virtual ~UT_Args();
00038
00039 int argc() const { return my_argc; }
00040 char *argv(unsigned i) { return myArgv(i); }
00041 const char *argv(unsigned i) const { return myArgv(i); }
00042 char **argv() { return myArgv.getArgv(); }
00043 const char **argv() const { return myArgv.getArgv(); }
00044 char *operator[](unsigned i) { return (i < my_argc) ? argv(i) : 0; }
00045 char *operator()(unsigned i)
00046 {
00047 UT_ASSERT_P(i < my_argc);
00048 return argv(i);
00049 }
00050
00051 int found(int opt) const
00052 {
00053 UT_ASSERT_P(opt >= 0 && opt < 128);
00054 return my_found[opt];
00055 }
00056 char *argp(int opt, int which=0)
00057 {
00058 UT_ASSERT_P(opt >= 0 && opt < 128);
00059 UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
00060 return my_opt[opt][which];
00061 }
00062 char *argp2(int opt)
00063 {
00064 return my_opt[opt][1];
00065 }
00066 char *argp3(int opt)
00067 {
00068 UT_ASSERT_P(opt >= 0 && opt < 128);
00069 return my_opt[opt][2];
00070 }
00071
00072 fpreal fargp(int opt, int which=0) const
00073 {
00074 UT_ASSERT_P(opt >= 0 && opt < 128);
00075 UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
00076 return atof(my_opt[opt][which]);
00077 }
00078 fpreal fargp2(int opt) const
00079 {
00080 UT_ASSERT_P(opt >= 0 && opt < 128);
00081 return fargp(opt, 1);
00082 }
00083 fpreal fargp3(int opt) const
00084 {
00085 UT_ASSERT_P(opt >= 0 && opt < 128);
00086 return fargp(opt, 2);
00087 }
00088
00089 int iargp(int opt, int which=0) const
00090 {
00091 UT_ASSERT_P(opt >= 0 && opt < 128);
00092 UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
00093 return atoi(my_opt[opt][which]);
00094 }
00095 int iargp2(int opt) const { return (int)fargp(opt, 1); }
00096 int iargp3(int opt) const { return (int)fargp(opt, 2); }
00097
00098 void initialize(int argc, char *argv[]);
00099 void appendArg(char *arg);
00100 void stripOptions(const char *options);
00101
00102
00103
00104
00105 int fillCommandLine(UT_WorkBuffer &buf,
00106 int first_arg=0,
00107 int include_options=1) const;
00108
00109
00110
00111
00112 void makeCommandLine(UT_String &str, int first_arg=1) const;
00113
00114
00115
00116
00117
00118 void setArgument(int idx, char *text);
00119
00120 void display();
00121
00122 private:
00123 int my_argc;
00124 UT_WorkArgs myArgv;
00125 char my_found[128];
00126 char *my_opt [128][UT_MAX_OPTIONS];
00127 };
00128 #endif