HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DS_ParmReader.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: DS_ParmReader.h ( PRM Library, C++ )
7  *
8  * COMMENTS: Generic parameter reader for the generation of dialog scripts
9  * for script shaders
10  */
11 
12 #ifndef __DS_ParmReader__
13 #define __DS_ParmReader__
14 
15 #include "PRM_API.h"
16 #include "PRM_Type.h"
17 #include <CH/CH_ExprLanguage.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_String.h>
20 #include <UT/UT_ValArray.h>
21 #include <SYS/SYS_Types.h>
22 
23 class UT_StringArray;
24 
25 class PRM_Range;
26 
27 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28 
30 {
31 public:
32 
33  DS_DefaultValue( const fpreal32 *fp, int size );
34  DS_DefaultValue( const fpreal64 *fp, int size );
35  DS_DefaultValue( const int32 *ip, int size );
36  DS_DefaultValue( const int64 *ip, int size );
37  DS_DefaultValue( const char *sp[],
38  const CH_StringMeaning *meanings,
39  int size );
41  DS_DefaultValue(const UT_Fpreal64Array &values);
42  DS_DefaultValue(const UT_Int32Array &values);
43  DS_DefaultValue(const UT_Int64Array &values);
44  DS_DefaultValue(const UT_StringArray &values,
45  const CH_StringMeaning *meaning);
46 
47  ~DS_DefaultValue();
48 
50 
51  int copy( const fpreal32 *fp, int size );
52  int copy( const fpreal64 *fp, int size );
53  int copy( const int32 *ip, int size );
54  int copy( const int64 *ip, int size );
55  int copy( const char *sp[],
56  const CH_StringMeaning *meanings,
57  int size);
58  int copy( const UT_Int32Array &v);
59  int copy( const UT_Int64Array &v);
60  int copy( const UT_Fpreal32Array &v);
61  int copy( const UT_Fpreal64Array &v);
62  int copy( const UT_StringArray &v,
63  const CH_StringMeaning *meanings);
64 
65  fpreal *getFloat() const { return myFloat; }
66  int *getInteger() const { return myInteger; }
67  const char *getString(int idx) const { return myStrings[idx]; }
69  { return myStringMeanings[idx]; }
70 
71  int getSize() const { return mySize; };
72 
73 private:
74  void initZero();
75  void cleanup();
76 
77  fpreal *myFloat;
78  int *myInteger;
79  char **myStrings;
80  CH_StringMeaning *myStringMeanings;
81 
82  int mySize;
83 };
84 
85 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86 
88 {
89 public:
90  DS_MenuChoice( const char *value, const char *label)
91  : myValue( 0 ),
92  myLabel( 0 )
93  {
94  if ( value ) myValue = ::strdup( value );
95  if ( label ) myLabel = ::strdup( label );
96  };
98  {
99  if ( myValue ) ::free( myValue );
100  if ( myLabel ) ::free( myLabel );
101  };
102 
104 
105  const char *getValue() const { return myValue; }
106  const char *getLabel() const { return myLabel; }
107 
108 private:
109  char *myValue;
110  char *myLabel;
111 };
112 
114 {
115 public:
116  DS_AttributeValue(const char *token, const char *value)
117  : myToken(0), myValue(0)
118  {
119  if (token) myToken = ::strdup(token);
120  if (value) myValue = ::strdup(value);
121  }
123  {
124  if (myToken) ::free(myToken);
125  if (myValue) ::free(myValue);
126  }
127 
129 
130  const char *getToken() const { return myToken; }
131  const char *getValue() const { return myValue; }
132 
133 private:
134  char *myToken;
135  char *myValue;
136 };
137 
139 {
140 public:
141  DS_HandleBinding(const char *channelname, const char *type,
142  const char *desc, const char *label,
143  const char *default_settings)
144  : myChannelName(0), myType(0), myDesc(0), myLabel(0)
145  {
146  if (channelname) myChannelName = ::strdup(channelname);
147  if (type) myType = ::strdup(type);
148  if (desc) myDesc = ::strdup(desc);
149  if (label) myLabel = ::strdup(label);
150  if (default_settings)
151  myDefaultSettings = ::strdup(default_settings);
152  }
154  {
155  if (myChannelName) ::free(myChannelName);
156  if (myType) ::free(myType);
157  if (myDesc) ::free(myDesc);
158  if (myLabel) ::free(myLabel);
159  if (myDefaultSettings) ::free(myDefaultSettings);
160  }
161 
163 
164  const char *getChannelName() const { return myChannelName; }
165  const char *getType() const { return myType; }
166  const char *getDesc() const { return myDesc; }
167  const char *getLabel() const { return myLabel; }
168  const char *getDefaultSettings() const { return myDefaultSettings; }
169 
170 private:
171  char *myChannelName, *myType, *myDesc, *myLabel, *myDefaultSettings;
172 };
173 
175 {
176 public:
177  DS_SelectorBinding(const char *parm_name,
178  const char *type, const char *prompt, const char *desc,
179  const char *mask, int dragging,
180  const char *menu, int asterisk,
181  int input_index=-1, int input_required=0)
182  : myParmName(0), myType(0), myDesc(0), myPrompt(0), myMask(0), myMenu(0)
183  {
184  myDragging = dragging;
185  myAsterisk = asterisk;
186  myInputIndex = input_index;
187  myInputRequired = input_required;
188  if (parm_name) myParmName = ::strdup(parm_name);
189  if (type) myType = ::strdup(type);
190  if (prompt) myPrompt = ::strdup(prompt);
191  if (desc) myDesc = ::strdup(desc);
192  if (mask) myMask = ::strdup(mask);
193  if (menu) myMenu = ::strdup(menu);
194  }
196  {
197  if (myParmName) ::free(myParmName);
198  if (myType) ::free(myType);
199  if (myPrompt) ::free(myPrompt);
200  if (myDesc) ::free(myDesc);
201  if (myMenu) ::free(myMenu);
202  if (myMask) ::free(myMask);
203  }
204 
206 
207  const char *getParmName() const { return myParmName; }
208  const char *getType() const { return myType; }
209  const char *getPrompt() const { return myPrompt; }
210  const char *getDesc() const { return myDesc; }
211  const char *getPrimMask() const { return myMask; }
212  int getDragging() const { return myDragging; }
213  const char *getMenu() const { return myMenu; }
214  int getAsterisk() const { return myAsterisk; }
215  int getInputIndex() const { return myInputIndex; }
216  int getInputRequired() const { return myInputRequired; }
217 
218 private:
219  char *myParmName, *myType, *myPrompt, *myDesc, *myMask, *myMenu;
220  int myDragging, myAsterisk;
221  int myInputIndex, myInputRequired;
222 };
223 
225 {
226 public:
228  ~DS_DisableInfo();
229 
231 
232  void addInfo(const char *parm, const char *value)
233  { myControlParm.append( ::strdup(parm) );
234  myControlValue.append( ::strdup(value) ); }
235 
238 };
239 
245 
246 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
247 
249 {
250 public:
251  DS_ParmInfo( const char *token );
252  ~DS_ParmInfo();
253 
255 
256  void addHelpText(const char *text);
257 
258  UT_String myToken; // Actual parm name
266  unsigned myFlag;
268 
277 
278  unsigned int mySize; // Vector size (1, 3, 4, 9, 16, etc.)
281 
283  UT_String myDisableWhen; // New style (with {})
284  UT_String myHideWhen; // New style (with {})
285 
286  bool setTypeByToken( const char *token );
287  const char *getTypeToken() const;
288 
289  void setInvisible();
290  bool isInvisible() const;
291 
292  void setLogarithmic(bool flag);
293  bool isLogarithmic() const;
294 
295  // Arrays get translated into multi-parms
296  bool getIsArray() const { return myIsArray; }
297  void setIsArray(bool f) { myIsArray = f; }
298 
299  void setFlag( unsigned flag ) { myFlag |= flag; }
300  void clearFlag( unsigned flag = (unsigned)-1 ){ myFlag &= ~flag; }
301  unsigned getFlag( unsigned flag ) const { return myFlag & flag; }
302 private:
303  bool myIsArray; // Represented as a multi-parm
304 };
305 
307 
308 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
309 
311 {
312 public:
313 
314  // the constructor expects the parms "d:g:cl"
315  DS_ParmReader( unsigned doGroups = 0,
316  unsigned color = 0,
317  unsigned lightChan = 1 );
318  virtual ~DS_ParmReader();
319 
321 
322  virtual const char *getClassName() const;
323 
324  // File IO
325  // all return 0 to indicate error
326  virtual int open( const char *fileName ) = 0;
327  virtual void close() = 0;
328 
329  // parse will read the given script file, and extract information on
330  // the parameters that are present in the script.
331  // parse will return the number of parameters it has successfully found.
332  // returns 0 to indicate error
333  virtual int parse() = 0;
334 
335  // The following must be filled out by derived classes.
336  // NAME and LABEL provide the name(s) for the scripted function.
337  // HELP is the help messages that were included in the script to be
338  // displayed in the UI to aid the user
339  virtual const char *getScriptTypeName() = 0;
340  virtual const char *getScriptName() = 0;
341  virtual const char *getScriptLabel() = 0;
342  virtual const char *getScriptHelp() = 0;
343  virtual const char *getScriptInfo() = 0;
344  virtual const char *getInputLabel(int /*idx*/) { return ""; }
345  virtual int getNumInputLabels() const { return 0; }
346  virtual const char *getRenderMask() { return ""; }
347 
348  // returns the number of parms the reader found from the script
349  int numParms() { return myParms.entries(); }
350 
351  // given an index, return the information on the index'th parm
352  // return 0 to indicate error
353  virtual DS_ParmInfo *getParmInfo( const int index );
354 
355  // let others know if we care about grouping of params
356  int isDoingGroups() const { return myDoGroups; }
357  void setGroupSize(int g) { myGroupSize = g; }
358  int getGroupSize() const { return myGroupSize; }
359  UT_StringList &getGroups() { return myGroups; }
360  DS_SelectorList &getUnboundSelectors() { return myUnboundSelectors; }
361  DS_SelectorList &getReservedSelectors() { return myReservedSelectors; }
362  DS_HandleList &getReservedHandles() { return myReservedHandles; }
363  DS_HandleList &getBoundHandles() { return myBoundHandles; }
364 
365 protected:
366  DS_ParmInfoList myParms;
372 
373  short myDoGroups;
374  short myGroupSize;
375  short myColorFlag;
376  short myLightChan;
377 };
378 
379 #endif
380 
DS_SelectorList myReservedSelectors
DS_HandleList myBoundHandles
DS_HandleList myHandles
DS_DefaultValue * myDefault
void setFlag(unsigned flag)
virtual const char * getRenderMask()
fpreal * getFloat() const
Definition: DS_ParmReader.h:65
const char * getPrimMask() const
int int32
Definition: SYS_Types.h:39
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
DS_SelectorBinding * mySelector
void clearFlag(unsigned flag=(unsigned)-1)
DS_HandleList & getBoundHandles()
const char * getValue() const
void
Definition: png.h:1083
UT_String myRenderManType
CH_StringMeaning
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
int getInputRequired() const
const GLdouble * v
Definition: glcorearb.h:837
const char * getDesc() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
DS_AttributeValue(const char *token, const char *value)
const char * getMenu() const
const char * getPrompt() const
GLboolean GLboolean g
Definition: glcorearb.h:1222
UT_String myLabel
DS_SelectorList myUnboundSelectors
DS_SelectorBinding(const char *parm_name, const char *type, const char *prompt, const char *desc, const char *mask, int dragging, const char *menu, int asterisk, int input_index=-1, int input_required=0)
unsigned int mySize
DS_SelectorList & getUnboundSelectors()
void close() override
UT_String myGroup
float fpreal32
Definition: SYS_Types.h:200
UT_ValArray< DS_SelectorBinding * > DS_SelectorList
UT_String myMenuScript
PRM_MultiType myMultiType
int getDragging() const
DS_HandleBinding(const char *channelname, const char *type, const char *desc, const char *label, const char *default_settings)
__hostdev__ float getValue(uint32_t i) const
Definition: NanoVDB.h:5578
UT_ValArray< DS_MenuChoice * > DS_Menu
double fpreal64
Definition: SYS_Types.h:201
virtual int getNumInputLabels() const
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
DS_AttributeList myAttributes
UT_StringList myGroups
UT_StringList & getGroups()
int open(float queuesize) override
void setGroupSize(int g)
PRM_Type myType
UT_String myToken
const char * getDesc() const
CH_ScriptLanguage myMenuScriptLanguage
const char * getLabel() const
UT_ValArray< DS_AttributeValue * > DS_AttributeList
DS_SelectorList & getReservedSelectors()
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLint GLuint mask
Definition: glcorearb.h:124
int getAsterisk() const
const char * getType() const
DS_HandleList & getReservedHandles()
long long int64
Definition: SYS_Types.h:116
unsigned getFlag(unsigned flag) const
UT_ValArray< DS_DisableInfo * > DS_DisableList
UT_String myOpFilter
void setIsArray(bool f)
DS_DisableList myDisableInfo
SYS_FORCE_INLINE UT_StringHolder getToken(Add enum_value)
Definition: SOP_Add.proto.h:35
UT_String myCallback
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
int isDoingGroups() const
DS_Menu myMenu
UT_ValArray< DS_HandleBinding * > DS_HandleList
const char * getDefaultSettings() const
virtual const char * getInputLabel(int)
unsigned myFlag
bool getIsArray() const
GLsizeiptr size
Definition: glcorearb.h:664
UT_Array< char * > myControlParm
DS_MenuChoice(const char *value, const char *label)
Definition: DS_ParmReader.h:90
int getSize() const
Definition: DS_ParmReader.h:71
DS_ParmInfoList myParms
PRM_Range * myRange
CH_StringMeaning getStringMeaning(int idx) const
Definition: DS_ParmReader.h:68
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint color
Definition: glcorearb.h:1261
DS_HandleList myReservedHandles
fpreal64 fpreal
Definition: SYS_Types.h:278
UT_Array< char * > myControlValue
GLuint index
Definition: glcorearb.h:786
UT_String myHelpText
const char * getString(int idx) const
Definition: DS_ParmReader.h:67
const char * getLabel() const
const char * getType() const
#define PRM_API
Definition: PRM_API.h:10
UT_ValArray< DS_ParmInfo * > DS_ParmInfoList
UT_String myDisableWhen
int getInputIndex() const
int * getInteger() const
Definition: DS_ParmReader.h:66
UT_String myHideWhen
PRM_MultiType
This type enum defines the different types of multi (dynamic) parameters.
Definition: PRM_Type.h:426
CH_ScriptLanguage
int getGroupSize() const