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 <OP/OP_DataTypes.h>
13 #include <UT/UT_Array.h>
14 #include <UT/UT_StringHolder.h>
15 
16 /// Types of basic data that are passed around a COP network.
17 typedef enum {
36 
37  // This is not a true type of data, but represents a collection of plain
38  // types from above.
40 } COP_Type;
41 
42 /// Returns true if src is implicitly convertible to dst.
44 /// Returns true if src is implicitly convertible to dst in Apex,
45 /// where layers and vdbs are indistinguishable for callbacks..
47 /// Returns the English label for a type.
48 COP_API const char *COPtypeLabel(COP_Type t);
49 /// Returns a type corresponding to the given English label.
51 /// Returns the number of channels for a type.
52 COP_API inline int COPtypeChannels(const COP_Type t)
53 {
54  switch (t)
55  {
56  case COP_TYPE_INT:
57  case COP_TYPE_FLOAT:
58  case COP_TYPE_VDB_FLOAT:
59  case COP_TYPE_VDB_INT:
62  return 1;
63  case COP_TYPE_VECTOR2:
65  return 2;
67  case COP_TYPE_VECTOR:
69  return 3;
70  case COP_TYPE_VECTOR4:
72  return 4;
73  case COP_TYPE_METADATA:
76  case COP_TYPE_UNDEF:
77  case COP_TYPE_GEO:
78  return 1;
79  case COP_TYPE_CABLE:
80  return 0;
81  }
82  UT_ASSERT(!"Unhandled cop type");
83  return 1;
84 }
85 /// Returns true if this is a layer type
91 
92 class COP_CableStructure;
93 class COP_PortData;
94 class IMX_Layer;
95 class IMX_VDB;
96 class IMX_Attribute;
97 
98 /// Type of data that was output by a COP_Verb
99 COP_API COP_Type COPtype(const COP_PortData&, int index = 0);
100 /// Type of data for the given layer
102 /// Type of data for the given vdb
104 /// Type of data for the given attrib
106 
107 /// Signature for a node.
108 /// Signature consists of a name (internal and label), and lists of types for
109 /// the inputs and outputs.
111 {
112 public:
113  /// same as COP_Signature("default", "Default")
114  COP_Signature() : COP_Signature("default", "Default") {}
115  /// Constructs a new signature with the given name and label.
117  /// Constructs a new signature with the given name, label, and number of
118  /// inputs and outputs.
120  int inputs, int outputs);
121  /// Constructs a new signature with the given name, label, and lists of
122  /// inputs and outputs. A character in a list corresponds to an input or
123  /// output. Its type can be one of the following:
124  /// i: COP_TYPE_INT
125  /// m: COP_TYPE_METADATA
126  /// f: COP_TYPE_FLOAT
127  /// u: COP_TYPE_VECTOR2
128  /// v: COP_TYPE_VECTOR
129  /// p: COP_TYPE_VECTOR4
130  /// g: COP_TYPE_GEO
131  /// I: COP_TYPE_VDB_INT
132  /// F: COP_TYPE_VDB_FLOAT
133  /// V: COP_TYPE_VDB_VECTOR
134  /// C: COP_TYPE_CABLE
135  /// If a type is succeeded by the ! symbol, then it's marked as null (or not
136  /// connected).
137  /// If a type is preceeded by 1,2,3 it specifies the dimension,
138  /// 1: IMX_Attribute: COP_TYPE_ATTRIB_
139  /// 2: IMX_Layer: COP_TYPE_
140  /// 3: IMX_VDB: COP_TYPE_VDB_
141  /// The next symbol should be ifuvp to specify the type.
143  const UT_StringRef &input_list,
144  const UT_StringRef &output_list);
145  /// Constructs a signature given lists of types and null states for inputs
146  /// and outputs.
148  const UT_Array<COP_Type> &input_types,
149  const UT_Array<bool> &input_null_states,
150  const UT_Array<COP_Type> &output_types,
151  const UT_Array<bool> &output_null_states);
152 
153  /// Returns the cost of converting all inputs of this signature into types
154  /// from the array.
155  /// If abort_on_impossible is true, returns -1 if one of the inputs is not
156  /// convertible.
157  int getInputConversionCost(const UT_Array<COP_Type> &inputs,
158  bool abort_on_impossible = false) const;
159 
160  /// Sets the number of inputs for this signature. If the current size
161  /// is not zero, the last entry is duplicated to fill array.
162  void setNumberOfInputs(int inputs);
163  /// Sets the number of outputs for this signature. If the current size
164  /// is not zero, the last entry is duplicated to fill array.
165  void setNumberOfOutputs(int outputs);
166  /// Sets the type of an input. If null state of the input is not provided,
167  /// it will stay unchanged from the previous setting.
168  void setInput(OP_InputIdx input, COP_Type type);
169  void setInput(OP_InputIdx input, COP_Type type, bool is_null);
170  /// Sets the type of an output. If null state of the output is not provided,
171  /// it will stay unchanged from the previous setting.
172  void setOutput(OP_OutputIdx output, COP_Type type);
173  void setOutput(OP_OutputIdx output, COP_Type type, bool is_null);
174  /// Sets the connected state of an input.
175  void setInputIsNull(OP_InputIdx input, bool is_null);
176  /// Sets the connected state of an output.
177  void setOutputIsNull(OP_OutputIdx output, bool is_null);
178 
179  /// Returns the number of inputs.
180  int getNumberOfInputs() const;
181  /// Returns the number of outputs.
182  int getNumberOfOutputs() const;
183  /// Get type of the input at the specified index.
184  COP_Type getInputType(OP_InputIdx index) const;
185  /// Get type of the output at the specified index.
186  COP_Type getOutputType(OP_OutputIdx index) const;
187  /// Get whether the input at the specified index is connected.
188  bool isInputNull(OP_InputIdx index) const;
189  /// Get whether the output at the specified index is connected.
190  bool isOutputNull(OP_OutputIdx index) const;
191 
192  /// Returns true if inputs of this signature (starting at i_start) are
193  /// convertible from its outputs (starting at o_start).
194  bool inputsMatchOutputs(OP_InputIdx i_start = 0, OP_OutputIdx o_start = 0)
195  const;
196  /// Returns true if inputs of this signature (starting at i_start) are
197  /// convertible from outputs of the other signature (starting at o_start).
198  /// That is, false is returned if other.outputType(k) is not convertible
199  /// into inputType(k-o_start+i_start) for some k. Only checks valid input
200  /// and output indices.
201  bool inputsMatchOutputs(const COP_Signature& other, OP_InputIdx i_start = 0,
202  OP_OutputIdx o_start = 0) const;
203 
204  /// Returns true if this signature has an input that is of cable type.
205  bool hasCableInput() const;
206  /// Returns true if this signature has an output that is of cable type.
207  bool hasCableOutput() const;
208 
209  /// Makes a list of cable structures for the inputs. Each cable stucture
210  /// has a single field that's the same type as the corresponding input on
211  /// this signature.
212  UT_Array<COP_CableStructure> makeInputCableStructures() const;
213 
214  /// Returns the internal name of this signature.
215  const UT_StringHolder &getName() const { return myName; }
216  /// Returns the English label for this signature.
217  const UT_StringHolder &getLabel() const { return myLabel; }
218  /// Changes name of this signature.
219  void setName(const UT_StringHolder& name) { myName = name; }
220  /// Changes label for this signature.
221  void setLabel(const UT_StringHolder& label) { myLabel = label; }
222 
223  /// Removes the input at the given index.
224  void removeInput(OP_InputIdx index);
225  /// Removes the output at the given index.
226  void removeOutput(OP_OutputIdx index);
227 
228  UT_StringHolder format() const;
229  /// Returns the format string for encoding all inputs (including their null
230  /// states).
231  UT_StringHolder getInputFormat() const;
232  /// Returns the format string for encoding all outputs (including their null
233  /// states).
234  UT_StringHolder getOutputFormat() const;
235 
236  /// Two signatures are equivalent if all input and output states match
237  /// exactly.
238  bool operator==(const COP_Signature& other) const;
239 
240  /// Returns the array of input null states.
242  {
243  return myInputIsNull;
244  }
245  /// Returns the array of output null states.
247  {
248  return myOutputIsNull;
249  }
250  /// Returns the array of this signature's input types.
252  {
253  return myInputTypes;
254  }
255  /// Returns the array of this signature's output types.
257  {
258  return myOutputTypes;
259  }
260 
261 protected:
262  /// List of input types for this signature.
264  /// List of output types for this signature.
266  /// Flag for each input indicating whether it's null (unconnected).
268  /// Flag for each output indicating whether it's null (unconnected).
270  /// The signature's internal name.
272  /// The signature's label.
274 
275  friend class COP_OperatorInfo;
276 };
277 
278 COP_API size_t
279 UTformatBuffer(char *buffer, size_t buffer_size,
280  const UT_Array<COP_Signature> &v);
281 COP_API size_t
282 UTformatBuffer(char *buffer, size_t buffer_size, const COP_Signature &v);
283 COP_API size_t
284 UTformatBuffer(char *buffer, size_t buffer_size, const COP_Type &v);
285 
void setLabel(const UT_StringHolder &label)
Changes label for this signature.
const UT_Array< bool > & getInputNullStates() const
Returns the array of input null states.
void setName(const UT_StringHolder &name)
Changes name of this signature.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
const GLdouble * v
Definition: glcorearb.h:837
int OP_InputIdx
Definition: OP_DataTypes.h:184
const UT_StringHolder & getName() const
Returns the internal name of this signature.
UT_StringHolder myName
The signature's internal name.
GLuint buffer
Definition: glcorearb.h:660
COP_API COP_Type COPtype(const COP_PortData &, int index=0)
Type of data that was output by a COP_Verb.
COP_API bool COPtypeIsLayerOrUndef(COP_Type t)
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
COP_API bool COPtypeIsConvertible(COP_Type src, COP_Type dst)
Returns true if src is implicitly convertible to dst.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
COP_Signature()
same as COP_Signature("default", "Default")
COP_API bool COPtypeIsGeo(COP_Type t)
UT_Array< COP_Type > myOutputTypes
List of output types for this signature.
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
COP_API bool COPtypeIsApexConvertible(COP_Type src, COP_Type dst)
COP_API bool COPtypeIsLayer(COP_Type t)
Returns true if this is a layer type.
COP_API bool COPtypeIsAttribute(COP_Type t)
COP_API size_t UTformatBuffer(char *buffer, size_t buffer_size, const UT_Array< COP_Signature > &v)
GLuint const GLchar * name
Definition: glcorearb.h:786
const UT_Array< COP_Type > & getOutputTypes() const
Returns the array of this signature's output types.
UT_StringHolder myLabel
The signature's label.
COP_API COP_Type COPtypeFromLabel(const char *label)
Returns a type corresponding to the given English label.
const UT_Array< COP_Type > & getInputTypes() const
Returns the array of this signature's input types.
GLdouble t
Definition: glad.h:2397
COP_Type
Types of basic data that are passed around a COP network.
Definition: COP_Signature.h:17
const UT_StringHolder & getLabel() const
Returns the English label for this signature.
GLenum GLenum dst
Definition: glcorearb.h:1793
UT_Array< bool > myInputIsNull
Flag for each input indicating whether it's null (unconnected).
UT_Array< COP_Type > myInputTypes
List of input types for this signature.
COP_API int COPtypeChannels(const COP_Type t)
Returns the number of channels for a type.
Definition: COP_Signature.h:52
GLuint index
Definition: glcorearb.h:786
COP_API const char * COPtypeLabel(COP_Type t)
Returns the English label for a type.
#define COP_API
Definition: COP_API.h:8
int OP_OutputIdx
Definition: OP_DataTypes.h:185
const UT_Array< bool > & getOutputNullStates() const
Returns the array of output null states.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
COP_API bool COPtypeIsVDB(COP_Type t)
UT_Array< bool > myOutputIsNull
Flag for each output indicating whether it's null (unconnected).
GLenum src
Definition: glcorearb.h:1793