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  {
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  /// Create instance of a procedural
163  virtual GU_PackedImpl *create() const = 0;
164 
165  /// Load shared data for the specific implementation. Shared data must be
166  /// saved in an array containing: @code
167  /// [ "string type", "string key", object ]
168  /// @endcode
169  /// The @c type is used to differentiate between different types of shared
170  /// primitive data, while the @c key is used to uniquely identify blocks of
171  /// shared data.
172  ///
173  /// When loading a geometry file, the type and key will be loaded and
174  /// passed to this method to resolve the shared data. The code should look
175  /// something like: @code
176  /// if (!strcmp(type, "typename1"))
177  /// {
178  /// Typename1Container data;
179  /// if (!Typename1Container::load(p, data.myObject))
180  /// return false;
181  /// loadmap.resolveSharedData(key, data);
182  /// }
183  /// @endcode
184  /// This assumes that Typename1Container is a sub-class of
185  /// GA_SharedLoadData and where Typename1Container::myObject is the object
186  /// which is shared between multiple primitives.
187  ///
188  /// Note that the base class should be called if the type can't be handled
189  /// by the subclass.
190  virtual GA_SharedLoadData* loadSharedData(UT_JSONParser &p,
191  const char *type,
192  const char *key,
193  bool isDelayedLoad) const;
194 
195  virtual GA_SharedLoadDataStat* statSharedData(UT_JSONParser& parser) const;
196 
197  /// Query how many intrinsic attributes are supported by this primitive type
198  /// Default: return 0
199  int getIntrinsicCount() const
200  { return myIntrinsics.entries(); }
201  /// Get information about the definition of the Nth intrinsic
202  /// Default: assert
204  void getIntrinsicDefinition(int idx,
205  UT_String &name,
207  bool &read_only) const;
208  void getIntrinsicDefinition(int idx,
209  UT_StringHolder &name,
210  GA_StorageClass &storage,
211  bool &read_only) const;
212  /// Get the intrinsic tuple size (which might be varying)
213  /// Default: return 0
214  GA_Size getIntrinsicTupleSize(const GU_PrimPacked *proc,
215  int idx) const;
216  /// @{
217  /// Get/Set intrinsic attribute values for a primitive
218  /// Default: return 0
219  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
220  int idx, fpreal64 *val, GA_Size vsize) const;
221  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
222  int idx, int64 *val, GA_Size vsize) const;
223  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
224  int idx, UT_String &str) const;
225  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
226  int idx, UT_StringHolder &str) const;
227  GA_Size getIntrinsicValue(const GU_PrimPacked *proc,
228  int idx, UT_StringArray &strings) const;
229  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
230  int idx, const fpreal64 *val, GA_Size vsize) const;
231  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
232  int idx, const int64 *val, GA_Size vsize) const;
233  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
234  int idx, const UT_StringArray &values) const;
235  GA_Size setIntrinsicValue(GU_PrimPacked *proc,
236  int idx, const char **values, GA_Size size) const;
237  /// @}
238 
239  /// Register a scalar floating point intrinsic
240  void registerIntrinsic(const UT_StringHolder &name,
241  GU_PackedImpl::FloatGetter getter,
242  GU_PackedImpl::FloatSetter setter=NULL);
243  /// Register a scalar integer intrinsic
244  void registerIntrinsic(const UT_StringHolder &name,
245  GU_PackedImpl::IntGetter getter,
246  GU_PackedImpl::IntSetter setter=NULL);
247  /// Register a scalar boolean intrinsic
248  void registerIntrinsic(const UT_StringHolder &name,
249  GU_PackedImpl::BoolGetter getter,
250  GU_PackedImpl::BoolSetter setter=NULL);
251  /// Register a scalar string (const UT_StringHolder &) intrinsic
252  void registerIntrinsic(const UT_StringHolder &name,
253  GU_PackedImpl::StringGetter getter,
254  GU_PackedImpl::StringSetter setter=NULL);
255  /// Register a scalar string (const std::string &) intrinsic
256  void registerIntrinsic(const UT_StringHolder &name,
257  GU_PackedImpl::StdStringGetter getter,
258  GU_PackedImpl::StdStringSetter setter=NULL);
259  /// Register a scalar string (const UT_StringHolder &) intrinsic
260  void registerIntrinsic(const UT_StringHolder &name,
261  GU_PackedImpl::StringHolderGetter getter,
262  GU_PackedImpl::StringHolderSetter setter=NULL);
263 
264  /// Register an intrinsic for a floating point array
265  void registerTupleIntrinsic(const UT_StringHolder &name,
266  GU_PackedImpl::IntGetter get_tuple_size,
267  GU_PackedImpl::FloatTupleGetter getter,
268  GU_PackedImpl::FloatTupleSetter setter=NULL,
269  GU_PackedImpl::IntSetter set_tuple_size=NULL);
270  /// Register an intrinsic for an integer array
271  void registerTupleIntrinsic(const UT_StringHolder &name,
272  GU_PackedImpl::IntGetter get_tuple_size,
273  GU_PackedImpl::IntTupleGetter getter,
274  GU_PackedImpl::IntTupleSetter setter=NULL,
275  GU_PackedImpl::IntSetter set_tuple_size=NULL);
276  /// Register an intrinsic for a boolean array
277  void registerTupleIntrinsic(const UT_StringHolder &name,
278  GU_PackedImpl::IntGetter get_tuple_size,
279  GU_PackedImpl::BoolTupleGetter getter,
280  GU_PackedImpl::BoolTupleSetter setter=NULL,
281  GU_PackedImpl::IntSetter set_tuple_size=NULL);
282  /// Register an intrinsic for a string (const char *) array
283  void registerTupleIntrinsic(const UT_StringHolder &name,
284  GU_PackedImpl::IntGetter get_tuple_size,
285  GU_PackedImpl::StringTupleGetter getter,
286  GU_PackedImpl::StringTupleSetter setter=NULL,
287  GU_PackedImpl::IntSetter set_tuple_size=NULL);
288  /// Register an intrinsic for a string (const std::string &) array
289  void registerTupleIntrinsic(const UT_StringHolder &name,
290  GU_PackedImpl::IntGetter get_tuple_size,
291  GU_PackedImpl::StdStringTupleGetter getter,
292  GU_PackedImpl::StdStringTupleSetter setter=NULL,
293  GU_PackedImpl::IntSetter set_tuple_size=NULL);
294  /// Register an intrinsic for a string (const StringHolder &) array
295  void registerTupleIntrinsic(const UT_StringHolder &name,
296  GU_PackedImpl::IntGetter get_tuple_size,
297  GU_PackedImpl::StringHolderTupleGetter getter,
298  GU_PackedImpl::StringHolderTupleSetter setter=NULL,
299  GU_PackedImpl::IntSetter set_tuple_size=NULL);
300 
301  /// Register an intrinsic for a floating point array
302  void registerTupleIntrinsic(const UT_StringHolder &name,
303  GU_PackedImpl::IntGetter get_tuple_size,
304  GU_PackedImpl::F32VectorGetter getter,
305  GU_PackedImpl::F32VectorSetter setter=NULL,
306  GU_PackedImpl::IntSetter set_tuple_size=NULL);
307  /// Register an intrinsic for a floating point array
308  void registerTupleIntrinsic(const UT_StringHolder &name,
309  GU_PackedImpl::IntGetter get_tuple_size,
310  GU_PackedImpl::F64VectorGetter getter,
311  GU_PackedImpl::F64VectorSetter setter=NULL,
312  GU_PackedImpl::IntSetter set_tuple_size=NULL);
313  /// Register an intrinsic for an integer array
314  void registerTupleIntrinsic(const UT_StringHolder &name,
315  GU_PackedImpl::IntGetter get_tuple_size,
316  GU_PackedImpl::I32VectorGetter getter,
317  GU_PackedImpl::I32VectorSetter setter=NULL,
318  GU_PackedImpl::IntSetter set_tuple_size=NULL);
319  /// Register an intrinsic for an integer array
320  void registerTupleIntrinsic(const UT_StringHolder &name,
321  GU_PackedImpl::IntGetter get_tuple_size,
322  GU_PackedImpl::I64VectorGetter getter,
323  GU_PackedImpl::I64VectorSetter setter=NULL,
324  GU_PackedImpl::IntSetter set_tuple_size=NULL);
325  /// Register an intrinsic for a boolean array
326  void registerTupleIntrinsic(const UT_StringHolder &name,
327  GU_PackedImpl::IntGetter get_tuple_size,
328  GU_PackedImpl::BVectorGetter getter,
329  GU_PackedImpl::BVectorSetter setter=NULL,
330  GU_PackedImpl::IntSetter set_tuple_size=NULL);
331  /// Register a string array intrinsic.
332  void registerTupleIntrinsic(const UT_StringHolder &name,
333  GU_PackedImpl::IntGetter get_tuple_size,
334  GU_PackedImpl::StringArrayGetter getter,
335  GU_PackedImpl::StringArraySetter setter = nullptr,
336  GU_PackedImpl::IntSetter set_tuple_size = nullptr);
337 
338  /// Clear any cached geometry. The method should return the number of
339  /// items cleared, and the default method just returns 0.
340  virtual exint clearCachedGeometry();
341 
342 private:
343  UT_StringHolder myName;
344  UT_StringHolder myLabel;
345  UT_StringHolder myIcon;
346  const GA_PrimitiveDefinition *myTypeDef;
347  UT_Array<IntrinsicDef *> myIntrinsics;
348  GA_IntrinsicDef myGAIntrinsics;
349 
350  friend class GU_PrimPacked; // To set the type definition.
351 };
352 
353 #endif
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
GA_StorageClass
Definition: GA_Types.h:68
#define DECL_SET_CAST(TYPE, METHOD, METHODCAST)
const UT_StringHolder & icon() const
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
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:211
GLsizeiptr size
Definition: glcorearb.h:663
#define DECL_VSET_CAST(TYPE, METHOD, METHODCAST)
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
long long int64
Definition: SYS_Types.h:107
#define DECL_TGET_CAST(TYPE, METHOD, METHODCAST)
int64 exint
Definition: SYS_Types.h:116
double fpreal64
Definition: SYS_Types.h:192
int method
Definition: png.h:1924
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
#define GU_API
Definition: GU_API.h:12
GLuint const GLchar * name
Definition: glcorearb.h:785
int int32
Definition: SYS_Types.h:35
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1932
void(GU_PackedImpl::* StringArrayGetter)(const GU_PrimPacked *, UT_StringArray &) const
double fpreal
Definition: SYS_Types.h:270
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
GLuint GLfloat * val
Definition: glcorearb.h:1607
GU_PackedFactoryPrivate::IntrinsicDef IntrinsicDef
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
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:191
const GA_PrimitiveDefinition & typeDef() const
#define DECL_GET_CAST(TYPE, METHOD, METHODCAST)
const UT_StringHolder & name() const