HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
COP_Signature.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  */
7 
8 #pragma once
9 
10 #include "COP_API.h"
11 
12 #include <UT/UT_Array.h>
13 #include <UT/UT_StringHolder.h>
14 
15 /// Types of basic data that are passed around a COP network.
16 typedef enum {
25 } COP_Type;
26 
27 /// Returns true if src is implicitly convertible to dst.
29 
30 COP_API const char *COPtypeLabel(COP_Type t);
32 
33 COP_API inline int COPtypeChannels(const COP_Type t)
34 {
35  switch (t)
36  {
37  case COP_TYPE_VECTOR2: return 2;
38  case COP_TYPE_VECTOR: return 3;
39  case COP_TYPE_VECTOR4: return 4;
40  default: return 1;
41  }
42 }
43 
44 class COP_PortData;
45 class IMX_Layer;
46 
47 /// Type of data that was output by a COP_Verb
48 COP_API COP_Type COPtype(const COP_PortData&);
49 /// Type of data for the given layer
51 
52 /// Signature for a node.
53 /// Signature consists of a name (internal and label), and lists of types for
54 /// the inputs and outputs.
55 /// The *number* of inputs and outputs is independent of this and set by the
56 /// verb min/max Inputs/Outputs and the current state of the GUI. If not enough
57 /// types are specified the last one is repeated for any extra inputs and outputs.
58 /// This helps with making signatures reusable between different verbs.
60 {
61 public:
62  /// same as COP_Signature("default", "Default")
63  COP_Signature() : COP_Signature("default", "Default") {}
64  /// Constructs a new signature with the given name and label.
66  /// Constructs a new signature with the given name, label, and number of
67  /// inputs and outputs.
69  int inputs, int outputs);
70  /// Constructs a new signature with the given name, label, and lists of
71  /// inputs and outputs. A character in a list corresponds to an input or
72  /// output. Its type can be one of the following:
73  /// i: COP_TYPE_INT
74  /// m: COP_TYPE_METADATA
75  /// f/1: COP_TYPE_FLOAT
76  /// u/2: COP_TYPE_VECTOR2
77  /// v/3: COP_TYPE_VECTOR
78  /// p/4: COP_TYPE_VECTOR4
79  /// g: COP_TYPE_GEO
81  const UT_StringRef &input_list,
82  const UT_StringRef &output_list);
83 
84 #if 0
85  /// Call this function to set all inputs at once using the variadic
86  /// arguments.
87  template <typename... TYPE>
88  void setInputs(TYPE... inputs);
89  /// Call this function to set all outputs at once using the variadic
90  /// arguments.
91  template <typename... TYPE>
92  void setOutputs(TYPE... outputs);
93 #endif
94 
95  /// Returns the cost of converting all inputs of this signature into types
96  /// from the array.
97  /// If abort_on_impossible is true, returns -1 if one of the inputs is not
98  /// convertible.
99  int getInputConversionCost(const UT_Array<COP_Type> &inputs,
100  bool abort_on_impossible = false) const;
101 
102  /// Sets the number of inputs for this signature. If the current size
103  /// is not zero, the last entry is duplicated to fill array.
104  void setNumberOfInputs(int inputs);
105  /// Sets the number of outputs for this signature. If the current size
106  /// is not zero, the last entry is duplicated to fill array.
107  void setNumberOfOutputs(int outputs);
108  /// Sets the type of an input.
109  void setInput(int input, COP_Type type);
110  /// Sets the type of an output;
111  void setOutput(int output, COP_Type type);
112 
113  /// Returns the number of inputs.
114  int getNumberOfInputs() const;
115  /// Returns the number of outputs.
116  int getNumberOfOutputs() const;
117  /// Get type of the input at the specified index.
118  COP_Type getInputType(int index) const;
119  /// Get type of the output at the specified index.
120  COP_Type getOutputType(int index) const;
121 
122  /// Returns true if inputs (starting at i_start) are convertible from the
123  /// outputs (starting at o_start). That is, false is returned if
124  /// - (inputs - i_start) is larger (outputs - o_start), or
125  /// - inputType(k) is not convertible into outputType(k-i_start+o_start)
126  /// for some (inputs > k >= i_start).
127  bool inputsMatchOutputs(int i_start = 0, int o_start = 0) const;
128 
129  /// Returns the internal name of this signature.
130  const UT_StringHolder &getName() const { return myName; }
131  /// Returns the English label for this signature.
132  const UT_StringHolder &getLabel() const { return myLabel; }
133  /// Changes name of this signature.
134  void setName(const UT_StringHolder& name) { myName = name; }
135  /// Changes label for this signature.
136  void setLabel(const UT_StringHolder& label) { myLabel = label; }
137 
138  /// Removes the input at the given index.
139  void removeInput(int index);
140  /// Removes the output at the given index.
141  void removeOutput(int index);
142 
143  UT_StringHolder format() const;
144 
145 protected:
146  /// List of input types for this signature.
148  /// List of output types for this signature.
150  /// The signature's internal name.
152  /// The signature's label.
154 
155  friend class COP_OperatorInfo;
156 };
void setLabel(const UT_StringHolder &label)
Changes label for this signature.
void setName(const UT_StringHolder &name)
Changes name of this signature.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
const UT_StringHolder & getName() const
Returns the internal name of this signature.
UT_StringHolder myName
The signature's internal name.
COP_API bool COPtypeIsConvertible(COP_Type src, COP_Type dst)
Returns true if src is implicitly convertible to dst.
COP_Signature()
same as COP_Signature("default", "Default")
Definition: COP_Signature.h:63
UT_Array< COP_Type > myOutputTypes
List of output types for this signature.
COP_API COP_Type COPtype(const COP_PortData &)
Type of data that was output by a COP_Verb.
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_StringHolder myLabel
The signature's label.
COP_API COP_Type COPtypeFromLabel(const char *label)
GLdouble t
Definition: glad.h:2397
COP_Type
Types of basic data that are passed around a COP network.
Definition: COP_Signature.h:16
const UT_StringHolder & getLabel() const
Returns the English label for this signature.
GLenum GLenum dst
Definition: glcorearb.h:1793
UT_Array< COP_Type > myInputTypes
List of input types for this signature.
COP_API int COPtypeChannels(const COP_Type t)
Definition: COP_Signature.h:33
GLuint index
Definition: glcorearb.h:786
COP_API const char * COPtypeLabel(COP_Type t)
#define COP_API
Definition: COP_API.h:8
type
Definition: core.h:1059
GLenum src
Definition: glcorearb.h:1793