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