HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_DataTypes.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  * NAME: OP library (C++)
7  *
8  * COMMENTS: Data types for cooked data
9  *
10  */
11 
12 #ifndef __OP_DataTypes_h__
13 #define __OP_DataTypes_h__
14 
15 #include <SYS/SYS_Deprecated.h>
16 #include <UT/UT_ValArray.h>
17 #include <UT/UT_IntrusivePtr.h>
18 #include <UT/UT_UniquePtr.h>
19 
20 /// Enabling these types can catch unwanted implicit conversions for node port
21 /// indices, and are helpful in catching misuse of these types (see r499653 for
22 /// an example that was caught using these types). This is especially helpful to
23 /// use if you are trying to remove uses of `unsigned` for input/output indices,
24 /// since negative values can refer to spare inputs/outputs.
25 ///
26 /// TODO: This currently only builds for OP and COP. It would be nice to sweep
27 /// the rest of the code to use these type aliases instead of `int`,
28 /// `unsigned`, etc.
29 #define OP_USE_STRICT_IDX_TYPES 0
30 #if OP_USE_STRICT_IDX_TYPES
31  // Includes needed for OP_IdxType wrapper
32  #include <SYS/SYS_Hash.h>
33  #include <UT/UT_Format.h>
34  #include <ostream>
35 #endif // OP_USE_STRICT_IDX_TYPES
36 
37 class OP_NetworkBoxItem;
38 class OP_Node;
40 
44 
45 #if OP_USE_STRICT_IDX_TYPES
46 
47 #define OP_ARITHMETIC(TEMPLATE, __VA_ARGS__) \
48  TEMPLATE(+, __VA_ARGS__) \
49  TEMPLATE(-, __VA_ARGS__) \
50  TEMPLATE(*, __VA_ARGS__) \
51  TEMPLATE(/, __VA_ARGS__) \
52  TEMPLATE(%, __VA_ARGS__)
53 
54 #define OP_COMPARISON(TEMPLATE, __VA_ARGS__) \
55  TEMPLATE(<, __VA_ARGS__) \
56  TEMPLATE(<=, __VA_ARGS__) \
57  TEMPLATE(>, __VA_ARGS__) \
58  TEMPLATE(>=, __VA_ARGS__) \
59  TEMPLATE(==, __VA_ARGS__) \
60  TEMPLATE(!=, __VA_ARGS__)
61 
62 template <typename Tag>
63 struct OP_IdxType
64 {
65  exint myValue;
66 
67  constexpr OP_IdxType() noexcept = default;
68  constexpr OP_IdxType(int v) : myValue(v) {}
69  constexpr OP_IdxType(exint v) : myValue(v) {}
70  constexpr OP_IdxType(const OP_IdxType &) noexcept = default;
71  constexpr OP_IdxType(OP_IdxType &&) noexcept = default;
72 
73  constexpr OP_IdxType &operator=(const OP_IdxType &) = default;
74  constexpr OP_IdxType &operator=(OP_IdxType &&) = default;
75 
76  /// Explicit conversion between different types of indices (i.e. between
77  /// an index to an input port and an index to an output port).
78  template <typename OtherTag>
79  constexpr explicit OP_IdxType(const OP_IdxType<OtherTag> &other)
80  : myValue(other.myValue) {}
81 
82  /// We should not be using `unsigned` as indices, so we require an explicit
83  /// conversion to ensure correctness.
84  constexpr explicit OP_IdxType(unsigned v) : myValue(v) {}
85 
86  // Allowed conversions:
87  constexpr OP_IdxType &operator=(int v) { myValue = v; return *this; }
88  constexpr OP_IdxType &operator=(exint v) { myValue = v; return *this; }
89  constexpr explicit operator int() const { return myValue; }
90  constexpr explicit operator bool() const { return myValue; }
91  constexpr operator exint() const { return myValue; }
92  constexpr operator UT::Format::ArgValue() const { return myValue; }
93 
94  // Delete any other implicit conversions:
95  template <typename T> constexpr OP_IdxType(T) = delete;
96  template <typename T> constexpr OP_IdxType &operator=(T v) = delete;
97  template <typename T> constexpr operator T() const = delete;
98 
99  // Increment/decrement operators needed for an index type:
100  constexpr OP_IdxType &operator++() { ++myValue; return *this; }
101  constexpr OP_IdxType &operator--() { --myValue; return *this; }
102  constexpr OP_IdxType operator++(int)
103  { OP_IdxType tmp = *this; ++myValue; return tmp; }
104  constexpr OP_IdxType operator--(int)
105  { OP_IdxType tmp = *this; --myValue; return tmp; }
106  constexpr OP_IdxType &operator+=(int other)
107  { myValue += other; return *this; }
108  constexpr OP_IdxType &operator+=(OP_IdxType other)
109  { myValue += other; return *this; }
110 
111  /// Get the address of the internal index value
112  /// @{
113  constexpr const exint *operator&() const { return &myValue; }
114  constexpr exint *operator&() { return &myValue; }
115  /// @}
116 
117  // Define arithmetic with same index type:
118 #define OP_IDXTYPE_ARITHMETIC_TEMPLATE(OPERATOR) \
119  constexpr OP_IdxType operator OPERATOR (OP_IdxType other) const \
120  { return OP_IdxType(myValue OPERATOR other.myValue); }
121  OP_ARITHMETIC(OP_IDXTYPE_ARITHMETIC_TEMPLATE)
122 #undef OP_IDXTYPE_ARITHMETIC_TEMPLATE
123 
124  // Define comparison with same index type:
125 #define OP_IDXTYPE_COMPARISON_TEMPLATE(OPERATOR) \
126  constexpr bool operator OPERATOR (OP_IdxType other) const \
127  { return myValue OPERATOR other.myValue; }
128  OP_COMPARISON(OP_IDXTYPE_COMPARISON_TEMPLATE)
129 #undef OP_IDXTYPE_COMPARISON_TEMPLATE
130 };
131 
132 // Define arithmetic with integral types:
133 #define OP_IDXTYPE_ARITHMETIC_TEMPLATE(OPERATOR, TYPE) \
134  template <typename Tag> \
135  constexpr TYPE operator OPERATOR (TYPE lhs, OP_IdxType<Tag> rhs) \
136  { return lhs OPERATOR rhs.myValue; } \
137  template <typename Tag> \
138  constexpr TYPE operator OPERATOR (OP_IdxType<Tag> lhs, TYPE rhs) \
139  { return lhs.myValue OPERATOR rhs; }
140 OP_ARITHMETIC(OP_IDXTYPE_ARITHMETIC_TEMPLATE, int)
141 OP_ARITHMETIC(OP_IDXTYPE_ARITHMETIC_TEMPLATE, exint)
142 OP_ARITHMETIC(OP_IDXTYPE_ARITHMETIC_TEMPLATE, unsigned)
143 #undef OP_IDXTYPE_ARITHMETIC_TEMPLATE
144 
145 // Define comparison with integral types:
146 #define OP_IDXTYPE_COMPARISON_TEMPLATE(OPERATOR, TYPE) \
147  template <typename Tag> \
148  constexpr bool operator OPERATOR (TYPE lhs, OP_IdxType<Tag> rhs) \
149  { return lhs OPERATOR rhs.myValue; } \
150  template <typename Tag> \
151  constexpr bool operator OPERATOR (OP_IdxType<Tag> lhs, TYPE rhs) \
152  { return lhs.myValue OPERATOR rhs; }
153 OP_COMPARISON(OP_IDXTYPE_COMPARISON_TEMPLATE, int)
154 OP_COMPARISON(OP_IDXTYPE_COMPARISON_TEMPLATE, exint)
155 OP_COMPARISON(OP_IDXTYPE_COMPARISON_TEMPLATE, unsigned)
156 #undef OP_IDXTYPE_COMPARISON_TEMPLATE
157 
158 #undef OP_ARITHMETIC
159 #undef OP_COMPARISON
160 
161 template <typename Tag>
162 constexpr std::ostream &operator<<(std::ostream &os, OP_IdxType<Tag> idx)
163 { return os << idx.myValue; }
164 
165 template <typename Tag>
166 inline SYS_HashType hash_value(OP_IdxType<Tag> idx)
167 { return SYShash(idx.myValue); }
168 
169 /// Tags used to distinguish between different index types.
170 /// @see OP_IdxType
171 /// @{
172 struct OP_IdxTypeInputTag {};
173 struct OP_IdxTypeOutputTag {};
174 /// @}
175 using OP_InputIdx = OP_IdxType<OP_IdxTypeInputTag>;
176 using OP_OutputIdx = OP_IdxType<OP_IdxTypeOutputTag>;
177 
178 #else
179 /// Type aliases that should be used for indices referencing node input/output
180 /// ports. These types should really be `exint`, but for compatibility with the
181 /// hundreds of places we use these indices, these are `int` for now. For that
182 /// reason you might see `static_cast<int>(...)` despite this type being `int`.
183 /// @{
184 using OP_InputIdx = int;
186 /// @}
187 #endif // OP_USE_STRICT_IDX_TYPES
188 
190 {
191  OP_NO_DATA, // No cooked data associated with the node
192  OP_GEOMETRY_DATA, // Cooked data in geometry format
193  OP_TRANSFORM_DATA, // Cooked data as a transform
194  OP_OTHER_DATA, // Generic catch all
195  OP_CHANNEL_DATA, // Channel collection output
196  OP_SHADER_DATA, // Shader data
197  OP_SIM_DATA, // Dynamics data
198  OP_RASTER_DATA, // Raster data
199  OP_SCENE_DATA, // Scene description
200  OP_LAYER_DATA, // IMX Layer data
201  OP_NUM_DATA_TYPES // sentinel
202 };
203 // For backwards
205 
207 {
208  OP_INTEREST_NONE = 0x00, // I'm not interested
209  OP_INTEREST_PARM = 0x01, // interested in a parameter changes (rare)
210  OP_INTEREST_DATA = 0x02, // interested in op data changes (usual)
211  OP_INTEREST_FLAG = 0x04, // interested in flag changes (e.g.display flg)
212 
213  // OP_INTEREST_NAME should NOT be used with addExtraInput().
214  // It should only be used with addOpReference() or addOpNameReference().
215  OP_INTEREST_NAME = 0x08, // interested in OP name changes
216 
217  OP_INTEREST_INPUT = 0x10, // interested when inputs change
218  OP_INTEREST_OUTPUT = 0x20, // interested when outputs change
219  OP_INTEREST_INPUTREF= 0x40, // used for resolving input references
220 
221  OP_INTEREST_CHANNEL = 0x80, // used for cached channel reference
222 
223  // OP_INTEREST_NAME should NOT be used with addExtraInput().
224  // It should only be used with addOpReference() or addOpNameReference().
225  // interested in name & data:
230 
231  // The following acts as a sentinal
232  OP_INTEREST_ALL = 0xFFFFFFFF // Use this to match all interests
233 };
234 
235 /// An enumeration that indicates to the user, what aspect of a OP_Node's UI
236 /// representation changed, that caused the OP_UI_CHANGED event for that node
237 /// to be sent.
239 {
240  /// The change type wasn't set, so it could be any of them.
242  /// Errors/warnings got set/cleared.
244  /// The pick/selection state changed
246  /// The node's color changed
248  /// The node's delete script changed
250  /// The node's comment changed
252  /// The node's lock flag
254  /// The node's compress (thumbnail) flag changed
256  /// The node's OTL definition match state changed
258  /// The active input changed
260  /// The input/output connections have changed
262  /// The expression language changed
264 
265  /// A network box owned by this network changed
267  /// A post-it owned by this network changed
269  /// A dot owned by this network changed
271 
272  /// Preview has changed
274 
276 
278  /// \sa COP2_UIChangeType
280  /// \sa VOP_UIChangeType
282 };
283 
284 // When loading data into an existing network, this enum defines the possible
285 // actions to take when loading items with names that are already in use.
287 {
288  // Always create a new item with a new name. Existing item is unaffected.
290  // Delete the existing item, and create a new one with the same name.
292  // Keep the existing item, and just load the data into this item.
294 };
295 
296 #endif
The change type wasn't set, so it could be any of them.
Definition: OP_DataTypes.h:241
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
The node's OTL definition match state changed.
Definition: OP_DataTypes.h:257
Preview has changed.
Definition: OP_DataTypes.h:273
#define SYS_DEPRECATED(__V__)
The input/output connections have changed.
Definition: OP_DataTypes.h:261
constexpr size_t SYShash(const SYS_Flicks f)
Definition: SYS_Flicks.h:46
A post-it owned by this network changed.
Definition: OP_DataTypes.h:268
const GLdouble * v
Definition: glcorearb.h:837
int OP_InputIdx
Definition: OP_DataTypes.h:184
UT_Array< OP_Node * > OP_NodeList
Definition: OP_DataTypes.h:42
int64 exint
Definition: SYS_Types.h:125
The node's delete script changed.
Definition: OP_DataTypes.h:249
A dot owned by this network changed.
Definition: OP_DataTypes.h:270
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_IntrusivePtr< OP_DataBlock > OP_DataBlockPtr
Definition: OP_DataTypes.h:43
The pick/selection state changed.
Definition: OP_DataTypes.h:245
OutGridT const XformOp bool bool
The expression language changed.
Definition: OP_DataTypes.h:263
A network box owned by this network changed.
Definition: OP_DataTypes.h:266
OP_InterestType
Definition: OP_DataTypes.h:206
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4512
The node's lock flag.
Definition: OP_DataTypes.h:253
Wrapper around hboost::intrusive_ptr.
UT_ValArray< OP_NetworkBoxItem * > OP_NetworkBoxItemList
Definition: OP_DataTypes.h:39
OP_UIChangeType
Definition: OP_DataTypes.h:238
The node's compress (thumbnail) flag changed.
Definition: OP_DataTypes.h:255
The node's color changed.
Definition: OP_DataTypes.h:247
OP_OverwriteAction
Definition: OP_DataTypes.h:286
LeafData & operator=(const LeafData &)=delete
Type-safe formatting, modeled on the Python str.format function.
OP_DataType
Definition: OP_DataTypes.h:189
int OP_OutputIdx
Definition: OP_DataTypes.h:185
Errors/warnings got set/cleared.
Definition: OP_DataTypes.h:243
The active input changed.
Definition: OP_DataTypes.h:259
size_t hash_value(const CH_ChannelRef &ref)
The node's comment changed.
Definition: OP_DataTypes.h:251