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