HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GOP_GroupParse.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  */
7 
8 #ifndef __GOP_GroupParse_h__
9 #define __GOP_GroupParse_h__
10 
11 #include "GOP_API.h"
12 
13 #include <GA/GA_ElementGroup.h>
14 #include <GA/GA_Types.h>
15 #include <UT/UT_Assert.h>
16 #include <SYS/SYS_Types.h>
17 #include <stddef.h>
18 #include <string.h>
19 
20 class UT_String;
21 class UT_WorkBuffer;
22 class GA_Attribute;
23 class GA_AttributeDict;
24 class GA_Detail;
25 class GA_EdgeGroup;
26 class GA_ElementGroup;
27 class GA_Group;
28 class GA_GroupTable;
29 
30 //___________________________________________________________________________
31 
32 class gopAddData;
33 class gop_PendingParse;
34 class GEO_Detail;
35 class GA_PrimitiveGroup;
36 class GA_PointGroup;
37 class GOP_Manager;
38 
40 {
41  friend class gopAddData;
42 
43 public:
44 
45  // A class for requesting ancillary information about a parse operation.
47  {
48  public:
50  : myNumericTokensFlag(false),
51  myAttributeTokensFlag(false),
52  myNameTokensFlag(false)
53  {
54  }
55 
56  bool getParsedNameTokens() const { return myNameTokensFlag; }
57  bool getParsedAdhocTokens() const
58  { return myNumericTokensFlag || myAttributeTokensFlag; }
59 
60  void setParsedNameToken(bool value = true)
61  { myNameTokensFlag = value; }
62  void setParsedNumericToken(bool value = true)
63  { myNumericTokensFlag = value; }
64  void setParsedAttributeToken(bool value = true)
65  { myAttributeTokensFlag = value; }
66 
67  private:
68  bool myNumericTokensFlag;
69  bool myAttributeTokensFlag;
70  bool myNameTokensFlag;
71  };
72 
73  /// This wrapper of a detail allows parsing of groups
74  /// on either a const or non-const GA_Detail using the
75  /// same interface for both. If the detail is const,
76  /// any new group will be detached. If the detail is
77  /// non-const, they will be optionally detached.
79  {
80  public:
82  explicit GroupCreator(const GEO_Detail *detail)
83  : myConstDetail(detail)
84  , myNonConstDetail(NULL)
85  {}
86  GroupCreator(GEO_Detail *detail,bool detached)
87  : myConstDetail(detail)
88  , myNonConstDetail(detached ? NULL : detail)
89  {}
90 
91  GA_Group *createGroup(GA_GroupType type) const;
92 
93  const GEO_Detail &getDetail() const
94  {
95  return *myConstDetail;
96  }
97 
100  };
101 
102 
104  {
105  myManager = manager;
106  };
108 
109  // Build a string that contains the id's of the primitives/points in a
110  // primitive/point group or a primitive/point selection. The offset is
111  // the amount to add to the id of each primitive/point in the selection.
112  static void buildPrimGroupToken(const GEO_Detail *gdp,
113  const GA_PrimitiveGroup *primgrp,
114  UT_String &token,
115  GA_Index offset = GA_Index(0),
116  bool ordered=true);
117  static void buildPointGroupToken(const GEO_Detail *gdp,
118  const GA_PointGroup *ptgrp,
119  UT_String &token,
120  GA_Index offset = GA_Index(0),
121  bool ordered=true);
122 
123  // Build a string representing a single primitive/point element. The offset
124  // is the amount to add to the id of the primitive/point.
125  static void buildPrimElementToken(const GEO_Detail *gdp,
126  GA_Offset prim,
127  UT_String &token,
128  GA_Index offset = GA_Index(0));
129  static void buildPointElementToken(const GEO_Detail *gdp,
130  GA_Offset point,
131  UT_String &token,
132  GA_Index offset = GA_Index(0));
133 
134  // Parse an attribute such as 'P.z' or 'P[2]'. Returns the component of the
135  // vector, or -1 if the index is invalid.
136  static int parseVectorAttributeComponent(
137  const GA_AttributeDict *dict,
138  UT_WorkBuffer &attribname,
139  const GA_Attribute *&attrib);
140 
141  const GA_PrimitiveGroup *parsePrimitiveGroups(const char *pat,
142  const GroupCreator &creator,
143  bool numok,
144  bool ordered,
145  bool strict,
146  GA_Index offset = GA_Index(0),
147  ParseInfo *info = NULL)
148  {
149  return static_cast<const GA_PrimitiveGroup *>
150  (parseGroups(pat, GA_GROUP_PRIMITIVE, creator,
151  numok, true, ordered, strict, offset, info));
152  }
153  const GA_PointGroup *parsePointGroups(const char *pat,
154  const GroupCreator &creator,
155  bool numok,
156  bool ordered,
157  bool strict,
158  GA_Index offset = GA_Index(0),
159  ParseInfo *info = NULL)
160  {
161  return static_cast<const GA_PointGroup *>
162  (parseGroups(pat, GA_GROUP_POINT, creator,
163  numok, true, ordered, strict, offset, info));
164  }
165 
166  const GA_EdgeGroup *parseEdgeGroups(const char *pat,
167  const GroupCreator &creator,
168  bool strict,
169  GA_Index prim_offset = GA_Index(0),
170  GA_Index point_offset = GA_Index(0),
171  ParseInfo *info = NULL);
172 
173  //
174  // Similar to above, except the caller is free to modify its contents
175  //
176 
178  const GroupCreator &creator,
179  bool numok,
180  bool ordered,
181  bool strict,
182  GA_Index offset = GA_Index(0))
183  {
184  return static_cast<GA_PrimitiveGroup *>
185  (constCastParseGroups(pat, GA_GROUP_PRIMITIVE, creator,
186  numok, false, ordered, strict, offset));
187  }
188 
190  const GroupCreator &creator,
191  bool numok,
192  bool ordered,
193  bool strict,
194  GA_Index offset = GA_Index(0))
195  {
196  return static_cast<GA_PointGroup *>
197  (constCastParseGroups(pat, GA_GROUP_POINT, creator,
198  numok, false, ordered, strict, offset));
199  }
200 
201  GA_EdgeGroup *parseEdgeGroupsCopy(const char *pat,
202  const GroupCreator &creator,
203  bool strict,
204  GA_Index prim_offset = GA_Index(0),
205  GA_Index point_offset = GA_Index(0),
206  ParseInfo *info = 0);
207 
208  void expandGroupMask(const char *pattern,
209  UT_String &outNames,
211  const GEO_Detail *gdp);
212 
213  /// Simple helpers to check if the string given is a group string literal
214  /// of a certain type, as output by build*GroupToken. This is call is
215  /// not a definitive arbiter of which group literal string is which type,
216  /// since their definitions are ambiguous.
217  /// Points and primitives: "<num> ..."
218  /// Edges: "[<num>e<num>|p<num>[-<num>...]] ..."
219  /// Vertices: "[<num>|<num>v<num>[-<num>]] ..."
220  /// Breakpoints: "[<num>b[<num>|\[<num>,<num>\]]] ..."
221 
222  static bool isGroupLiteral(const char *pattern, GA_GroupType type);
223 
224  static bool isGroupNumeric(const char* pattern);
225 
226  static void matchGroups(
227  const char *pattern,
228  const GA_GroupTable &group_table,
229  UT_ValArray<const GA_Group *> &match_list);
230 
231  static bool hasAttributePattern(const char *pattern)
232  { return (::strchr(pattern, '@') != nullptr); }
233 
234 private:
235 
236  GOP_Manager *myManager;
237 
238  const GA_Group *parseGroups(const char *inpattern, GA_GroupType type,
239  const GroupCreator &creator,
240  bool allow_numeric,
241  bool allow_reference,
242  bool ordered,
243  bool strict,
245  ParseInfo *info = NULL);
246  GA_Group *constCastParseGroups(const char *inpattern,
248  const GroupCreator &creator,
249  bool allow_numeric,
250  bool allow_reference,
251  bool ordered,
252  bool strict,
254  ParseInfo *info = NULL)
255  {
256  const GA_Group *group = parseGroups(
257  inpattern, type, creator, allow_numeric,
258  allow_reference, ordered, strict, offset, info);
259  UT_ASSERT_MSG_P(!group || group->getInternal(),
260  "This group must be a newly-created, ad-hoc group!");
261  return SYSconst_cast(group);
262  }
263 
264  // Parse a block of consecutive numeric patterns, updating group. Returns
265  // a pointer to the first non-whitespace character in pattern following
266  // the parsed block.
267  //
268  // An optional pointer to gop_PendingParse object may be provided to have
269  // that parse be processed before any numeric patterns.
270  //
271  // PRE: *pattern is 0 or a non-whitespace character.
272  char *parseNumericBlock(char *pattern, bool is_prim,
273  const GroupCreator &creator,
274  GA_ElementGroup *&group,
275  bool &adhoc_flag,
276  bool ordered, GA_Index offset,
277  gop_PendingParse *pending_parse);
278 
279  // Parse a single attribute pattern, updating group. Returns a pointer
280  // to the character in pattern immediately following the block.
281  //
282  // PRE: *pattern == '@' && group != NULL
283  char *parseAttributeGroup(GA_Group *group,
284  char *pattern, bool isPrim,
285  const GA_Detail &gdp, bool remove, bool invert,
286  bool ordered);
287 
288  GA_Group *createAdhocGroup(const GroupCreator &creator,
289  GA_GroupType type);
290  void appendAdhocGroup(GA_Group *group, bool ismetheowner);
291  void destroyAdhocGroup(const GA_Group *group);
292 
293  friend class gop_PendingNamePatternParse;
294 };
295 
296 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
GLboolean invert
Definition: glew.h:1422
void setParsedNumericToken(bool value=true)
GA_PointGroup * parsePointGroupsCopy(const char *pat, const GroupCreator &creator, bool numok, bool ordered, bool strict, GA_Index offset=GA_Index(0))
GroupCreator(GEO_Detail *detail, bool detached)
void setParsedNameToken(bool value=true)
void setParsedAttributeToken(bool value=true)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:131
const GEO_Detail * myConstDetail
#define UT_ASSERT_MSG_P(ZZ,...)
Definition: UT_Assert.h:137
const GA_PrimitiveGroup * parsePrimitiveGroups(const char *pat, const GroupCreator &creator, bool numok, bool ordered, bool strict, GA_Index offset=GA_Index(0), ParseInfo *info=NULL)
#define GOP_API
Definition: GOP_API.h:10
A string map of attributes to ease backward compatibility In the GB/GEO/GU library code would often p...
const GA_PointGroup * parsePointGroups(const char *pat, const GroupCreator &creator, bool numok, bool ordered, bool strict, GA_Index offset=GA_Index(0), ParseInfo *info=NULL)
GA_Size GA_Offset
Definition: GA_Types.h:637
GOP_GroupParse(GOP_Manager *manager)
GA_PrimitiveGroup * parsePrimitiveGroupsCopy(const char *pat, const GroupCreator &creator, bool numok, bool ordered, bool strict, GA_Index offset=GA_Index(0))
static bool hasAttributePattern(const char *pattern)
GroupCreator(const GEO_Detail *detail)
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
bool getParsedAdhocTokens() const
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
const GEO_Detail & getDetail() const
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:157
bool getParsedNameTokens() const
Container class for all geometry.
Definition: GA_Detail.h:95
GLubyte * pattern
Definition: glew.h:5711
GLsizei const GLfloat * value
Definition: glew.h:1849
bool getInternal() const
Definition: GA_Group.h:45
GLboolean GLuint group
Definition: glew.h:2745
GLintptr offset
Definition: glew.h:1682