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