HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
APEX_Include.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: APEX_Include.h (APEX Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __APEX_INCLUDE_H__
12 #define __APEX_INCLUDE_H__
13 
14 #include "APEX_API.h"
15 #include "APEX_Names.h"
16 #include "APEX_COW.h"
17 
18 #include <UN/UN_Include.h>
19 
20 #include <UT/UT_Array.h>
21 #include <UT/UT_ArrayMap.h>
22 #include <UT/UT_Assert.h>
23 #include <UT/UT_Debug.h>
24 #include <UT/UT_Format.h>
25 #include <UT/UT_Map.h>
26 #include <UT/UT_Matrix3.h> // IWYU pragma: export
27 #include <UT/UT_Matrix4.h> // IWYU pragma: export
28 #include <UT/UT_Options.h>
29 #include <UT/UT_Ramp.h> // IWYU pragma: export
30 #include <UT/UT_Set.h>
31 #include <UT/UT_SharedPtr.h>
32 #include <UT/UT_StringArray.h>
33 #include <UT/UT_StringHolder.h>
34 #include <UT/UT_Tracing.h>
35 #include <UT/UT_Tuple.h>
36 #include <UT/UT_Vector2.h> // IWYU pragma: export
37 #include <UT/UT_Vector3.h> // IWYU pragma: export
38 #include <UT/UT_Vector4.h> // IWYU pragma: export
39 #include <SYS/SYS_Types.h>
40 
41 #include <algorithm>
42 #include <any>
43 #include <functional>
44 #include <string>
45 #include <tuple>
46 #include <type_traits>
47 #include <typeinfo>
48 #include <utility>
49 #include <vector>
50 
51 #include <stddef.h>
52 
53 // Forward declarations from <PRM/PRM_Parm.h>
54 class PRM_DataItem;
56 
57 namespace apex
58 {
59 
60 using Bool = bool;
61 using Int = exint;
62 using Float = double;
70 class FloatRamp : public UT_Ramp
71 {
72 public:
74  {
75  this->addNode(0, UT_FRGBA(0.0, 0.0, 0.0, 0.0));
76  this->addNode(1, UT_FRGBA(1.0, 1.0, 1.0, 1.0));
77  };
78  FloatRamp(const UT_Ramp &ramp) : UT_Ramp{ramp} {}
79 };
80 class ColorRamp : public UT_Ramp
81 {
82 public:
84  {
85  this->addNode(0, UT_FRGBA(0.0, 0.0, 0.0, 0.0));
86  this->addNode(1, UT_FRGBA(1.0, 1.0, 1.0, 1.0));
87  };
88  ColorRamp(const UT_Ramp &ramp) : UT_Ramp{ramp} {}
89 };
90 
91 class APEX_Graph;
93 
106 
107 // Quaternion is not an exposed type. It's only used within callbacks
108 // internally to ensure we consistently use the same base type. Externally,
109 // Vector4 is used in the callback signatures.
111 
113 
114 template <typename T>
116 {
117 public:
119  VariadicArg(std::initializer_list<std::pair<const char *, T *>> inputs)
120  {
121  myNames.setCapacity(inputs.size()); // optional metadata
122  myData.setCapacity(inputs.size());
123  for (auto &[name, p] : inputs)
124  {
125  myNames.emplace_back(name);
126  myData.append(p);
127  }
128  }
129 
130  using value_type = T;
131 
132  void append(const UT_StringHolder &name, T *item)
133  {
134  myNames.emplace_back(name);
135  myData.append(item);
136  }
137 
138  exint size() const
139  {
140  if (myData.size() != myNames.size())
141  {
142  UTdebugPrint(this, myData.size(), myNames.size());
143  }
144  UT_ASSERT(myData.size() == myNames.size());
145  return myData.size();
146  }
147 
148  const UT_Array<UT_StringHolder> &names() const { return myNames; }
149 
151  {
152  return myData[idx];
153  }
154 
155  const T *operator[](exint idx) const
156  {
157  return myData[idx];
158  }
159 
161  {
162  return myNames.find(name);
163  }
164 
165  void toArray(UT_Array<T> &arr) const
166  {
167  arr.setSize(myData.size());
168  for (exint i = 0, n = myData.size(); i < n; ++i)
169  arr[i] = *operator[](i);
170  }
171 
174 
175  iterator begin() { return myData.begin(); }
176  iterator end() { return myData.end(); }
177  const_iterator begin() const { return myData.begin(); }
178  const_iterator end() const { return myData.end(); }
179 
180  /// A minimal array like adaptor which dereferences the VariadicArgs data
181  /// before returning it. This can be useful to write generic code which
182  /// deals either with VariadicArgs or ApexArrays.
183  /// Note: Not compatible with ranged based for loops
184  template<typename IterT>
186  {
187  public:
188  using value_type = T;
189 
190  exint size() const
191  {
192  return std::distance(myBegin, myEnd);
193  }
194 
196  {
197  return *myBegin[index];
198  }
199 
200  const T &operator[](exint index) const
201  {
202  return *myBegin[index];
203  }
204 
205  private:
206  friend class VariadicArg<T>;
207  IndirectRange() = delete;
208  IndirectRange(IterT begin, IterT end) : myBegin{begin}, myEnd{end} {}
209  IterT myBegin, myEnd;
210  };
211 
213  {
214  return IndirectRange<iterator>(begin(), end());
215  }
216 
218  {
220  }
221 
222 private:
224  UT_Array<T *> myData;
225 };
226 
227 } // end namespace apex
228 
230 #define APEX_INVALID_GRAPHDATAID -1
231 
232 // APEX data IDs based on UN concepts:
233 using APEX_NodeID = UN_NodeID;
234 using APEX_SubnetID = UN_SubnetID;
236 using APEX_PortID = UN_PortID;
237 using APEX_WireID = UN_WireID;
238 using APEX_StickyNoteID = UN_StickyNoteID;
239 
241 
244 
245 // An index into a data container, referring to a data object.
246 // Indices may be reused for new data objects, if old ones were deleted.
247 #define APEX_INDEX(Class) UN_DATA_INDEX(Class)
248 
249 // A clearer for UT::ArraySet. Must be used within the UT namespace.
250 #define APEX_INDEX_CLEARER(IndexType) UN_INDEX_CLEARER(IndexType)
251 
252 // For debug printouts
253 #define APEX_NUMBER_FORMATTER(IdOrIndexType) UN_NUMBER_FORMATTER(IdOrIndexType)
254 
255 // Apex Scope ID
256 // It is currently defined as a data index, because APEX (subnets) use it solely
257 // as a direct index into its arrays.
258 APEX_INDEX(APEX_ScopeID)
259 APEX_NUMBER_FORMATTER(APEX_ScopeID)
260 
261 namespace UT
262 {
263 APEX_INDEX_CLEARER(APEX_ScopeID)
264 } // namespace UT
265 
266 #endif
ColorRamp(const UT_Ramp &ramp)
Definition: APEX_Include.h:88
#define UTdebugPrint(...)
Definition: UT_Debug.h:146
int addNode(fpreal pos)
Returns the index of the inserted node.
#define APEX_NUMBER_FORMATTER(IdOrIndexType)
Definition: APEX_Include.h:253
PRM_DataItemHandle DataItem
Definition: APEX_Include.h:112
exint size() const
Definition: APEX_Include.h:138
int64 exint
Definition: SYS_Types.h:125
UN_SubnetID APEX_SubnetID
Definition: APEX_Include.h:234
void setCapacity(exint new_capacity)
iterator begin()
Definition: APEX_Include.h:175
const IndirectRange< const_iterator > indirectRange() const
Definition: APEX_Include.h:217
3D Vector class.
typename UT_Array< T * >::iterator iterator
Definition: APEX_Include.h:172
4D Vector class.
Definition: UT_Vector4.h:176
2D Vector class.
Definition: UT_Vector2.h:162
exint find(const S &s, exint start=0) const
UN_WireID APEX_WireID
Definition: APEX_Include.h:237
const T & operator[](exint index) const
Definition: APEX_Include.h:200
exint size() const
Definition: UT_Array.h:667
void setSize(exint newsize)
Definition: UT_Array.h:690
OutGridT const XformOp bool bool
void toArray(UT_Array< T > &arr) const
Definition: APEX_Include.h:165
UT_SharedPtr< const PRM_DataItem > PRM_DataItemHandle
Definition: APEX_Include.h:55
UNI_PortKind UN_PortKind
Differentiates between input and output ports.
Definition: UN_Include.h:619
GLdouble n
Definition: glcorearb.h:2008
void append(const UT_StringHolder &name, T *item)
Definition: APEX_Include.h:132
IndirectRange< iterator > indirectRange()
Definition: APEX_Include.h:212
exint emplace_back(S &&...s)
Definition: UT_ArrayImpl.h:781
int64 APEX_GraphDataID
Definition: APEX_Include.h:229
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
double Float
Definition: APEX_Include.h:62
typename UT_Array< T * >::const_iterator const_iterator
Definition: APEX_Include.h:173
GLuint GLuint end
Definition: glcorearb.h:475
VariadicArg(std::initializer_list< std::pair< const char *, T * >> inputs)
Definition: APEX_Include.h:119
UNI_PortKind
Specifies the port kind, ie, wheter it is an input or an output port.
Definition: UNI_Include.h:21
UN_PortID APEX_PortID
Definition: APEX_Include.h:236
iterator begin()
Definition: UT_Array.h:1039
long long int64
Definition: SYS_Types.h:116
UN_StickyNoteID APEX_StickyNoteID
Definition: APEX_Include.h:238
GLuint const GLchar * name
Definition: glcorearb.h:786
exint append()
Definition: UT_Array.h:142
Quaternion class.
Definition: GEO_Detail.h:49
exint Int
Definition: APEX_Include.h:61
const UT_Array< UT_StringHolder > & names() const
Definition: APEX_Include.h:148
const_iterator end() const
Definition: APEX_Include.h:178
UT_RGBAT< fpreal32 > UT_FRGBA
Definition: UT_Pixel.h:113
Utility class for containing a color ramp.
Definition: UT_Ramp.h:96
GLuint index
Definition: glcorearb.h:786
bool Bool
Definition: APEX_Include.h:60
Type-safe formatting, modeled on the Python str.format function.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
T * operator[](exint idx)
Definition: APEX_Include.h:150
#define APEX_INDEX(Class)
Definition: APEX_Include.h:247
SIM_API const UT_StringHolder distance
exint nameToIndex(const UT_StringRef &name) const
Definition: APEX_Include.h:160
UN_NodeID APEX_NodeID
Definition: APEX_Include.h:233
const_iterator begin() const
Definition: APEX_Include.h:177
const T * operator[](exint idx) const
Definition: APEX_Include.h:155
iterator end()
End iterator.
Definition: UT_Array.h:1044
FloatRamp(const UT_Ramp &ramp)
Definition: APEX_Include.h:78
APEX_SubnetID APEX_GraphID
Definition: APEX_Include.h:235
#define APEX_INDEX_CLEARER(IndexType)
Definition: APEX_Include.h:250