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 {
29 
30  // This is not a true type of data, but represents a collection of plain
31  // types from above.
33 } COP_Type;
34 
35 /// Returns true if src is implicitly convertible to dst.
37 /// Returns true if src is implicitly convertible to dst in Apex,
38 /// where layers and vdbs are indistinguishable for callbacks..
40 /// Returns the English label for a type.
41 COP_API const char *COPtypeLabel(COP_Type t);
42 /// Returns a type corresponding to the given English label.
44 /// Returns the number of channels for a type.
45 COP_API inline int COPtypeChannels(const COP_Type t)
46 {
47  switch (t)
48  {
49  case COP_TYPE_INT:
50  case COP_TYPE_FLOAT:
51  case COP_TYPE_VDB_FLOAT:
52  case COP_TYPE_VDB_INT:
53  return 1;
54  case COP_TYPE_VECTOR2:
55  return 2;
57  case COP_TYPE_VECTOR:
58  return 3;
59  case COP_TYPE_VECTOR4:
60  return 4;
61  case COP_TYPE_METADATA:
62  case COP_TYPE_UNDEF:
63  case COP_TYPE_GEO:
64  return 1;
65  case COP_TYPE_CABLE:
66  return 0;
67  }
68  UT_ASSERT(!"Unhandled cop type");
69  return 1;
70 }
71 /// Returns true if this is a layer type
76 
77 class COP_CableStructure;
78 class COP_PortData;
79 class IMX_Layer;
80 class IMX_VDB;
81 
82 /// Type of data that was output by a COP_Verb
83 COP_API COP_Type COPtype(const COP_PortData&, int index = 0);
84 /// Type of data for the given layer
86 /// Type of data for the given vdb
88 
89 /// Signature for a node.
90 /// Signature consists of a name (internal and label), and lists of types for
91 /// the inputs and outputs.
93 {
94 public:
95  /// same as COP_Signature("default", "Default")
96  COP_Signature() : COP_Signature("default", "Default") {}
97  /// Constructs a new signature with the given name and label.
99  /// Constructs a new signature with the given name, label, and number of
100  /// inputs and outputs.
102  int inputs, int outputs);
103  /// Constructs a new signature with the given name, label, and lists of
104  /// inputs and outputs. A character in a list corresponds to an input or
105  /// output. Its type can be one of the following:
106  /// i: COP_TYPE_INT
107  /// m: COP_TYPE_METADATA
108  /// f: COP_TYPE_FLOAT
109  /// u: COP_TYPE_VECTOR2
110  /// v: COP_TYPE_VECTOR
111  /// p: COP_TYPE_VECTOR4
112  /// g: COP_TYPE_GEO
113  /// I: COP_TYPE_VDB_INT
114  /// F: COP_TYPE_VDB_FLOAT
115  /// V: COP_TYPE_VDB_VECTOR
116  /// C: COP_TYPE_CABLE
117  /// If a type is succeeded by the ! symbol, then it's marked as null (or not
118  /// connected).
120  const UT_StringRef &input_list,
121  const UT_StringRef &output_list);
122 
123  /// Returns the cost of converting all inputs of this signature into types
124  /// from the array.
125  /// If abort_on_impossible is true, returns -1 if one of the inputs is not
126  /// convertible.
127  int getInputConversionCost(const UT_Array<COP_Type> &inputs,
128  bool abort_on_impossible = false) const;
129 
130  /// Sets the number of inputs for this signature. If the current size
131  /// is not zero, the last entry is duplicated to fill array.
132  void setNumberOfInputs(int inputs);
133  /// Sets the number of outputs for this signature. If the current size
134  /// is not zero, the last entry is duplicated to fill array.
135  void setNumberOfOutputs(int outputs);
136  /// Sets the type of an input. If null state of the input is not provided,
137  /// it will stay unchanged from the previous setting.
138  void setInput(OP_InputIdx input, COP_Type type);
139  void setInput(OP_InputIdx input, COP_Type type, bool is_null);
140  /// Sets the type of an output. If null state of the output is not provided,
141  /// it will stay unchanged from the previous setting.
142  void setOutput(OP_OutputIdx output, COP_Type type);
143  void setOutput(OP_OutputIdx output, COP_Type type, bool is_null);
144  /// Sets the connected state of an input.
145  void setInputIsNull(OP_InputIdx input, bool is_null);
146  /// Sets the connected state of an output.
147  void setOutputIsNull(OP_OutputIdx output, bool is_null);
148 
149  /// Returns the number of inputs.
150  int getNumberOfInputs() const;
151  /// Returns the number of outputs.
152  int getNumberOfOutputs() const;
153  /// Get type of the input at the specified index.
154  COP_Type getInputType(OP_InputIdx index) const;
155  /// Get type of the output at the specified index.
156  COP_Type getOutputType(OP_OutputIdx index) const;
157  /// Get whether the input at the specified index is connected.
158  bool isInputNull(OP_InputIdx index) const;
159  /// Get whether the output at the specified index is connected.
160  bool isOutputNull(OP_OutputIdx index) const;
161 
162  /// Returns true if inputs of this signature (starting at i_start) are
163  /// convertible from its outputs (starting at o_start).
164  bool inputsMatchOutputs(OP_InputIdx i_start = 0, OP_OutputIdx o_start = 0)
165  const;
166  /// Returns true if inputs of this signature (starting at i_start) are
167  /// convertible from outputs of the other signature (starting at o_start).
168  /// That is, false is returned if other.outputType(k) is not convertible
169  /// into inputType(k-o_start+i_start) for some k. Only checks valid input
170  /// and output indices.
171  bool inputsMatchOutputs(const COP_Signature& other, OP_InputIdx i_start = 0,
172  OP_OutputIdx o_start = 0) const;
173 
174  /// Returns true if this signature has an input that is of cable type.
175  bool hasCableInput() const;
176 
177  /// Makes a list of cable structures for the inputs. Each cable stucture
178  /// has a single field that's the same type as the corresponding input on
179  /// this signature.
180  UT_Array<COP_CableStructure> makeInputCableStructures() const;
181 
182  /// Returns the internal name of this signature.
183  const UT_StringHolder &getName() const { return myName; }
184  /// Returns the English label for this signature.
185  const UT_StringHolder &getLabel() const { return myLabel; }
186  /// Changes name of this signature.
187  void setName(const UT_StringHolder& name) { myName = name; }
188  /// Changes label for this signature.
189  void setLabel(const UT_StringHolder& label) { myLabel = label; }
190 
191  /// Removes the input at the given index.
192  void removeInput(OP_InputIdx index);
193  /// Removes the output at the given index.
194  void removeOutput(OP_OutputIdx index);
195 
196  UT_StringHolder format() const;
197  /// Returns the format string for encoding all inputs (including their null
198  /// states).
199  UT_StringHolder getInputFormat() const;
200  /// Returns the format string for encoding all outputs (including their null
201  /// states).
202  UT_StringHolder getOutputFormat() const;
203 
204  /// Two signatures are equivalent if all input and output states match
205  /// exactly.
206  bool operator==(const COP_Signature& other) const;
207 
208  /// Returns the array of input null states.
210  {
211  return myInputIsNull;
212  }
213  /// Returns the array of output null states.
215  {
216  return myOutputIsNull;
217  }
218  /// Returns the array of this signature's input types.
220  {
221  return myInputTypes;
222  }
223  /// Returns the array of this signature's output types.
225  {
226  return myOutputTypes;
227  }
228 
229 protected:
230  /// List of input types for this signature.
232  /// List of output types for this signature.
234  /// Flag for each input indicating whether it's null (unconnected).
236  /// Flag for each output indicating whether it's null (unconnected).
238  /// The signature's internal name.
240  /// The signature's label.
242 
243  friend class COP_OperatorInfo;
244 };
245 
246 COP_API size_t format(char *buffer, size_t buffer_size, const UT_Array<COP_Signature> &v);
247 COP_API size_t format(char *buffer, size_t buffer_size, const COP_Signature &v);
248 COP_API size_t format(char *buffer, size_t buffer_size, const COP_Type &v);
249 
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")
Definition: COP_Signature.h:96
COP_API bool COPtypeIsGeo(COP_Type t)
UT_Array< COP_Type > myOutputTypes
List of output types for this signature.
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.
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_API size_t format(char *buffer, size_t buffer_size, const UT_Array< COP_Signature > &v)
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:45
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:156
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