HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_BatchParm.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: PRM_BatchParm.h ( PRM Library, C++)
7  *
8  * COMMENTS: Batch evaluation of parameters. This class is the definition
9  * of a parameter.
10  */
11 
12 #ifndef __PRM_BatchParm__
13 #define __PRM_BatchParm__
14 
15 #include "PRM_API.h"
16 #include <UT/UT_NonCopyable.h>
17 #include <UT/UT_String.h>
18 #include <SYS/SYS_Types.h>
19 
20 typedef enum
21 {
27 
28 #define PRM_BATCH_CACHE_SIZE 4
29 
31 {
32 public:
33  PRM_BatchParm();
34  ~PRM_BatchParm();
35 
37 
38  bool init(const char *name, PRM_BatchType type,
39  int vsize, void *userdata);
40 
41  const char *getName() const { return myName; }
42  PRM_BatchType getType() const { return myType; }
43  int getVectorSize() const { return myVectorSize; }
44  bool isEvaluated() const { return myEvaluated; }
45 
46  int getEvaluatingOp() const { return myOpId; }
47  int getEvaluatingParmIndex() const { return myParmIndex; }
48 
49  void clearEvaluated() { myEvaluated = false; }
50  void clearValueSet() { myValueSet = false; }
51 
52  // Determine whether we can set the value of the parm into the actual OP
53  // node's parameter.
54  bool isValueSet() const { return myValueSet && myEvaluated; }
55 
56  int *getInt() { return myVector.myInt; }
57  fpreal *getReal() { return myVector.myReal; }
58  UT_String *getString() { return myVector.myString; }
59 
60  void *getUserData() { return myUserData; }
61 
62  int getDefaultedInt(int def, int idx=0)
63  { return myEvaluated ? myVector.myInt[idx] : def; }
64  fpreal getDefaultedReal(fpreal def, int idx=0)
65  { return myEvaluated ? myVector.myReal[idx] : def; }
66  const char *getDefaultedString(const char *def, int idx=0)
67  {
68  if (myEvaluated)
69  def = (const char *)myVector.myString[idx];
70  return def;
71  }
72 
74  {
75  myValueSet = true;
76  for (int i = 0; i < myVectorSize; i++)
77  myVector.myInt[i] = (int)val[i];
78  }
80  {
81  myValueSet = true;
82  for (int i = 0; i < myVectorSize; i++)
83  myVector.myInt[i] = (int)val[i];
84  }
86  {
87  myValueSet = true;
88  for (int i = 0; i < myVectorSize; i++)
89  myVector.myReal[i] = (fpreal)val[i];
90  }
92  {
93  myValueSet = true;
94  for (int i = 0; i < myVectorSize; i++)
95  myVector.myReal[i] = (fpreal)val[i];
96  }
97  void setValue(const char **val)
98  {
99  myValueSet = true;
100  for (int i = 0; i < myVectorSize; i++)
101  myVector.myString[i].harden(val[i]);
102  }
103 
104  void dump();
105 
106 private:
107  void freeVector();
108  void setEvaluated(int opid, int pidx)
109  {
110  myEvaluated = true;
111  myOpId = opid;
112  myParmIndex = pidx;
113  }
114 
115  // Rather than allocating memory for small vectors, we just create a cache.
116  union {
119  } myCache;
120  union {
122  int *myInt;
124  } myVector;
125  const char *myName;
126  void *myUserData;
127  PRM_BatchType myType;
128  int myVectorSize;
129  int myOpId, myParmIndex;
130  bool myEvaluated;
131  bool myValueSet;
132 
133  friend class PRM_BatchList;
134 };
135 
136 #endif
const char * getDefaultedString(const char *def, int idx=0)
Definition: PRM_BatchParm.h:66
int int32
Definition: SYS_Types.h:39
void clearValueSet()
Definition: PRM_BatchParm.h:50
UT_String * getString()
Definition: PRM_BatchParm.h:58
fpreal * myReal
int getVectorSize() const
Definition: PRM_BatchParm.h:43
int getEvaluatingParmIndex() const
Definition: PRM_BatchParm.h:47
int getEvaluatingOp() const
Definition: PRM_BatchParm.h:46
void clearEvaluated()
Definition: PRM_BatchParm.h:49
fpreal getDefaultedReal(fpreal def, int idx=0)
Definition: PRM_BatchParm.h:64
float fpreal32
Definition: SYS_Types.h:200
bool isEvaluated() const
Definition: PRM_BatchParm.h:44
double fpreal64
Definition: SYS_Types.h:201
void setValue(const char **val)
Definition: PRM_BatchParm.h:97
void setValue(fpreal64 *val)
Definition: PRM_BatchParm.h:91
UT_String * myString
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
int * getInt()
Definition: PRM_BatchParm.h:56
void setValue(int32 *val)
Definition: PRM_BatchParm.h:73
#define PRM_BATCH_CACHE_SIZE
Definition: PRM_BatchParm.h:28
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
PRM_BatchType getType() const
Definition: PRM_BatchParm.h:42
bool isValueSet() const
Definition: PRM_BatchParm.h:54
long long int64
Definition: SYS_Types.h:116
void * getUserData()
Definition: PRM_BatchParm.h:60
GLuint const GLchar * name
Definition: glcorearb.h:786
PRM_BatchType
Definition: PRM_BatchParm.h:20
fpreal64 fpreal
Definition: SYS_Types.h:278
GLuint GLfloat * val
Definition: glcorearb.h:1608
void setValue(int64 *val)
Definition: PRM_BatchParm.h:79
int getDefaultedInt(int def, int idx=0)
Definition: PRM_BatchParm.h:62
#define PRM_API
Definition: PRM_API.h:10
const char * getName() const
Definition: PRM_BatchParm.h:41
fpreal * getReal()
Definition: PRM_BatchParm.h:57
void setValue(fpreal32 *val)
Definition: PRM_BatchParm.h:85