HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_Block.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: VOP Library (C++)
7  *
8  */
9 
10 #ifndef __VOP_Block_h__
11 #define __VOP_Block_h__
12 
13 #include <UT/UT_Set.h>
14 
15 #include "VOP_API.h"
16 #include "VOP_Node.h"
17 
18 class VOP_API VOP_Block : public VOP_Node
19 {
20 public:
21  static PRM_Template myTemplateListOpen[];
22  static PRM_Template myTemplateListClose[];
23 
24  virtual void getCode(UT_String &codestr,
25  const VOP_CodeGenContext &context);
26 
27  virtual const char *inputLabel(unsigned idx) const;
28  virtual const char *outputLabel(unsigned idx) const;
29 
30  virtual const VOP_Block *castToBlock() const { return this; }
31  virtual VOP_Block *castToBlock() { return this; }
32 
33  virtual unsigned getNumVisibleInputs() const;
34  virtual unsigned getNumVisibleOutputs() const;
35  virtual unsigned orderedInputs() const;
36 
37  virtual unsigned getBuiltInInputs() const = 0;
38 
39  /// Convenience method to get the paired block node
40  VOP_Node *getPairedNodeRaw() const;
41 
42  /// Only returns non-null if it is a valid pair.
44  { UT_StringHolder tmp; return getPairedNode(tmp); }
45  VOP_Block *getPairedNode(UT_StringHolder &error) const;
46 
47  bool isOpenBlock() const
48  { return myIsOpenBlock; }
49  bool isCloseBlock() const
50  { return !isOpenBlock(); }
51  virtual bool isLoop() const = 0;
52  virtual bool isConditional() const = 0;
53 
54  virtual void getOpenCode(UT_String &codestr,
55  const VOP_CodeGenContext &context) = 0;
56  virtual void getCloseCode(UT_String &codestr,
57  const VOP_CodeGenContext &context) = 0;
58 
59  /// Creates a set of all the nodes inside of our open/close pair.
60  /// Returns true if done with no errors.
61  bool findEnclosedItems(
62  OP_EnclosedItems &items,
63  UT_StringHolder &error) const;
65  OP_EnclosedItems &items) const
66  { UT_StringHolder tmp; return findEnclosedItems(items, tmp); }
67 
68  /// Given a set of enclosed nodes, likely from the findEnclosedItems,
69  /// generates a set of all nodes that are inputs & are not themselves
70  /// enclosed
71  void findAllBlockInputNodes(
72  OP_EnclosedItems &inputnodes,
73  const OP_EnclosedItems &enclosed) const;
74 
75  // Returns true if the begin/end pairs are copacetic.
76  bool validatePairing(UT_StringHolder &error) const;
77 
78  // We enforce that blocked pairs have the same color
79  virtual bool setColor(const UT_Color &col);
80 
81 protected:
82  VOP_Block(OP_Network *parent, const char *name,
83  OP_Operator *entry, bool isopen);
84  virtual ~VOP_Block();
85 
86  virtual bool generateErrorsSubclass();
87 
88  virtual UT_StringHolder builtinVARNAME(int idx) const = 0;
89  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info,
90  int idx) = 0;
91 
92  // Called on the open node, asks if the given close node
93  // is a valid pair.
94  virtual bool validatePairingSubclass(
95  const VOP_Block *close) const = 0;
96 
97  virtual void postOpChanged(OP_EventType reason, void *data);
98 
99  virtual void getInputNameSubclass(UT_String &in, int idx) const;
100  virtual int getInputFromNameSubclass(const UT_String &in) const;
101  virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info,
102  int idx);
103 
104  virtual void getOutputNameSubclass(UT_String &out, int idx) const;
105  virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
106  int idx);
107 
108  virtual int NUMPARMS() const;
109  UT_StringHolder VARNAME(int idx) const;
110  UT_StringHolder VARLABEL(int idx) const;
111 
112 private:
113  // Set by constructor, implied by the type, so does not
114  // have to be saved.
115  bool myIsOpenBlock;
116 
117  // These are for our variables *after* the built ins.
118  mutable OP_VERSION myVarNameCacheParms;
119  mutable UT_StringArray myVarNameCache;
120  mutable bool myFindingEnclosed;
121 };
122 
124 {
125 public:
126  static OP_Node *myConstructorClose(OP_Network *net,
127  const char *name,
128  OP_Operator *entry);
129 
130  virtual unsigned getBuiltInInputs() const { return 1; }
131  virtual UT_StringHolder builtinVARNAME(int idx) const
132  {
133  UT_StringHolder result;
134  result.reference("condition");
135  return result;
136  }
137  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
138  {
139  type_info.setType(VOP_TYPE_INTEGER);
140  }
141  virtual bool validatePairingSubclass(const VOP_Block *close) const
142  {
143  return false;
144  }
145  virtual bool isLoop() const { return true; }
146  virtual bool isConditional() const { return false; }
147 
148  virtual void getOpenCode(UT_String &codestr,
149  const VOP_CodeGenContext &context);
150  virtual void getCloseCode(UT_String &codestr,
151  const VOP_CodeGenContext &context);
152 
153 protected:
154  VOP_BlockWhile(OP_Network *parent, const char *name,
155  OP_Operator *entry, bool isopen)
156  : VOP_Block(parent, name, entry, isopen)
157  { }
158 };
159 
161 {
162 public:
163  static OP_Node *myConstructorOpen(OP_Network *net,
164  const char *name,
165  OP_Operator *entry);
166  static OP_Node *myConstructorClose(OP_Network *net,
167  const char *name,
168  OP_Operator *entry);
169 
170  virtual unsigned getBuiltInInputs() const { return 0; }
171  virtual UT_StringHolder builtinVARNAME(int idx) const
172  {
173  UT_StringHolder result;
174  return result;
175  }
176  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
177  {
178  }
179  virtual bool validatePairingSubclass(const VOP_Block *close) const
180  {
181  if (dynamic_cast<const VOP_BlockWhile *>(close) ||
182  dynamic_cast<const VOP_BlockNone *>(close))
183  {
184  return true;
185  }
186  return false;
187  }
188  virtual bool isLoop() const { return false; }
189  virtual bool isConditional() const { return false; }
190 
191  virtual void getOpenCode(UT_String &codestr,
192  const VOP_CodeGenContext &context);
193  virtual void getCloseCode(UT_String &codestr,
194  const VOP_CodeGenContext &context);
195 
196 protected:
197  VOP_BlockNone(OP_Network *parent, const char *name,
198  OP_Operator *entry, bool isopen)
199  : VOP_Block(parent, name, entry, isopen)
200  { }
201 };
202 
204 {
205 public:
206  static OP_Node *myConstructorOpen(OP_Network *net,
207  const char *name,
208  OP_Operator *entry);
209 
210  virtual unsigned getBuiltInInputs() const { return 1; }
211  virtual UT_StringHolder builtinVARNAME(int idx) const
212  {
213  UT_StringHolder result;
214  result.reference("condition");
215  return result;
216  }
217  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
218  {
219  type_info.setType(VOP_TYPE_INTEGER);
220  }
221  virtual bool validatePairingSubclass(const VOP_Block *close) const
222  {
223  if (dynamic_cast<const VOP_BlockWhile *>(close) ||
224  dynamic_cast<const VOP_BlockNone *>(close))
225  {
226  return true;
227  }
228  return false;
229  }
230  virtual bool isLoop() const { return false; }
231  virtual bool isConditional() const { return true; }
232 
233  virtual void getOpenCode(UT_String &codestr,
234  const VOP_CodeGenContext &context);
235  virtual void getCloseCode(UT_String &codestr,
236  const VOP_CodeGenContext &context);
237 
238 protected:
239  VOP_BlockIf(OP_Network *parent, const char *name,
240  OP_Operator *entry, bool isopen)
241  : VOP_Block(parent, name, entry, isopen)
242  { }
243 };
244 
246 {
247 public:
248  static OP_Node *myConstructorClose(OP_Network *net,
249  const char *name,
250  OP_Operator *entry);
251 
252  virtual unsigned getBuiltInInputs() const { return 1; }
253  virtual UT_StringHolder builtinVARNAME(int idx) const
254  {
255  UT_StringHolder result;
256  result.reference("condition");
257  return result;
258  }
259  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
260  {
261  type_info.setType(VOP_TYPE_INTEGER);
262  }
263  virtual bool validatePairingSubclass(const VOP_Block *close) const
264  {
265  return false;
266  }
267  virtual bool isLoop() const { return false; }
268  virtual bool isConditional() const { return true; }
269 
270  virtual void getOpenCode(UT_String &codestr,
271  const VOP_CodeGenContext &context);
272  virtual void getCloseCode(UT_String &codestr,
273  const VOP_CodeGenContext &context);
274 
275 protected:
276  VOP_BlockBreakIf(OP_Network *parent, const char *name,
277  OP_Operator *entry, bool isopen)
278  : VOP_Block(parent, name, entry, isopen)
279  { }
280 };
281 
282 
284 {
285 public:
286  static OP_Node *myConstructorOpen(OP_Network *net,
287  const char *name,
288  OP_Operator *entry);
289 
290  virtual unsigned getBuiltInInputs() const { return 2; }
291  virtual UT_StringHolder builtinVARNAME(int idx) const
292  {
293  UT_StringHolder result;
294  if (idx == 1)
295  result.reference("index");
296  else
297  result.reference("length");
298  return result;
299  }
300  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
301  {
302  type_info.setType(VOP_TYPE_INTEGER);
303  }
304  virtual bool validatePairingSubclass(const VOP_Block *close) const
305  {
306  if (dynamic_cast<const VOP_BlockBreakIf *>(close) ||
307  dynamic_cast<const VOP_BlockNone *>(close))
308  {
309  return true;
310  }
311  return false;
312  }
313  virtual bool isLoop() const { return true; }
314  virtual bool isConditional() const { return false; }
315 
316  virtual void getOpenCode(UT_String &codestr,
317  const VOP_CodeGenContext &context);
318  virtual void getCloseCode(UT_String &codestr,
319  const VOP_CodeGenContext &context);
320 
321 protected:
322  VOP_BlockFor(OP_Network *parent, const char *name,
323  OP_Operator *entry, bool isopen)
324  : VOP_Block(parent, name, entry, isopen)
325  { }
326 };
327 
329 {
330 public:
331  static OP_Node *myConstructorOpen(OP_Network *net,
332  const char *name,
333  OP_Operator *entry);
334 
335  virtual unsigned getBuiltInInputs() const { return 3; }
336  virtual UT_StringHolder builtinVARNAME(int idx) const
337  {
338  UT_StringHolder result;
339  switch (idx)
340  {
341  case 0: // Array.
342  result.reference("array");
343  break;
344  case 1: // Element.
345  result.reference("element");
346  break;
347  case 2: // Index.
348  result.reference("index");
349  break;
350  }
351  return result;
352  }
353  virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx);
354  virtual bool validatePairingSubclass(const VOP_Block *close) const
355  {
356  if (dynamic_cast<const VOP_BlockBreakIf *>(close) ||
357  dynamic_cast<const VOP_BlockNone *>(close))
358  {
359  return true;
360  }
361  return false;
362  }
363  virtual bool isLoop() const { return true; }
364  virtual bool isConditional() const { return false; }
365 
366  virtual void getOpenCode(UT_String &codestr,
367  const VOP_CodeGenContext &context);
368  virtual void getCloseCode(UT_String &codestr,
369  const VOP_CodeGenContext &context);
370 
371 protected:
372  VOP_BlockForEach(OP_Network *parent, const char *name,
373  OP_Operator *entry, bool isopen)
374  : VOP_Block(parent, name, entry, isopen)
375  { }
376 };
377 
378 
379 #endif
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:171
virtual int getInputFromNameSubclass(const UT_String &in) const
virtual bool isConditional() const
Definition: VOP_Block.h:268
VOP_BlockFor(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:322
Definition: UT_Set.h:58
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:130
virtual const VOP_Block * castToBlock() const
Definition: VOP_Block.h:30
virtual VOP_Block * castToBlock()
Definition: VOP_Block.h:31
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:335
uint64 OP_VERSION
Definition: OP_Version.h:6
virtual bool isLoop() const
Definition: VOP_Block.h:363
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
Definition: VOP_Block.h:217
virtual bool isConditional() const
Definition: VOP_Block.h:364
virtual unsigned getNumVisibleInputs() const
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:291
virtual const char * inputLabel(unsigned idx) const
virtual void getOpenCode(UT_String &codestr, const VOP_CodeGenContext &context)=0
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:211
VOP_BlockWhile(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:154
virtual unsigned getNumVisibleOutputs() const
void setType(VOP_Type type, VOP_Type raw_type=VOP_TYPE_UNDEF, const char *type_name=NULL)
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
Definition: VOP_Block.h:259
VOP_BlockForEach(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:372
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:336
virtual bool generateErrorsSubclass()
virtual bool isConditional() const
Definition: VOP_Block.h:231
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
Definition: VOP_Block.h:300
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:354
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:253
virtual bool setColor(const UT_Color &col)
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:179
VOP_Block * getPairedNode() const
Only returns non-null if it is a valid pair.
Definition: VOP_Block.h:43
bool isCloseBlock() const
Definition: VOP_Block.h:49
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:263
#define VOP_API
Definition: VOP_API.h:10
virtual bool isConditional() const
Definition: VOP_Block.h:146
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
Definition: VOP_Block.h:137
virtual bool isLoop() const
Definition: VOP_Block.h:313
virtual unsigned orderedInputs() const
virtual bool isLoop() const
Definition: VOP_Block.h:267
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)=0
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual bool isConditional() const
Definition: VOP_Block.h:189
VOP_BlockBreakIf(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:276
bool isOpenBlock() const
Definition: VOP_Block.h:47
virtual bool isLoop() const
Definition: VOP_Block.h:230
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:141
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
virtual void getCloseCode(UT_String &codestr, const VOP_CodeGenContext &context)=0
virtual UT_StringHolder builtinVARNAME(int idx) const
Definition: VOP_Block.h:131
virtual bool isLoop() const
Definition: VOP_Block.h:145
virtual const char * outputLabel(unsigned idx) const
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:221
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:170
virtual void getOutputNameSubclass(UT_String &out, int idx) const
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:210
bool findEnclosedItems(OP_EnclosedItems &items) const
Definition: VOP_Block.h:64
virtual void close()
virtual bool validatePairingSubclass(const VOP_Block *close) const
Definition: VOP_Block.h:304
VOP_BlockIf(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:239
OP_EventType
Definition: OP_Value.h:22
virtual void getInputNameSubclass(UT_String &in, int idx) const
void reference(const char *src)
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:252
virtual bool isConditional() const
Definition: VOP_Block.h:314
virtual bool isLoop() const
Definition: VOP_Block.h:188
virtual unsigned getBuiltInInputs() const
Definition: VOP_Block.h:290
VOP_BlockNone(OP_Network *parent, const char *name, OP_Operator *entry, bool isopen)
Definition: VOP_Block.h:197
virtual void getBuiltInTypeInfo(VOP_TypeInfo &type_info, int idx)
Definition: VOP_Block.h:176
virtual void postOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1364