HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Args.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Command Library (C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_Args_H__
13 #define __UT_Args_H__
14 
15 #include "UT_API.h"
16 #include "UT_WorkArgs.h"
17 #include "UT_Assert.h"
18 #include <stdlib.h>
19 #include <SYS/SYS_Types.h>
20 #include <SYS/SYS_ParseNumber.h>
21 
22 #define UT_MAX_OPTIONS 4 // A maximum of three args following
23  // an option
24 class UT_WorkBuffer;
25 class UT_String;
26 class UT_StringRef;
27 class UT_StringHolder;
28 
30 {
31 public:
32  /// Default constructor
33  UT_Args();
34  /// Convenience constructor. This is equivalent to: @code
35  /// UT_Args args;
36  /// args.initialize(argc, argv);
37  /// args.stripOptions(options);
38  /// @endcode
39  UT_Args(int argc, const char *const argv[], const char *options);
40  /// Destructor
41  virtual ~UT_Args();
42 
43  int argc() const { return my_argc; }
44  const char *argv(unsigned i) const { return myArgv(i); }
45  const char *const *argv() const { return myArgv.getArgv(); }
46  const char *operator[](unsigned i) const
47  {
48  return (i < my_argc) ? argv(i) : 0;
49  }
50  const char *operator()(unsigned i) const
51  {
52  UT_ASSERT_P(i < my_argc);
53  return argv(i);
54  }
55 
56  int found(int opt) const
57  {
58  UT_ASSERT_P(opt >= 0 && opt < 128);
59  return my_found[opt];
60  }
61  const char *argp(int opt, int which=0) const
62  {
63  UT_ASSERT_P(opt >= 0 && opt < 128);
64  UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
65  return my_opt[opt][which];
66  }
67  const char *argp2(int opt) const
68  {
69  return my_opt[opt][1];
70  }
71  const char *argp3(int opt) const
72  {
73  UT_ASSERT_P(opt >= 0 && opt < 128);
74  return my_opt[opt][2];
75  }
76 
77  fpreal fargp(int opt, int which=0) const
78  {
79  UT_ASSERT_P(opt >= 0 && opt < 128);
80  UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
81  return SYSatof(my_opt[opt][which]);
82  }
83  fpreal fargp2(int opt) const { return fargp(opt, 1); }
84  fpreal fargp3(int opt) const { return fargp(opt, 2); }
85 
86  int iargp(int opt, int which=0) const
87  {
88  UT_ASSERT_P(opt >= 0 && opt < 128);
89  UT_ASSERT_P(which >= 0 && which < UT_MAX_OPTIONS);
90  return SYSatoi(my_opt[opt][which]);
91  }
92  int iargp2(int opt) const { return (int)fargp(opt, 1); }
93  int iargp3(int opt) const { return (int)fargp(opt, 2); }
94 
95  void initialize(int argc, const char *const argv[]);
96  /// Initialize with an array of UT_StringRef objects. This method
97  /// extracts the c_str() from the UT_StringRef, so the UT_StringRef objects
98  /// need to remain in scope while the UT_Args is in existence.
99  void initialize(int argc, const UT_StringRef *argv);
100  void initialize(int argc, const UT_StringHolder *argv);
101  void appendArg(const char *arg);
102  void stripOptions(const char *options);
103 
104  /// This method will make a command string out of all the arguments (and
105  /// options). Arguments will be quoted according to 'csh' syntax.
106  int fillCommandLine(UT_WorkBuffer &buf,
107  int first_arg=0,
108  int include_options=1) const;
109 
110  /// This is a version of fillCommandLine that takes a UT_String for the
111  /// result.
112  void makeCommandLine(UT_String &str, int first_arg=1) const;
113 
114  /// Set an argument to a specific value
115  void setArgument(int idx, const char *text);
116 
117  /// Dump options
118  void display();
119 
120 private:
121  int my_argc; // Arg count (after options)
122  UT_WorkArgs myArgv;
123  char my_found[128]; // Options found (one for each char)
124  const char *my_opt[128][UT_MAX_OPTIONS];
125 };
126 #endif
int iargp(int opt, int which=0) const
Definition: UT_Args.h:86
fpreal fargp3(int opt) const
Definition: UT_Args.h:84
int iargp3(int opt) const
Definition: UT_Args.h:93
const char * operator[](unsigned i) const
Definition: UT_Args.h:46
const char * argv(unsigned i) const
Definition: UT_Args.h:44
int found(int opt) const
Definition: UT_Args.h:56
#define UT_API
Definition: UT_API.h:12
const char *const * argv() const
Definition: UT_Args.h:45
png_uint_32 i
Definition: png.h:2877
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
int iargp2(int opt) const
Definition: UT_Args.h:92
const char * argp2(int opt) const
Definition: UT_Args.h:67
fpreal fargp(int opt, int which=0) const
Definition: UT_Args.h:77
int argc() const
Definition: UT_Args.h:43
fpreal fargp2(int opt) const
Definition: UT_Args.h:83
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
const char * operator()(unsigned i) const
Definition: UT_Args.h:50
const char * argp3(int opt) const
Definition: UT_Args.h:71
double fpreal
Definition: SYS_Types.h:263
#define UT_MAX_OPTIONS
Definition: UT_Args.h:22
const char * argp(int opt, int which=0) const
Definition: UT_Args.h:61