HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PackedFactory.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: GU_PackedFactory.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_PackedFactory__
12 #define __GU_PackedFactory__
13 
14 #include "GU_API.h"
15 #include <UT/UT_String.h>
16 #include <UT/UT_StringHolder.h>
18 #include <GA/GA_IntrinsicDef.h>
19 #include "GU_PackedImpl.h"
20 
21 namespace GU_PackedFactoryPrivate
22 {
23  class IntrinsicDef;
24 }
25 
27 {
28 public:
29  /// @{
30  /// Typedefs
32  typedef GU_PackedFactoryPrivate::IntrinsicDef IntrinsicDef;
33  /// @}
34 
35  /// <b> Intrinsics in Packed Primitives </b>
36  ///
37  /// Convenience methods for casting a subclass of GU_PackedImpl accessor
38  /// methods to the methods used by registerIntrinsic or
39  /// registerTupleIntrinsic. for example, the factory constructor might
40  /// look like: @code
41  /// class MyImpl : public GU_PackedImpl {
42  /// const std::string &filename() const { return myFilename; }
43  /// void setFilename(const std::string &f) { myFilename = f; }
44  /// fpreal frame() const { return myFrame; }
45  /// void setFrame(fpreal f) { myFrame = f; }
46  /// bool isAnimated() const { return myAnimated; }
47  /// };
48  /// class MyFactory : public GU_PackedFactory {
49  /// MyFactory()
50  /// {
51  /// registerIntrinsic("filename"_sh,
52  /// StdStringGetterCast(&MyImpl::filename),
53  /// StdStringSetterCast(&MyImpl::setFilename));
54  /// registerIntrinsic("frame"_sh,
55  /// FloatGetterCast(&MyImpl::frame),
56  /// FloatSetterCast(&MyImpl::setFrame));
57  /// registerIntrinsic("animated"_sh,
58  /// BoolGetterCast(&MyImpl::isAnimated));
59  /// }
60  /// };
61  /// @endcode
62 
63 #define DECL_GET_CAST(TYPE, METHOD, METHODCAST) \
64  template <typename CLASS> inline GU_PackedImpl::METHOD \
65  METHODCAST(TYPE (CLASS::*method)(const GU_PrimPacked *)const) \
66  { return (GU_PackedImpl::METHOD)(method); }
67 #define DECL_SET_CAST(TYPE, METHOD, METHODCAST) \
68  template <typename CLASS> inline GU_PackedImpl::METHOD \
69  METHODCAST(void (CLASS::*method)(GU_PrimPacked *, TYPE)) \
70  { return (GU_PackedImpl::METHOD)(method); }
71 
72 #define DECL_TGET_CAST(TYPE, METHOD, METHODCAST) \
73  template <typename CLASS> inline GU_PackedImpl::METHOD \
74  METHODCAST(TYPE (CLASS::*method)(const GU_PrimPacked *,exint)const) \
75  { return (GU_PackedImpl::METHOD)(method); }
76 #define DECL_TSET_CAST(TYPE, METHOD, METHODCAST) \
77  template <typename CLASS> inline GU_PackedImpl::METHOD \
78  METHODCAST(void (CLASS::*method)(GU_PrimPacked *, exint, TYPE)) \
79  { return (GU_PackedImpl::METHOD)(method); }
80 
81 #define DECL_VGET_CAST(TYPE, METHOD, METHODCAST) \
82  template <typename CLASS> inline GU_PackedImpl::METHOD \
83  METHODCAST(void (CLASS::*method)(const GU_PrimPacked *, TYPE *, exint) const) \
84  { return (GU_PackedImpl::METHOD)(method); }
85 #define DECL_VSET_CAST(TYPE, METHOD, METHODCAST) \
86  template <typename CLASS> inline GU_PackedImpl::METHOD \
87  METHODCAST(void (CLASS::*method)(GU_PrimPacked *, const TYPE *, exint)) \
88  { return (GU_PackedImpl::METHOD)(method); }
89 
90 
91  DECL_GET_CAST(fpreal, FloatGetter, FloatGetterCast)
92  DECL_SET_CAST(fpreal, FloatSetter, FloatSetterCast)
93  DECL_GET_CAST(exint, IntGetter, IntGetterCast)
94  DECL_SET_CAST(exint, IntSetter, IntSetterCast)
95  DECL_GET_CAST(bool, BoolGetter, BoolGetterCast)
96  DECL_SET_CAST(bool, BoolSetter, BoolSetterCast)
97  DECL_GET_CAST(const char *, StringGetter, StringGetterCast)
98  DECL_SET_CAST(const char *, StringSetter, StringSetterCast)
99  DECL_GET_CAST(std::string, StdStringGetter, StdStringGetterCast)
100  DECL_SET_CAST(const std::string &, StdStringSetter, StdStringSetterCast)
101  DECL_GET_CAST(UT_StringHolder, StringHolderGetter, StringHolderGetterCast)
102  DECL_SET_CAST(const UT_StringHolder &, StringHolderSetter, StringHolderSetterCast)
103 
104  DECL_TGET_CAST(fpreal, FloatTupleGetter, FloatTupleGetterCast)
105  DECL_TSET_CAST(fpreal, FloatTupleSetter, FloatTupleSetterCast)
106  DECL_TGET_CAST(exint, IntTupleGetter, IntTupleGetterCast)
107  DECL_TSET_CAST(exint, IntTupleSetter, IntTupleSetterCast)
108  DECL_TGET_CAST(bool, BoolTupleGetter, BoolTupleGetterCast)
109  DECL_TSET_CAST(bool, BoolTupleSetter, BoolTupleSetterCast)
110  DECL_TGET_CAST(const char *, StringTupleGetter, StringTupleGetterCast)
111  DECL_TSET_CAST(const char *, StringTupleSetter, StringTupleSetterCast)
112  DECL_TGET_CAST(const std::string &, StdStringTupleGetter, StdStringTupleGetterCast)
113  DECL_TSET_CAST(const std::string &, StdStringTupleSetter, StdStringTupleSetterCast)
114  DECL_TGET_CAST(const UT_StringHolder &, StringHolderTupleGetter, StringHolderTupleGetterCast)
115  DECL_TSET_CAST(const UT_StringHolder &, StringHolderTupleSetter, StringHolderTupleSetterCast)
116 
117  DECL_VGET_CAST(fpreal32, F32VectorGetter, F32VectorGetterCast)
118  DECL_VSET_CAST(fpreal32, F32VectorSetter, F32VectorSetterCast)
119  DECL_VGET_CAST(fpreal64, F64VectorGetter, F64VectorGetterCast)
120  DECL_VSET_CAST(fpreal64, F64VectorSetter, F64VectorSetterCast)
121  DECL_VGET_CAST(int32, I32VectorGetter, I32VectorGetterCast)
122  DECL_VSET_CAST(int32, I32VectorSetter, I32VectorSetterCast)
123  DECL_VGET_CAST(int64, I64VectorGetter, I64VectorGetterCast)
124  DECL_VSET_CAST(int64, I64VectorSetter, I64VectorSetterCast)
125  DECL_VGET_CAST(bool, BVectorGetter, BVectorGetterCast)
126  DECL_VSET_CAST(bool, BVectorSetter, BVectorSetterCast)
127 
128  template <typename CLASS>
129  inline GU_PackedImpl::StringArrayGetter
130  StringArrayGetterCast(void (CLASS::*method)(const GU_PrimPacked *,UT_StringArray &) const)
131  {
132  return (GU_PackedImpl::StringArrayGetter)(method);
133  }
134 
135  DECL_SET_CAST(const UT_StringArray &, StringArraySetter,
136  StringArraySetterCast)
137 
138 #undef DECL_GET_METHOD_CAST
139 #undef DECL_SET_METHOD_CAST
140 #undef DECL_TGET_METHOD_CAST
141 #undef DECL_TSET_METHOD_CAST
142 #undef DECL_VGET_METHOD_CAST
143 #undef DECL_VSET_METHOD_CAST
144 
145  /// Factory constructor
149  /// Factory destructor
150  virtual ~GU_PackedFactory();
151 
152  bool isRegistered() const { return myTypeDef != 0; }
153 
154  /// @{
155  /// Member data accessors
156  const UT_StringHolder &name() const { return myName; }
157  const UT_StringHolder &label() const { return myLabel; }
158  const UT_StringHolder &icon() const { return myIcon; }
159  const GA_PrimitiveDefinition &typeDef() const { return *myTypeDef; }
160  /// @}
161 
162  /// Return an intrusive pointer to a default-constructed packed primitive
163  /// implementation of the correct type. Use this instead of create(), to avoid
164  /// redundantly allocating a new GU_PackedImpl that may just be replaced.
165  virtual const UT_IntrusivePtr<GU_PackedImpl> &defaultImpl() const = 0;
166 
167  /// Create new instance of a packed primitive implementation.
168  virtual GU_PackedImpl *create() const = 0;
169 
170  /// Load shared data for the specific implementation. Shared data must be
171  /// saved in an array containing: @code
172  /// [ "string type", "string key", object ]
173  /// @endcode
174  /// The @c type is used to differentiate between different types of shared
175  /// primitive data, while the @c key is used to uniquely identify blocks of
176  /// shared data.
177  ///
178  /// When loading a geometry file, the type and key will be loaded and
179  /// passed to this method to resolve the shared data. The code should look
180  /// something like: @code
181  /// if (!strcmp(type, "typename1"))
182  /// {
183  /// Typename1Container data;
184  /// if (!Typename1Container::load(p, data.myObject))
185  /// return false;
186  /// loadmap.resolveSharedData(key, data);
187  /// }
188  /// @endcode
189  /// This assumes that Typename1Container is a sub-class of
190  /// GA_SharedLoadData and where Typename1Container::myObject is the object
191  /// which is shared between multiple primitives.
192  ///
193  /// Note that the base class should be called if the type can't be handled
194  /// by the subclass.
195  virtual GA_SharedLoadData* loadSharedData(UT_JSONParser &p,
196  const char *type,
197  const char *key,
198  bool isDelayedLoad) const;
199 
200  virtual GA_SharedLoadDataStat* statSharedData(UT_JSONParser& parser) const;
201 
202  /// Query how many intrinsic attributes are supported by this primitive type
203  /// Default: return 0
204  int getIntrinsicCount() const
205  { return myIntrinsics.entries(); }
206  /// Get information about the definition of the Nth intrinsic
207  /// Default: assert
209  void getIntrinsicDefinition(int idx,
210  UT_String &name,
212  bool &read_only) const;
213  void getIntrinsicDefinition(int idx,
214  UT_StringHolder &name,
215  GA_StorageClass &storage,
216  bool &read_only) const;
217  /// Get the intrinsic tuple size (which might be varying)
218  /// Default: return 0
219  GA_Size getIntrinsicTupleSize(const GU_PrimPacked *proc,
220  int idx) const;
221  /// @{
222  /// Get/Set intrinsic attribute values for a primitive
223  /// Default: return 0
224  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
225  int idx, fpreal64 *val, GA_Size vsize) const;
226  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
227  int idx, int64 *val, GA_Size vsize) const;
228  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
229  int idx, UT_String &str) const;
230  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
231  int idx, UT_StringHolder &str) const;
232  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
233  int idx, UT_StringArray &strings) const;
234  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
235  int idx, const fpreal64 *val, GA_Size vsize) const;
236  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
237  int idx, const int64 *val, GA_Size vsize) const;
238  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
239  int idx, const UT_StringArray &values) const;
240  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
241  int idx, const char **values, GA_Size size) const;
242  /// @}
243 
244  /// Register a scalar floating point intrinsic
245  void registerIntrinsic(const UT_StringHolder &name,
246  GU_PackedImpl::FloatGetter getter,
247  GU_PackedImpl::FloatSetter setter=NULL);
248  /// Register a scalar integer intrinsic
249  void registerIntrinsic(const UT_StringHolder &name,
250  GU_PackedImpl::IntGetter getter,
251  GU_PackedImpl::IntSetter setter=NULL);
252  /// Register a scalar boolean intrinsic
253  void registerIntrinsic(const UT_StringHolder &name,
254  GU_PackedImpl::BoolGetter getter,
255  GU_PackedImpl::BoolSetter setter=NULL);
256  /// Register a scalar string (const UT_StringHolder &) intrinsic
257  void registerIntrinsic(const UT_StringHolder &name,
258  GU_PackedImpl::StringGetter getter,
259  GU_PackedImpl::StringSetter setter=NULL);
260  /// Register a scalar string (const std::string &) intrinsic
261  void registerIntrinsic(const UT_StringHolder &name,
262  GU_PackedImpl::StdStringGetter getter,
263  GU_PackedImpl::StdStringSetter setter=NULL);
264  /// Register a scalar string (const UT_StringHolder &) intrinsic
265  void registerIntrinsic(const UT_StringHolder &name,
266  GU_PackedImpl::StringHolderGetter getter,
267  GU_PackedImpl::StringHolderSetter setter=NULL);
268 
269  /// Register an intrinsic for a floating point array
270  void registerTupleIntrinsic(const UT_StringHolder &name,
271  GU_PackedImpl::IntGetter get_tuple_size,
272  GU_PackedImpl::FloatTupleGetter getter,
273  GU_PackedImpl::FloatTupleSetter setter=NULL,
274  GU_PackedImpl::IntSetter set_tuple_size=NULL);
275  /// Register an intrinsic for an integer array
276  void registerTupleIntrinsic(const UT_StringHolder &name,
277  GU_PackedImpl::IntGetter get_tuple_size,
278  GU_PackedImpl::IntTupleGetter getter,
279  GU_PackedImpl::IntTupleSetter setter=NULL,
280  GU_PackedImpl::IntSetter set_tuple_size=NULL);
281  /// Register an intrinsic for a boolean array
282  void registerTupleIntrinsic(const UT_StringHolder &name,
283  GU_PackedImpl::IntGetter get_tuple_size,
284  GU_PackedImpl::BoolTupleGetter getter,
285  GU_PackedImpl::BoolTupleSetter setter=NULL,
286  GU_PackedImpl::IntSetter set_tuple_size=NULL);
287  /// Register an intrinsic for a string (const char *) array
288  void registerTupleIntrinsic(const UT_StringHolder &name,
289  GU_PackedImpl::IntGetter get_tuple_size,
290  GU_PackedImpl::StringTupleGetter getter,
291  GU_PackedImpl::StringTupleSetter setter=NULL,
292  GU_PackedImpl::IntSetter set_tuple_size=NULL);
293  /// Register an intrinsic for a string (const std::string &) array
294  void registerTupleIntrinsic(const UT_StringHolder &name,
295  GU_PackedImpl::IntGetter get_tuple_size,
296  GU_PackedImpl::StdStringTupleGetter getter,
297  GU_PackedImpl::StdStringTupleSetter setter=NULL,
298  GU_PackedImpl::IntSetter set_tuple_size=NULL);
299  /// Register an intrinsic for a string (const StringHolder &) array
300  void registerTupleIntrinsic(const UT_StringHolder &name,
301  GU_PackedImpl::IntGetter get_tuple_size,
302  GU_PackedImpl::StringHolderTupleGetter getter,
303  GU_PackedImpl::StringHolderTupleSetter setter=NULL,
304  GU_PackedImpl::IntSetter set_tuple_size=NULL);
305 
306  /// Register an intrinsic for a floating point array
307  void registerTupleIntrinsic(const UT_StringHolder &name,
308  GU_PackedImpl::IntGetter get_tuple_size,
309  GU_PackedImpl::F32VectorGetter getter,
310  GU_PackedImpl::F32VectorSetter setter=NULL,
311  GU_PackedImpl::IntSetter set_tuple_size=NULL);
312  /// Register an intrinsic for a floating point array
313  void registerTupleIntrinsic(const UT_StringHolder &name,
314  GU_PackedImpl::IntGetter get_tuple_size,
315  GU_PackedImpl::F64VectorGetter getter,
316  GU_PackedImpl::F64VectorSetter setter=NULL,
317  GU_PackedImpl::IntSetter set_tuple_size=NULL);
318  /// Register an intrinsic for an integer array
319  void registerTupleIntrinsic(const UT_StringHolder &name,
320  GU_PackedImpl::IntGetter get_tuple_size,
321  GU_PackedImpl::I32VectorGetter getter,
322  GU_PackedImpl::I32VectorSetter setter=NULL,
323  GU_PackedImpl::IntSetter set_tuple_size=NULL);
324  /// Register an intrinsic for an integer array
325  void registerTupleIntrinsic(const UT_StringHolder &name,
326  GU_PackedImpl::IntGetter get_tuple_size,
327  GU_PackedImpl::I64VectorGetter getter,
328  GU_PackedImpl::I64VectorSetter setter=NULL,
329  GU_PackedImpl::IntSetter set_tuple_size=NULL);
330  /// Register an intrinsic for a boolean array
331  void registerTupleIntrinsic(const UT_StringHolder &name,
332  GU_PackedImpl::IntGetter get_tuple_size,
333  GU_PackedImpl::BVectorGetter getter,
334  GU_PackedImpl::BVectorSetter setter=NULL,
335  GU_PackedImpl::IntSetter set_tuple_size=NULL);
336  /// Register a string array intrinsic.
337  void registerTupleIntrinsic(const UT_StringHolder &name,
338  GU_PackedImpl::IntGetter get_tuple_size,
339  GU_PackedImpl::StringArrayGetter getter,
340  GU_PackedImpl::StringArraySetter setter = nullptr,
341  GU_PackedImpl::IntSetter set_tuple_size = nullptr);
342 
343  /// Clear any cached geometry. The method should return the number of
344  /// items cleared, and the default method just returns 0.
345  virtual exint clearCachedGeometry();
346 
347 private:
348  UT_StringHolder myName;
349  UT_StringHolder myLabel;
350  UT_StringHolder myIcon;
351  const GA_PrimitiveDefinition *myTypeDef;
352  UT_Array<IntrinsicDef *> myIntrinsics;
353  GA_IntrinsicDef myGAIntrinsics;
354 
355  friend class GU_PrimPacked; // To set the type definition.
356 };
357 
358 #endif
GLsizeiptr size
Definition: glew.h:1681
GLuint const GLchar * name
Definition: glew.h:1814
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
GA_StorageClass
Definition: GA_Types.h:70
#define DECL_SET_CAST(TYPE, METHOD, METHODCAST)
GLuint const GLfloat * val
Definition: glew.h:2794
const UT_StringHolder & icon() const
GLint GLsizei const GLuint64 * values
Definition: glew.h:3612
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
Stores information about intrinsic attributes for classes.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:231
#define DECL_VSET_CAST(TYPE, METHOD, METHODCAST)
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
long long int64
Definition: SYS_Types.h:111
#define DECL_TGET_CAST(TYPE, METHOD, METHODCAST)
int64 exint
Definition: SYS_Types.h:120
double fpreal64
Definition: SYS_Types.h:196
void
Definition: png.h:1083
GLsizei const GLchar *const * strings
Definition: glew.h:5883
#define GU_API
Definition: GU_API.h:14
int int32
Definition: SYS_Types.h:39
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
void(GU_PackedImpl::* StringArrayGetter)(const GU_PrimPacked *, UT_StringArray &) const
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
GLfloat GLfloat p
Definition: glew.h:16321
double fpreal
Definition: SYS_Types.h:276
const UT_StringHolder & label() const
bool isRegistered() const
#define DECL_TSET_CAST(TYPE, METHOD, METHODCAST)
#define DECL_VGET_CAST(TYPE, METHOD, METHODCAST)
int getIntrinsicCount() const
GU_PackedFactoryPrivate::IntrinsicDef IntrinsicDef
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
GA_PrimitiveDefinition::SharedDataLoader SharedDataLoader
Definition of a geometric primitive.
#define const
Definition: zconf.h:214
float fpreal32
Definition: SYS_Types.h:195
const GA_PrimitiveDefinition & typeDef() const
#define DECL_GET_CAST(TYPE, METHOD, METHODCAST)
const UT_StringHolder & name() const