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.
82 
85 
88 
93 
100 
106 
110 
116 
119 
121 
136 
144 
149 
151 
154 
155 public:
157  UT_StringHolder name = "",
158  UT_StringHolder data_type = "");
159  virtual ~PDG_NodeInterface();
160 
161  int64 getMemoryUsage(bool inclusive) const;
162 
163  /// Clones the template interface into the ports/parameters on this
164  /// interface.
165  void cloneFrom(const PDG_NodeInterface& interface);
166 
167  /// Adds builtin ports for the specified node type and subtype
168  void addBuiltinPorts(
170  PDG_NodeSubtype sub_type);
171 
172  /// Queries the work item data type associated with this node
174  { return myWorkItemDataType; }
176  { return myWorkItemDataType; }
177 
178  /// Resolves and caches the work item data type
179  bool resolveWorkItemDataType(UT_WorkBuffer& errors);
180 
181  /// Returns the list of all ports of the specified type
182  const PDG_PortArray& ports(PDG_PortType type) const;
183  const PDG_PortArray& inputPorts() const;
184  const PDG_PortArray& outputPorts() const;
185  const PDG_PortArray& parameters() const;
186 
187  /// Returns the list of parameter groups for the node
189  { return myParameterGroups; }
190 
191  /// Returns the list of parameters with the specified tag
192  bool parametersForTag(
193  const UT_StringHolder& tag,
194  PDG_PortArray& parameters) const;
195 
196  /// Returns the list of custom parameter ports.
197  const PDG_PortArray& customParameters() const;
198 
199  /// Find a port by type, index and/or name. If no matching port is found,
200  /// nullptr is returned.
201  PDG_Port* port(PDG_PortType type, int index) const;
202  PDG_Port* port(
204  const UT_StringHolder& name) const;
205  PDG_Port* port(const UT_StringHolder& name) const;
206 
207  /// Specialized functions for finding input ports by name or index
208  PDG_Port* inputPort(int index) const;
209  PDG_Port* inputPort(const UT_StringHolder& name) const;
210  bool inputPortsForNode(
211  PDG_Node* node,
212  PDG_PortArray& ports) const;
213  bool inputPortsForWorkItem(
214  const PDG_WorkItem* work_item,
215  PDG_PortArray& ports) const;
216  bool isWorkItemFromInputPort(
217  const PDG_WorkItem* work_item,
218  const UT_StringHolder& name) const;
219 
220  /// Sepcialized functions for finding output ports by name or index
221  PDG_Port* outputPort(int index) const;
222  PDG_Port* outputPort(const UT_StringHolder& name) const;
223 
224  /// Returns the parameter with the specified name, or nullptr if no such
225  /// parameter exists.
226  PDG_Port* parameter(
227  const UT_StringHolder& name,
228  int multi=-1) const;
229 
230  /// Returns the value and default value of the parameter with the
231  /// specified name and index. If no parameter is found or the index is
232  /// out of range, nullptr is returned.
233  PDGT_Value* paramValue(
234  const UT_StringHolder& name,
235  int index=0) const;
236  PDGT_Value* defaultParamValue(
237  const UT_StringHolder& name,
238  int index=0) const;
239 
240  /// Returns the numbers of ports with the specified type (input,
241  /// output, etc).
242  int portCount(PDG_PortType type) const;
243  int inputCount() const;
244  int outputCount() const;
245  int parameterCount() const;
246 
247  /// Returns information about the number of ordered vs. unordered input
248  /// ports on this node.
249  bool hasUnorderedPorts() const;
250  int numOrderedPorts() const;
251 
252  /// Adds the specified port, which can be an input, output or a parameter.
253  /// Returns the new port on success, else returns failure.
254  PDG_Port* addPort(
256  const PDG_WorkItemDataType* data_type,
257  const UT_StringHolder& name,
258  const UT_StringHolder& label,
259  const UT_StringArray& tags = UT_StringArray(),
260  int size = 0,
261  bool ordered = true,
262  bool custom = false);
263 
264  /// Adds a parameter with the specified data type, size, name, label and
265  /// tag list. Returns the parameter on success, or nullptr on failure.
266  PDG_Port* addParameter(
267  PDGT_Value::DataType data_type,
268  const UT_StringHolder& name,
269  const UT_StringHolder& label,
270  const UT_StringArray& tags,
271  int size = 1,
272  bool custom = false);
273 
274  /// Adds a parameter with a data type, name, label and optional size.
275  PDG_Port* addParameter(
276  PDGT_Value::DataType data_type,
277  const UT_StringHolder& name,
278  const UT_StringHolder& label,
279  int size = 1,
280  bool custom = false);
281 
282  /// Removes the specified parameter by name, and returns true if the
283  /// parameter was found and successfully removed.
284  bool removeParameter(const UT_StringHolder& name);
285 
286  /// Adds a new file dependency to the node interface
287  void addFileDependency(
288  const UT_StringHolder& file_path);
289 
290  /// Adds a new parameter group to the node interface
291  void addParameterGroup(
292  const UT_StringHolder& name,
293  bool root = true,
294  bool multiparm = false);
295 
296  /// Ends the current parameter group
297  void endParameterGroup();
298 
299  /// If this interface represents a template, returns the name of that
300  /// template
302  { return myTemplateName; }
303 
304  /// Returns the template interface that defined how this interface
305  /// was created
306  virtual const PDG_NodeInterface*
308  { return nullptr; }
309 
310  /// Returns true if the node interface is valid
311  bool isValid() const
312  { return myValidFlag; }
313 
314  /// Returns the list of external files that this node depends on.
316  { return myAutoDependencies; }
317 
318  /// Returns the list of common expression variables, available on all
319  /// parameters on this node interface.
321  commonVars() const
322  { return myCommonVars; }
323 
324  /// Returns the underlying application node associated with this PDG node,
325  /// for example a TOP node or TOP scheduler. This may be null.
327  { return myAppNode.get(); }
328 
329  /// Sets the underlying app node.
330  template <typename T, typename... Args>
331  void setAppNode(Args&&... args)
332  {
333  myAppNode = UTmakeUnique<T>(
334  std::forward<Args>(args)...);
335  }
336 
337  /// Returns the attribute info object for this node interface. If this is
338  /// a template loaded from .json, the attribute info object contains the
339  /// definition as it was specified in the template. Otherwise, if this is
340  /// a cooked node, then it contains the evaluated attribute info from the
341  /// last cook.
343  { return myAttributeInfo; }
344 
345  /// Clears and sets the attribute info for this interface
347  { myAttributeInfo = info; }
348 
349  /// Returns the script info for this node interface.
351  { return myScriptInfo; }
352 
353  /// Sets the script info for the interface
355  { myScriptInfo = info; }
356 
357  /// Adds a single entry to the job script info's service compatiblity
358  /// list
359  void setServiceCompatibility(
360  const UT_StringHolder& service_type_name,
361  bool compatible);
362 
363  /// Adds an error to the node interface -- implemented in subclasses
364  virtual void addError(const UT_StringHolder& message) const
365  {}
366 
367  /// Adds an error using a format string, instead of plain string
368  template <typename... Args>
370  const char* fmt,
371  Args&&... args) const
372  {
374  buffer.format(
375  fmt, std::forward<Args>(args)...);
376  addError(buffer.buffer());
377  }
378 
379  /// Adds a warning to the node interface -- implemented in subclasses
380  virtual void addWarning(const UT_StringHolder& message) const
381  {}
382 
383  /// Adds a warning using a format string, instead of plain string
384  template <typename... Args>
386  const char* fmt,
387  Args&&... args) const
388  {
390  buffer.format(
391  fmt, std::forward<Args>(args)...);
392  addWarning(buffer.buffer());
393  }
394 
395  /// Evaluates a parameter and reports errors if desired
396  template <typename T>
398  const UT_StringHolder& name,
399  const PDG_WorkItem* work_item=nullptr,
400  int index=0,
401  int multi=-1) const
402  {
403  PDG_Port* parm = parameter(name, multi);
404  if (!parm)
405  return false;
406 
407  UT_WorkBuffer errors;
408  if (parm->evaluate(index, result, work_item, errors))
409  return true;
410 
411  addError(errors.buffer());
412  return false;
413  }
414 
415  /// Evaluates a string parameter as a raw string, and reports errors if
416  /// desired.
419  const UT_StringHolder& name,
420  const PDG_WorkItem* work_item=nullptr,
421  int index=0,
422  int multi=-1) const
423  {
424  PDG_Port* parm = parameter(name, multi);
425  if (!parm)
426  return false;
427 
428  UT_WorkBuffer errors;
429  if (parm->evaluateRaw(index, result, work_item, errors))
430  return true;
431 
432  addError(errors.buffer());
433  return false;
434  }
435 
436  /// Evaluates a parameter as an array and reports errors if desired
437  template <typename T>
439  T& result,
440  const UT_StringHolder& name,
441  const PDG_WorkItem* work_item=nullptr,
442  int multi=-1) const
443  {
444  PDG_Port* parm = parameter(name, multi);
445  if (!parm)
446  return false;
447 
448  UT_WorkBuffer errors;
449  if (parm->evaluate(result, work_item, errors))
450  return true;
451 
452  addError(errors.buffer());
453  return false;
454  }
455 
456 protected:
458 
459 private:
460  PDG_Port* addPortInternal(
461  PDG_PortType type,
462  const PDG_WorkItemDataType* data_type,
463  const UT_StringHolder& name,
464  const UT_StringHolder& label,
465  int size = 0,
466  bool ordered = true,
467  bool custom = false,
468  bool builtin = false);
469 private:
470  friend class PDG_NodeTemplate;
471 
473 
474  PDG_NodePorts myPorts;
475  TaggedParameters myTaggedParameters;
476  PDG_PortArray myCustomParameters;
477  UT_StringArray myMultiEntries;
478  DependencyArray myAutoDependencies;
479  PDG_Port::ExpressionVars myCommonVars;
480 
481  ParameterGroupArray myParameterGroups;
482 
483  UT_StringHolder myTemplateName;
484  UT_StringHolder mySpecifiedWorkItemDataType;
485  mutable PDG_WorkItemDataType*
486  myWorkItemDataType;
488  myAppNode;
489 
490  PDG_JobScriptInfo myScriptInfo;
491 
492  int myCurrentParameterGroup;
493  int myNumOrderedPorts;
494 
495  bool myUnorderedFlag;
496  bool myValidFlag;
497  bool myNoSchedulerParams;
498  bool myHasCustomInputs;
499  bool myHasCustomOutputs;
500 };
501 
503 
504 #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 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
**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
PDG_NodeType
Enumeration of node types in a PDG graph.
Definition: PDG_NodeTypes.h:95
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
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: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
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
type
Definition: core.h:1059
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