HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_PrimitiveFactory.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: GA_PrimitiveFactory.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  * A GA_PrimitiveFactory manages a collection of GA_PrimitiveDefinition
10  * objects and an associated set of intrinsic attributes.
11  */
12 
13 #ifndef __GA_PrimitiveFactory__
14 #define __GA_PrimitiveFactory__
15 
16 #include "GA_API.h"
17 #include "GA_IOTable.h"
18 #include "GA_IntrinsicManager.h"
19 #include "GA_PrimitiveDefinition.h"
20 #include "GA_PrimitiveFamilyMask.h"
21 #include "GA_PrimitiveTypeMask.h"
22 #include "GA_PrimitiveTypeId.h"
23 #include "GA_PrimitiveTypes.h"
24 #include "GA_Types.h"
25 
26 #include <UT/UT_Array.h>
27 #include <UT/UT_SymbolTable.h>
28 #include <UT/UT_Set.h>
29 #include <UT/UT_FSATable.h>
30 
31 #include <stddef.h>
32 
33 class GA_Detail;
34 class GA_IO;
35 class GA_Primitive;
36 
37 class UT_StringArray;
38 
39 
41 {
42 public:
43  // Define a map where the key is the primitive name and the value is the
44  // DSO file defining the primitive. Primitives not defined by DSOs are not
45  // stored in this map.
47 
49  const UT_FSATable *factory_ids,
50  unsigned non_factory_id_start, int nentries_hint = 0,
51  bool isforprimarydetail = true);
53 
54  /// Register a new primitive definition.
55  /// In the event of a name collision with an existing definition, we return
56  /// NULL.
57  GA_PrimitiveDefinition *registerDefinition(
58  const UT_StringHolder &name,
62  const UT_StringHolder &icon=UT_StringHolder());
63 
64  /// Return the number of possible primitive types in this factory.
65  /// Primitive type id's may not always be contiguous (i.e. there may be
66  /// invalid primitive id's in the range).
67  int getPrimTypeCount() const { return myNextId; }
68 
69  /// Lookup an existing primitive definition, by either token or primitive
70  /// identifier.
71  const GA_PrimitiveDefinition *lookupDefinition(
72  const UT_StringRef &name) const;
73  const GA_PrimitiveDefinition *lookupDefinition(
74  const GA_PrimitiveTypeId &id) const;
75  const GA_PrimitiveDefinition *lookupDefinition(int id) const;
76 
77  /// Given a factory type id, return the corresponding GA_PrimitiveTypeId
79  {
80  if (id >= 0 && id < myList.size() && myList(id))
81  return GA_PrimitiveTypeId(id);
82  return GA_PrimitiveTypeId();
83  }
84 
85  /// Return a list of all primitives defined by DSOs
86  static const ga_DSODefinitions &dsoDefinitions();
87 
88 
89  /// Get a primitive type mask representing all known types registered by
90  /// this primitive factory.
91  GA_PrimitiveTypeMask getTypeMaskAll() const;
92 
93  /// Query the first and last primitive type id in this factory
94  void getDefinitionIdRange(unsigned &first,
95  unsigned &last) const;
96 
97  /// @{
98  /// Fill out the list of intrinsic names for the given primitive type. The
99  /// intrinsic names are added to the set.
100  void addPrimitiveIntrinsicNames(const GA_PrimitiveTypeId &id,
101  UT_Set<std::string> &names) const;
102  /// @}
103 
104  /// Get the names of all detail intrinsics. You can avoid creating a
105  /// detail to do this by calling GUgetFactory().getDetailIntrinsics(names);
107  {
108  myDetailIntrinsics.extractNames(names);
109  }
110 
111  /// Returns true if this factory is for use by GEO_Detail and false
112  /// if this type is for use by GD_Detail.
113  bool isForPrimaryDetail() const { return myForPrimaryDetail; }
114 
115  /// Class to traverse all primitive definitions in the factory
116  class iterator
117  {
118  public:
120  : myFactory(NULL)
121  , myCurr(0)
122  , myEnd(0)
123  {}
125  {
126  *this = src;
127  }
130  {
131  myFactory = src.myFactory;
132  myCurr = src.myCurr;
133  myEnd = src.myEnd;
134  return *this;
135  }
136  bool operator==(const iterator &src) const
137  {
138  if (atEnd() && src.atEnd())
139  return true;
140  return myFactory == src.myFactory &&
141  myCurr == src.myCurr &&
142  myEnd == src.myEnd;
143  }
144  bool operator!=(const iterator &cmp) const
145  { return !(*this == cmp); }
146  bool atEnd() const
147  { return myCurr >= myEnd; }
148  iterator &operator++() { advance(); return *this; }
149  // No post increment as it is harmful.
150  void rewind()
151  {
152  if (myFactory)
153  {
154  myFactory->getDefinitionIdRange(
155  myCurr, myEnd
156  );
157  // Go one beyond last definition
158  myEnd++;
159  }
160  }
161 
162  void advance()
163  {
164  for (myCurr++; myCurr < myEnd; ++myCurr)
165  {
166  // Skip empty entries in the table
167  if (myFactory->lookupDefinition(myCurr))
168  break;
169  }
170  }
172  { return myFactory->lookupDefinition(myCurr); }
173  private:
175  : myFactory(f)
176  {
177  rewind();
178  }
179  const GA_PrimitiveFactory *myFactory;
180  unsigned int myCurr, myEnd;
181  friend class GA_PrimitiveFactory;
182  };
183  iterator begin() const { return iterator(this); }
184 
185  /// @{
186  /// Interface to the IO table -- this may not exist in future versions
187  bool registerIO(GA_IO *io)
188  { return myIOTable.add(io); }
189  const GA_IO *findIO(const char *name)
190  { return myIOTable.find(name); }
192  { myIOTable.getNames(names); }
193  /// @}
194 
195 private:
196  /// Access detail/global intrinsic attributes defined for this factory
197  const GA_IntrinsicManager &getDetailIntrinsics() const
198  { return myDetailIntrinsics; }
199  GA_IntrinsicManager &getDetailIntrinsics()
200  { return myDetailIntrinsics; }
201 
202  const UT_StringArray &getPrimitiveIntrinsics();
203 
206  const UT_FSATable *myFactoryIds;
207  unsigned int myNextId;
208  GA_PrimitiveTypeMask myTypeMask;
209 
210  GA_IntrinsicManager myDetailIntrinsics;
211  UT_StringArray *myPrimitiveIntrinsics;
212 
213  /// Currently, we use the primitive factory as a place to store the IO
214  /// table. It's really a per-detail specialization variable, and this is
215  /// the best place to put it. We rely on the detail friendliness to allow
216  /// access to it.
217  GA_IOTable myIOTable;
218 
219  /// true iff this primitive factory is for use in GEO_Detail,
220  /// and not GD_Detail.
221  const bool myForPrimaryDetail;
222 
223  friend class GA_Detail;
225 };
226 
227 #endif
GLint first
Definition: glcorearb.h:404
void getIONames(UT_StringArray &names)
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
GA_PrimitiveTypeId getFactoryTypeId(int id) const
Given a factory type id, return the corresponding GA_PrimitiveTypeId.
const GA_IO * findIO(const char *name)
GLint GLuint mask
Definition: glcorearb.h:123
Manager to keep track of global handle to name mappings.
#define GA_API
Definition: GA_API.h:12
GA_PrimitiveFamilyMask
UT_StringMap< UT_StringHolder > ga_DSODefinitions
void getDetailIntrinsicNames(UT_StringArray &names) const
GLfloat f
Definition: glcorearb.h:1925
Container class to store GA_IO objects for a detail specialization.
Definition: GA_IOTable.h:29
bool operator!=(const iterator &cmp) const
iterator & operator=(const iterator &src)
bool isForPrimaryDetail() const
GLuint const GLchar * name
Definition: glcorearb.h:785
int cmp(T a, T b)
Definition: ImathFun.h:119
const GA_PrimitiveDefinition * def() const
void(* GA_PrimitiveBlockConstructor)(GA_Primitive **new_prims, GA_Size nprimitives, GA_Detail &detail, GA_Offset start_offset, const GA_PrimitiveDefinition &def, bool allowed_to_parallelize)
int getPrimTypeCount() const
iterator begin() const
Container class for all geometry.
Definition: GA_Detail.h:96
bool registerIO(GA_IO *io)
Definition of a geometric primitive.
bool operator==(const iterator &src) const
Class to traverse all primitive definitions in the factory.
GLenum src
Definition: glcorearb.h:1792