HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_NodeInterface.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_NODE_INTERFACE_H__
10 #define __PDG_NODE_INTERFACE_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_ApplicationShim.h"
15 #include "PDG_AttributeInfo.h"
16 #include "PDG_JobScriptInfo.h"
17 #include "PDG_NodePorts.h"
18 #include "PDG_Port.h"
19 
20 #include <PDGT/PDGT_ValueArgs.h>
21 
22 #include <UT/UT_Array.h>
23 #include <UT/UT_NonCopyable.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_StringMap.h>
27 
28 #include <SYS/SYS_TypeDecorate.h>
29 
30 #define PDG_BUILTIN_PARAM_PREFIX "pdg_"
31 #define PDG_BUILTIN_TAG_PREFIX "pdg::"
32 
33 #define PDG_BUILTIN_PARAM(name) PDG_BUILTIN_PARAM_PREFIX name
34 #define PDG_SEP_PARAM(index) "sepparm" #index
35 #define PDG_BUILTIN_TAG(name) PDG_BUILTIN_TAG_PREFIX name
36 
37 class PDG_Node;
38 class PDG_WorkItem;
39 class UT_WorkBuffer;
40 
42 {
43 public:
45  {
47 
50 
51  bool multiparm;
52  };
53 
55 
57  {
61  };
62 
64 
65 public:
66 
67  /// UT_StringHolder instances for built in PDG parm/data field names. Since
68  /// some of these are used during the cook, it's advantageous to store them
69  /// as static instances and refer to them using PDG_NodeInterace::theXYZX
70  /// rather just referring to them with a const char* to avoid rehashing for
71  /// map lookups.
83 
86 
89 
94 
101 
107 
111 
117 
120 
122 
139 
147 
152 
154 
157 
158 public:
160  UT_StringHolder name = "",
161  UT_StringHolder data_type = "");
162  virtual ~PDG_NodeInterface();
163 
164  int64 getMemoryUsage(bool inclusive) const;
165 
166  /// Clones the template interface into the ports/parameters on this
167  /// interface.
168  void cloneFrom(const PDG_NodeInterface& interface);
169 
170  /// Adds builtin ports for the specified node type and subtype
171  void addBuiltinPorts(
173  PDG_NodeSubtype sub_type);
174 
175  /// Queries the work item data type associated with this node
177  { return myWorkItemDataType; }
179  { return myWorkItemDataType; }
180 
181  /// Resolves and caches the work item data type
182  bool resolveWorkItemDataType(UT_WorkBuffer& errors);
183 
184  /// Returns the list of all ports of the specified type
185  const PDG_PortArray& ports(PDG_PortType type) const;
186  const PDG_PortArray& inputPorts() const;
187  const PDG_PortArray& outputPorts() const;
188  const PDG_PortArray& parameters() const;
189 
190  /// Returns the list of parameter groups for the node
192  { return myParameterGroups; }
193 
194  /// Returns the list of parameters with the specified tag
195  bool parametersForTag(
196  const UT_StringHolder& tag,
197  PDG_PortArray& parameters) const;
198 
199  /// Returns the list of custom parameter ports.
200  const PDG_PortArray& customParameters() const;
201 
202  /// Find a port by type, index and/or name. If no matching port is found,
203  /// nullptr is returned.
204  PDG_Port* port(PDG_PortType type, int index) const;
205  PDG_Port* port(
207  const UT_StringHolder& name) const;
208  PDG_Port* port(const UT_StringHolder& name) const;
209 
210  /// Specialized functions for finding input ports by name or index
211  PDG_Port* inputPort(int index) const;
212  PDG_Port* inputPort(const UT_StringHolder& name) const;
213  bool inputPortsForNode(
214  PDG_Node* node,
215  PDG_PortArray& ports) const;
216  bool inputPortsForWorkItem(
217  const PDG_WorkItem* work_item,
218  PDG_PortArray& ports) const;
219  bool isWorkItemFromInputPort(
220  const PDG_WorkItem* work_item,
221  const UT_StringHolder& name) const;
222 
223  /// Sepcialized functions for finding output ports by name or index
224  PDG_Port* outputPort(int index) const;
225  PDG_Port* outputPort(const UT_StringHolder& name) const;
226 
227  /// Returns the parameter with the specified name, or nullptr if no such
228  /// parameter exists.
229  PDG_Port* parameter(
230  const UT_StringHolder& name,
231  int multi=-1) const;
232 
233  /// Returns the value and default value of the parameter with the
234  /// specified name and index. If no parameter is found or the index is
235  /// out of range, nullptr is returned.
236  PDGT_Value* paramValue(
237  const UT_StringHolder& name,
238  int index=0) const;
239  PDGT_Value* defaultParamValue(
240  const UT_StringHolder& name,
241  int index=0) const;
242 
243  /// Returns the numbers of ports with the specified type (input,
244  /// output, etc).
245  int portCount(PDG_PortType type) const;
246  int inputCount() const;
247  int outputCount() const;
248  int parameterCount() const;
249 
250  /// Returns information about the number of ordered vs. unordered input
251  /// ports on this node.
252  bool hasUnorderedPorts() const;
253  int numOrderedPorts() const;
254 
255  /// Adds the specified port, which can be an input, output or a parameter.
256  /// Returns the new port on success, else returns failure.
257  PDG_Port* addPort(
259  const PDG_WorkItemDataType* data_type,
260  const UT_StringHolder& name,
261  const UT_StringHolder& label,
262  const UT_StringArray& tags = UT_StringArray(),
263  int size = 0,
264  bool ordered = true,
265  bool custom = false);
266 
267  /// Adds a parameter with the specified data type, size, name, label and
268  /// tag list. Returns the parameter on success, or nullptr on failure.
269  PDG_Port* addParameter(
270  PDGT_Value::DataType data_type,
271  const UT_StringHolder& name,
272  const UT_StringHolder& label,
273  const UT_StringArray& tags,
274  int size = 1,
275  bool custom = false);
276 
277  /// Adds a parameter with a data type, name, label and optional size.
278  PDG_Port* addParameter(
279  PDGT_Value::DataType data_type,
280  const UT_StringHolder& name,
281  const UT_StringHolder& label,
282  int size = 1,
283  bool custom = false);
284 
285  /// Removes the specified parameter by name, and returns true if the
286  /// parameter was found and successfully removed.
287  bool removeParameter(const UT_StringHolder& name);
288 
289  /// Adds a new file dependency to the node interface
290  void addFileDependency(
291  const UT_StringHolder& file_path);
292 
293  /// Adds a new parameter group to the node interface
294  void addParameterGroup(
295  const UT_StringHolder& name,
296  bool root = true,
297  bool multiparm = false);
298 
299  /// Ends the current parameter group
300  void endParameterGroup();
301 
302  /// If this interface represents a template, returns the name of that
303  /// template
305  { return myTemplateName; }
306 
307  /// Returns the template interface that defined how this interface
308  /// was created
309  virtual const PDG_NodeInterface*
311  { return nullptr; }
312 
313  /// Returns true if the node interface is valid
314  bool isValid() const
315  { return myValidFlag; }
316 
317  /// Returns the list of external files that this node depends on.
319  { return myAutoDependencies; }
320 
321  /// Returns the list of common expression variables, available on all
322  /// parameters on this node interface.
324  commonVars() const
325  { return myCommonVars; }
326 
327  /// Returns the underlying application node associated with this PDG node,
328  /// for example a TOP node or TOP scheduler. This may be null.
330  { return myAppNode.get(); }
331 
332  /// Sets the underlying app node.
333  template <typename T, typename... Args>
334  void setAppNode(Args&&... args)
335  {
336  myAppNode = UTmakeUnique<T>(
337  std::forward<Args>(args)...);
338  }
339 
340  /// Returns the attribute info object for this node interface. If this is
341  /// a template loaded from .json, the attribute info object contains the
342  /// definition as it was specified in the template. Otherwise, if this is
343  /// a cooked node, then it contains the evaluated attribute info from the
344  /// last cook.
346  { return myAttributeInfo; }
347 
348  /// Clears and sets the attribute info for this interface
350  { myAttributeInfo = info; }
351 
352  /// Returns the script info for this node interface.
354  { return myScriptInfo; }
355 
356  /// Sets the script info for the interface
358  { myScriptInfo = info; }
359 
360  /// Adds a single entry to the job script info's service compatiblity
361  /// list
362  void setServiceCompatibility(
363  const UT_StringHolder& service_type_name,
364  bool compatible);
365 
366  /// Adds an error to the node interface -- implemented in subclasses
367  virtual void addError(const UT_StringHolder& message) const
368  {}
369 
370  /// Adds an error using a format string, instead of plain string
371  template <typename... Args>
373  const char* fmt,
374  Args&&... args) const
375  {
377  buffer.format(
378  fmt, std::forward<Args>(args)...);
379  addError(buffer.buffer());
380  }
381 
382  /// Adds a warning to the node interface -- implemented in subclasses
383  virtual void addWarning(const UT_StringHolder& message) const
384  {}
385 
386  /// Adds a warning using a format string, instead of plain string
387  template <typename... Args>
389  const char* fmt,
390  Args&&... args) const
391  {
393  buffer.format(
394  fmt, std::forward<Args>(args)...);
395  addWarning(buffer.buffer());
396  }
397 
398  /// Evaluates a parameter and reports errors if desired
399  template <typename T>
401  const UT_StringHolder& name,
402  const PDG_WorkItem* work_item=nullptr,
403  int index=0,
404  int multi=-1) const
405  {
406  PDG_Port* parm = parameter(name, multi);
407  if (!parm)
408  return false;
409 
410  UT_WorkBuffer errors;
411  if (parm->evaluate(index, result, work_item, errors))
412  return true;
413 
414  addError(errors.buffer());
415  return false;
416  }
417 
418  /// Evaluates a string parameter as a raw string, and reports errors if
419  /// desired.
422  const UT_StringHolder& name,
423  const PDG_WorkItem* work_item=nullptr,
424  int index=0,
425  int multi=-1) const
426  {
427  PDG_Port* parm = parameter(name, multi);
428  if (!parm)
429  return false;
430 
431  UT_WorkBuffer errors;
432  if (parm->evaluateRaw(index, result, work_item, errors))
433  return true;
434 
435  addError(errors.buffer());
436  return false;
437  }
438 
439  /// Evaluates a parameter as an array and reports errors if desired
440  template <typename T>
442  T& result,
443  const UT_StringHolder& name,
444  const PDG_WorkItem* work_item=nullptr,
445  int multi=-1) const
446  {
447  PDG_Port* parm = parameter(name, multi);
448  if (!parm)
449  return false;
450 
451  UT_WorkBuffer errors;
452  if (parm->evaluate(result, work_item, errors))
453  return true;
454 
455  addError(errors.buffer());
456  return false;
457  }
458 
459 protected:
462 
463 private:
464  PDG_Port* addPortInternal(
465  PDG_PortType type,
466  const PDG_WorkItemDataType* data_type,
467  const UT_StringHolder& name,
468  const UT_StringHolder& label,
469  int size = 0,
470  bool ordered = true,
471  bool custom = false,
472  bool builtin = false);
473 private:
474  friend class PDG_NodeTemplate;
475 
477 
478  PDG_NodePorts myPorts;
479  TaggedParameters myTaggedParameters;
480  PDG_PortArray myCustomParameters;
481  UT_StringArray myMultiEntries;
482  DependencyArray myAutoDependencies;
483  PDG_Port::ExpressionVars myCommonVars;
484 
485  ParameterGroupArray myParameterGroups;
486 
487  UT_StringHolder myTemplateName;
488  UT_StringHolder mySpecifiedWorkItemDataType;
489  mutable PDG_WorkItemDataType*
490  myWorkItemDataType;
492  myAppNode;
493 
494  int myCurrentParameterGroup;
495  int myNumOrderedPorts;
496 
497  bool myUnorderedFlag;
498  bool myValidFlag;
499  bool myNoSchedulerParams;
500  bool myHasCustomInputs;
501  bool myHasCustomOutputs;
502 };
503 
505 
506 #endif
static const UT_StringHolder thePartitionerMergeOpParm
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
static const UT_StringHolder theTagOpDepDirty
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
static const UT_StringHolder theProcessorCommandTypeParm
static const UT_StringHolder thePartitionerSplitAttributeParm
static const UT_StringHolder thePartitionerSortParm
static const UT_StringHolder theProcessorCookTypeParm
void setAttributeInfo(const PDG_AttributeInfo &info)
Clears and sets the attribute info for this interface.
static const UT_StringHolder theSchedulerRpcTimeout
void addWarningFmt(const char *fmt, Args &&...args) const
Adds a warning using a format string, instead of plain string.
static const UT_StringHolder thePartitionerSortDirectionParm
static const UT_StringHolder thePartitionerTargetParm
static const UT_StringHolder thePartitionerSplitDefaultParm
#define PDG_API
Definition: PDG_API.h:23
static const UT_StringHolder theTagOpDepRegen
static const UT_StringHolder theSchedulerDeleteTempDirParm
static const UT_StringHolder theProcessorUseServiceBlockParm
static const UT_StringHolder theSchedulerUseMaxTasksParm
int64 exint
Definition: SYS_Types.h:125
static const UT_StringHolder theProcessorCacheModeParm
SYS_FORCE_INLINE const char * buffer() const
static const UT_StringHolder theSchedulerMaxTasksParm
static const UT_StringHolder theSchedulerTransferRootParm
**But if you need a result
Definition: thread.h:622
virtual void addWarning(const UT_StringHolder &message) const
Adds a warning to the node interface – implemented in subclasses.
static const UT_StringHolder theSchedulerCompressWorkItemDataParm
static const UT_StringHolder theGenerateMenuScript
bool isValid() const
Returns true if the node interface is valid.
GLuint buffer
Definition: glcorearb.h:660
bool evaluateRaw(UT_StringHolder &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int index=0, int multi=-1) const
PDG_WorkItemDataType * workItemDataType()
Queries the work item data type associated with this node.
const PDG_Port::ExpressionVars & commonVars() const
static const UT_StringHolder theProcessorServiceResetTypeParm
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
PDG_NodeType
Enumeration of node types in a PDG graph.
Definition: PDG_NodeTypes.h:95
static const UT_StringHolder theProcessorServiceResetWhenParm
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
static const UT_StringHolder theSchedulerUseMapZoneParm
static const UT_StringHolder theTagExtraInput
static const UT_StringHolder theSchedulerTransferTypeParm
void addErrorFmt(const char *fmt, Args &&...args) const
Adds an error using a format string, instead of plain string.
static const UT_StringHolder theProcessorLabelTypeParm
static const UT_StringHolder thePartitionerSplitEnabledParm
static const UT_StringHolder theProcessorWorkItemGenerationParm
static const UT_StringHolder theProcessorServiceNameParm
static const UT_StringHolder thePartitionerMergeParm
static const UT_StringHolder thePartitionerMergePatternParm
static const UT_StringHolder thePartitionerStoreIDsParm
const UT_StringHolder & templateName() const
static const UT_StringHolder thePartitionerIDAttribParm
virtual void addError(const UT_StringHolder &message) const
Adds an error to the node interface – implemented in subclasses.
static const UT_StringHolder theSchedulerRpcBatch
static const UT_StringHolder theProcessorScheduleWhenParm
static const UT_StringHolder theFeedbackBeginParm
long long int64
Definition: SYS_Types.h:116
static const UT_StringHolder theSchedulerWaitForFailuresParm
bool evaluateArray(T &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int multi=-1) const
Evaluates a parameter as an array and reports errors if desired.
static const UT_StringHolder theProcessorCommandParm
const PDG_WorkItemDataType * workItemDataType() const
const PDG_AttributeInfo & attributeInfo() const
PDG_ApplicationShim::Node * appNode() const
static const UT_StringHolder thePartitionerMergeOutputsParm
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual const PDG_NodeInterface * templateInterface() const
SYS_DECLARE_LEGACY_TR(GU_Detail)
static const UT_StringHolder theSchedulerTickPeriodParm
static const UT_StringHolder theCacheModeMenuScript
static const UT_StringHolder thePartitionerMergePreserveParm
static const UT_StringHolder thePartitionerSplitMissingParm
static const UT_StringHolder theSchedulerMapModeParm
static const UT_StringHolder theSchedulerRpcIgnoreErrors
static const UT_StringHolder thePartitionerWhenParm
static const UT_StringHolder thePartitionerIgnoreFailures
void setScriptInfo(const PDG_JobScriptInfo &info)
Sets the script info for the interface.
static const UT_StringHolder theSchedulerValidateOutputsParm
static const UT_StringHolder thePartitionerSetFrameParm
static const UT_StringHolder theSchedulerMapZoneParm
GLsizeiptr size
Definition: glcorearb.h:664
static const UT_StringHolder theSchedulerRpcMaxErrors
static const UT_StringHolder theFeedbackFilesParm
size_t format(const char *fmt, const Args &...args)
static const UT_StringHolder theProcessorPriorityExpressionParm
void setAppNode(Args &&...args)
Sets the underlying app node.
static const UT_StringHolder theSchedulerWorkingDirParm
static const UT_StringHolder theTagExpandName
GLuint index
Definition: glcorearb.h:786
static const UT_StringHolder theFeedbackAttribPatternParm
static const UT_StringHolder thePartitionerMergeAttribsParm
static const UT_StringHolder theSeparatorLabel
**If you just want to fire and args
Definition: thread.h:618
const PDG_JobScriptInfo & scriptInfo() const
Returns the script info for this node interface.
static const UT_StringHolder theSchedulerMaxItemsParm
static const UT_StringHolder thePartitionerTargetTypeParm
static const UT_StringHolder theProcessorPriorityTypeParm
static const UT_StringHolder thePartitionerSortRequiredParm
PDG_NodeSubtype
Enumeration of node subtypes.
static const UT_StringHolder thePartitionerSortAttribParm
static const UT_StringHolder theSchedulerRpcRelease
static const UT_StringHolder thePartitionerSplitPartialParm
static const UT_StringHolder theFeedbackAttribsParm
static const UT_StringHolder theSchedulerCheckExpectedOutputsParm
const DependencyArray & autoDependencies() const
Returns the list of external files that this node depends on.
bool evaluate(int index, fpreal &result, const PDG_WorkItem *work_item, UT_WorkBuffer &errors) const
bool evaluateRaw(int index, UT_StringHolder &result, const PDG_WorkItem *work_item, UT_WorkBuffer &errors) const
static const UT_StringHolder theProcessorLabelExpressionParm
static const UT_StringHolder theSchedulerDataSourceParm
PDG_JobScriptInfo myScriptInfo
static const UT_StringHolder theProcessorUseScheduleWhenParm
static const UT_StringHolder theSchedulerRpcBackoff
const ParameterGroupArray & parameterGroups() const
Returns the list of parameter groups for the node.
PDG_PortType
Enumeration of node port types.
PDG_AttributeInfo myAttributeInfo
bool evaluate(T &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int index=0, int multi=-1) const
Evaluates a parameter and reports errors if desired.
static const UT_StringHolder theSchedulerRpcRetries