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