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 #include "PDG_Types.h"
20 
21 #include <PDGT/PDGT_ValueArgs.h>
22 
23 #include <UT/UT_Array.h>
24 #include <UT/UT_NonCopyable.h>
25 #include <UT/UT_StringArray.h>
26 #include <UT/UT_StringHolder.h>
27 #include <UT/UT_StringMap.h>
28 
29 #include <SYS/SYS_TypeDecorate.h>
30 
31 #define PDG_BUILTIN_PARAM_PREFIX "pdg_"
32 #define PDG_BUILTIN_TAG_PREFIX "pdg::"
33 
34 #define PDG_BUILTIN_PARAM(name) PDG_BUILTIN_PARAM_PREFIX name
35 #define PDG_SEP_PARAM(index) "sepparm" #index
36 #define PDG_BUILTIN_TAG(name) PDG_BUILTIN_TAG_PREFIX name
37 
38 class PDG_Node;
39 class PDG_WorkItem;
40 class UT_WorkBuffer;
41 
43 {
44 public:
46  {
48 
51 
52  bool multiparm;
53  };
54 
56 
58  {
62  };
63 
65 
66 public:
67 
68  /// UT_StringHolder instances for built in PDG parm/data field names. Since
69  /// some of these are used during the cook, it's advantageous to store them
70  /// as static instances and refer to them using PDG_NodeInterace::theXYZX
71  /// rather just referring to them with a const char* to avoid rehashing for
72  /// map lookups.
83 
86 
89 
94 
101 
107 
111 
117 
120 
122 
137 
145 
150 
152 
155 
156 public:
158  UT_StringHolder name = "",
159  UT_StringHolder data_type = "");
160  virtual ~PDG_NodeInterface();
161 
162  int64 getMemoryUsage(bool inclusive) const;
163 
164  /// Clones the template interface into the ports/parameters on this
165  /// interface.
166  void cloneFrom(const PDG_NodeInterface& interface);
167 
168  /// Adds builtin ports for the specified node type and subtype
169  void addBuiltinPorts(
171  PDG_NodeSubtype sub_type);
172 
173  /// Queries the work item data type associated with this node
175  { return myWorkItemDataType; }
177  { return myWorkItemDataType; }
178 
179  /// Resolves and caches the work item data type
180  bool resolveWorkItemDataType(UT_WorkBuffer& errors);
181 
182  /// Returns the list of all ports of the specified type
183  const PDG_PortArray& ports(PDG_PortType type) const;
184  const PDG_PortArray& inputPorts() const;
185  const PDG_PortArray& outputPorts() const;
186  const PDG_PortArray& parameters() const;
187 
188  /// Returns the list of parameter groups for the node
190  { return myParameterGroups; }
191 
192  /// Returns the list of parameters with the specified tag
193  bool parametersForTag(
194  const UT_StringHolder& tag,
195  PDG_PortArray& parameters) const;
196 
197  /// Returns the list of custom parameter ports.
198  const PDG_PortArray& customParameters() const;
199 
200  /// Find a port by type, index and/or name. If no matching port is found,
201  /// nullptr is returned.
202  PDG_Port* port(PDG_PortType type, int index) const;
203  PDG_Port* port(
205  const UT_StringHolder& name) const;
206  PDG_Port* port(const UT_StringHolder& name) const;
207 
208  /// Specialized functions for finding input ports by name or index
209  PDG_Port* inputPort(int index) const;
210  PDG_Port* inputPort(const UT_StringHolder& name) const;
211  bool inputPortsForNode(
212  PDG_Node* node,
213  PDG_PortArray& ports) const;
214  bool inputPortsForWorkItem(
215  const PDG_WorkItem* work_item,
216  PDG_PortArray& ports) const;
217  bool isWorkItemFromInputPort(
218  const PDG_WorkItem* work_item,
219  const UT_StringHolder& name) const;
220 
221  /// Sepcialized functions for finding output ports by name or index
222  PDG_Port* outputPort(int index) const;
223  PDG_Port* outputPort(const UT_StringHolder& name) const;
224 
225  /// Returns the parameter with the specified name, or nullptr if no such
226  /// parameter exists.
227  PDG_Port* parameter(
228  const UT_StringHolder& name,
229  int multi=-1) const;
230 
231  /// Returns the value and default value of the parameter with the
232  /// specified name and index. If no parameter is found or the index is
233  /// out of range, nullptr is returned.
234  PDGT_Value* paramValue(
235  const UT_StringHolder& name,
236  int index=0) const;
237  PDGT_Value* defaultParamValue(
238  const UT_StringHolder& name,
239  int index=0) const;
240 
241  /// Returns the numbers of ports with the specified type (input,
242  /// output, etc).
243  int portCount(PDG_PortType type) const;
244  int inputCount() const;
245  int outputCount() const;
246  int parameterCount() const;
247 
248  /// Returns information about the number of ordered vs. unordered input
249  /// ports on this node.
250  bool hasUnorderedPorts() const;
251  int numOrderedPorts() const;
252 
253  /// Adds the specified port, which can be an input, output or a parameter.
254  /// Returns the new port on success, else returns failure.
255  PDG_Port* addPort(
257  const PDG_WorkItemDataType* data_type,
258  const UT_StringHolder& name,
259  const UT_StringHolder& label,
260  const UT_StringArray& tags = UT_StringArray(),
261  int size = 0,
262  bool ordered = true,
263  bool custom = false);
264 
265  /// Adds a parameter with the specified data type, size, name, label and
266  /// tag list. Returns the parameter on success, or nullptr on failure.
267  PDG_Port* addParameter(
268  PDGT_Value::DataType data_type,
269  const UT_StringHolder& name,
270  const UT_StringHolder& label,
271  const UT_StringArray& tags,
272  int size = 1,
273  bool custom = false);
274 
275  /// Adds a parameter with a data type, name, label and optional size.
276  PDG_Port* addParameter(
277  PDGT_Value::DataType data_type,
278  const UT_StringHolder& name,
279  const UT_StringHolder& label,
280  int size = 1,
281  bool custom = false);
282 
283  /// Removes the specified parameter by name, and returns true if the
284  /// parameter was found and successfully removed.
285  bool removeParameter(const UT_StringHolder& name);
286 
287  /// Adds a new file dependency to the node interface
288  void addFileDependency(
289  const UT_StringHolder& file_path);
290 
291  /// Adds a new parameter group to the node interface
292  void addParameterGroup(
293  const UT_StringHolder& name,
294  bool root = true,
295  bool multiparm = false);
296 
297  /// Ends the current parameter group
298  void endParameterGroup();
299 
300  /// If this interface represents a template, returns the name of that
301  /// template
303  { return myTemplateName; }
304 
305  /// Returns true if the node interface is valid
306  bool isValid() const
307  { return myValidFlag; }
308 
309  /// Returns the list of external files that this node depends on.
311  { return myAutoDependencies; }
312 
313  /// Returns the list of common expression variables, available on all
314  /// parameters on this node interface.
316  commonVars() const
317  { return myCommonVars; }
318 
319  /// Returns the underlying application node associated with this PDG node,
320  /// for example a TOP node or TOP scheduler. This may be null.
322  { return myAppNode.get(); }
323 
324  /// Sets the underlying app node.
325  template <typename T, typename... Args>
326  void setAppNode(Args&&... args)
327  {
328  myAppNode = UTmakeUnique<T>(
329  std::forward<Args>(args)...);
330  }
331 
332  /// Returns the attribute info object for this node interface. If this is
333  /// a template loaded from .json, the attribute info object contains the
334  /// definition as it was specified in the template. Otherwise, if this is
335  /// a cooked node, then it contains the evaluated attribute info from the
336  /// last cook.
338  { return myAttributeInfo; }
339 
340  /// Clears and sets the attribute info for this interface
342  { myAttributeInfo = info; }
343 
344  /// Returns the script info for this node interface.
346  { return myScriptInfo; }
347 
348  /// Sets the script info for the interface
350  { myScriptInfo = info; }
351 
352  /// Adds a single entry to the job script info's service compatiblity
353  /// list
354  void setServiceCompatibility(
355  const UT_StringHolder& service_type_name,
356  bool compatible);
357 
358  /// Adds an error to the node interface -- implemented in subclasses
359  virtual void addError(const UT_StringHolder& message) const
360  {}
361 
362  /// Adds an error using a format string, instead of plain string
363  template <typename... Args>
365  const char* fmt,
366  Args&&... args) const
367  {
369  buffer.format(
370  fmt, std::forward<Args>(args)...);
371  addError(buffer.buffer());
372  }
373 
374  /// Adds a warning to the node interface -- implemented in subclasses
375  virtual void addWarning(const UT_StringHolder& message) const
376  {}
377 
378  /// Adds a warning using a format string, instead of plain string
379  template <typename... Args>
381  const char* fmt,
382  Args&&... args) const
383  {
385  buffer.format(
386  fmt, std::forward<Args>(args)...);
387  addWarning(buffer.buffer());
388  }
389 
390  /// Evaluates a parameter and reports errors if desired
391  template <typename T>
393  const UT_StringHolder& name,
394  const PDG_WorkItem* work_item=nullptr,
395  int index=0,
396  int multi=-1) const
397  {
398  PDG_Port* parm = parameter(name, multi);
399  if (!parm)
400  return false;
401 
402  UT_WorkBuffer errors;
403  if (parm->evaluate(index, result, work_item, errors))
404  return true;
405 
406  addError(errors.buffer());
407  return false;
408  }
409 
410  /// Evaluates a string parameter as a raw string, and reports errors if
411  /// desired.
414  const UT_StringHolder& name,
415  const PDG_WorkItem* work_item=nullptr,
416  int index=0,
417  int multi=-1) const
418  {
419  PDG_Port* parm = parameter(name, multi);
420  if (!parm)
421  return false;
422 
423  UT_WorkBuffer errors;
424  if (parm->evaluateRaw(index, result, work_item, errors))
425  return true;
426 
427  addError(errors.buffer());
428  return false;
429  }
430 
431  /// Evaluates a parameter as an array and reports errors if desired
432  template <typename T>
434  T& result,
435  const UT_StringHolder& name,
436  const PDG_WorkItem* work_item=nullptr,
437  int multi=-1) const
438  {
439  PDG_Port* parm = parameter(name, multi);
440  if (!parm)
441  return false;
442 
443  UT_WorkBuffer errors;
444  if (parm->evaluate(result, work_item, errors))
445  return true;
446 
447  addError(errors.buffer());
448  return false;
449  }
450 
451 protected:
453 
454 private:
455  PDG_Port* addPortInternal(
456  PDG_PortType type,
457  const PDG_WorkItemDataType* data_type,
458  const UT_StringHolder& name,
459  const UT_StringHolder& label,
460  int size = 0,
461  bool ordered = true,
462  bool custom = false,
463  bool builtin = false);
464 private:
465  friend class PDG_NodeTemplate;
466 
468 
469  PDG_NodePorts myPorts;
470  TaggedParameters myTaggedParameters;
471  PDG_PortArray myCustomParameters;
472  UT_StringArray myMultiEntries;
473  DependencyArray myAutoDependencies;
474  PDG_Port::ExpressionVars myCommonVars;
475 
476  ParameterGroupArray myParameterGroups;
477 
478  UT_StringHolder myTemplateName;
479  UT_StringHolder mySpecifiedWorkItemDataType;
480  mutable PDG_WorkItemDataType*
481  myWorkItemDataType;
483  myAppNode;
484 
485  PDG_JobScriptInfo myScriptInfo;
486 
487  int myCurrentParameterGroup;
488  int myNumOrderedPorts;
489 
490  bool myUnorderedFlag;
491  bool myValidFlag;
492  bool myNoSchedulerParams;
493  bool myHasCustomInputs;
494  bool myHasCustomOutputs;
495 };
496 
498 
499 #endif
static const UT_StringHolder thePartitionerMergeOpParm
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
static const UT_StringHolder theTagOpDepDirty
PDG_NodeSubtype
Enumeration of node subtypes.
Definition: PDG_Types.h:302
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
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
PDG_NodeType
Enumeration of node types in a PDG graph.
Definition: PDG_Types.h:279
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 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
**But if you need a result
Definition: thread.h:613
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
static const UT_StringHolder theProcessorServiceResetWhenParm
static const UT_StringHolder theSchedulerUseMapZoneParm
static const UT_StringHolder theTagExtraInput
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
PDG_PortType
Enumeration of node port types.
Definition: PDG_Types.h:347
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
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
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:609
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
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
type
Definition: core.h:1059
static const UT_StringHolder theProcessorUseScheduleWhenParm
static const UT_StringHolder theSchedulerDeleteTempDir
static const UT_StringHolder theSchedulerRpcBackoff
const ParameterGroupArray & parameterGroups() const
Returns the list of parameter groups for the node.
static const UT_StringHolder theSchedulerWaitForFailures
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