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  // Parse an attribute such as 'P.z' or 'P[2]'. Returns the component of the
124  // vector, or -1 if the index is invalid.
125  static int parseVectorAttributeComponent(
126  const GA_AttributeDict *dict,
127  UT_WorkBuffer &attribname,
128  const GA_Attribute *&attrib);
129 
130  const GA_PrimitiveGroup *parsePrimitiveGroups(const char *pat,
131  const GroupCreator &creator,
132  bool numok,
133  bool ordered,
134  bool strict,
135  GA_Index offset = GA_Index(0),
136  ParseInfo *info = NULL)
137  {
138  return static_cast<const GA_PrimitiveGroup *>
139  (parseGroups(pat, GA_GROUP_PRIMITIVE, creator,
140  numok, true, ordered, strict, offset, info));
141  }
142  const GA_PointGroup *parsePointGroups(const char *pat,
143  const GroupCreator &creator,
144  bool numok,
145  bool ordered,
146  bool strict,
147  GA_Index offset = GA_Index(0),
148  ParseInfo *info = NULL)
149  {
150  return static_cast<const GA_PointGroup *>
151  (parseGroups(pat, GA_GROUP_POINT, creator,
152  numok, true, ordered, strict, offset, info));
153  }
154 
155  const GA_EdgeGroup *parseEdgeGroups(const char *pat,
156  const GroupCreator &creator,
157  bool strict,
158  GA_Index prim_offset = GA_Index(0),
159  GA_Index point_offset = GA_Index(0),
160  ParseInfo *info = NULL);
161 
162  //
163  // Similar to above, except the caller is free to modify its contents
164  //
165 
167  const GroupCreator &creator,
168  bool numok,
169  bool ordered,
170  bool strict,
171  GA_Index offset = GA_Index(0))
172  {
173  return static_cast<GA_PrimitiveGroup *>
174  (constCastParseGroups(pat, GA_GROUP_PRIMITIVE, creator,
175  numok, false, ordered, strict, offset));
176  }
177 
179  const GroupCreator &creator,
180  bool numok,
181  bool ordered,
182  bool strict,
183  GA_Index offset = GA_Index(0))
184  {
185  return static_cast<GA_PointGroup *>
186  (constCastParseGroups(pat, GA_GROUP_POINT, creator,
187  numok, false, ordered, strict, offset));
188  }
189 
190  GA_EdgeGroup *parseEdgeGroupsCopy(const char *pat,
191  const GroupCreator &creator,
192  bool strict,
193  GA_Index prim_offset = GA_Index(0),
194  GA_Index point_offset = GA_Index(0),
195  ParseInfo *info = 0);
196 
197  void expandGroupMask(const char *pattern,
198  UT_String &outNames,
200  const GEO_Detail *gdp);
201 
202  /// Simple helpers to check if the string given is a group string literal
203  /// of a certain type, as output by build*GroupToken. This is call is
204  /// not a definitive arbiter of which group literal string is which type,
205  /// since their definitions are ambiguous.
206  /// Points and primitives: "<num> ..."
207  /// Edges: "[<num>e<num>|p<num>[-<num>...]] ..."
208  /// Vertices: "[<num>|<num>v<num>[-<num>]] ..."
209  /// Breakpoints: "[<num>b[<num>|\[<num>,<num>\]]] ..."
210 
211  static bool isGroupLiteral(const char *pattern, GA_GroupType type);
212 
213  static bool isGroupNumeric(const char* pattern);
214 
215  static void matchGroups(
216  const char *pattern,
217  const GA_GroupTable &group_table,
218  UT_ValArray<const GA_Group *> &match_list);
219 
220  static bool hasAttributePattern(const char *pattern)
221  { return (::strchr(pattern, '@') != nullptr); }
222 
223 private:
224 
225  GOP_Manager *myManager;
226 
227  const GA_Group *parseGroups(const char *inpattern, GA_GroupType type,
228  const GroupCreator &creator,
229  bool allow_numeric,
230  bool allow_reference,
231  bool ordered,
232  bool strict,
234  ParseInfo *info = NULL);
235  GA_Group *constCastParseGroups(const char *inpattern,
237  const GroupCreator &creator,
238  bool allow_numeric,
239  bool allow_reference,
240  bool ordered,
241  bool strict,
243  ParseInfo *info = NULL)
244  {
245  const GA_Group *group = parseGroups(
246  inpattern, type, creator, allow_numeric,
247  allow_reference, ordered, strict, offset, info);
248  UT_ASSERT_MSG_P(!group || group->getInternal(),
249  "This group must be a newly-created, ad-hoc group!");
250  return SYSconst_cast(group);
251  }
252 
253  // Parse a block of consecutive numeric patterns, updating group. Returns
254  // a pointer to the first non-whitespace character in pattern following
255  // the parsed block.
256  //
257  // An optional pointer to gop_PendingParse object may be provided to have
258  // that parse be processed before any numeric patterns.
259  //
260  // PRE: *pattern is 0 or a non-whitespace character.
261  char *parseNumericBlock(char *pattern, bool is_prim,
262  const GroupCreator &creator,
263  GA_ElementGroup *&group,
264  bool &adhoc_flag,
265  bool ordered, GA_Index offset,
266  gop_PendingParse *pending_parse);
267 
268  // Parse a single attribute pattern, updating group. Returns a pointer
269  // to the character in pattern immediately following the block.
270  //
271  // PRE: *pattern == '@' && group != NULL
272  char *parseAttributeGroup(GA_Group *group,
273  char *pattern, bool isPrim,
274  const GA_Detail &gdp, bool remove, bool invert,
275  bool ordered);
276 
277  GA_Group *createAdhocGroup(const GroupCreator &creator,
278  GA_GroupType type);
279  void appendAdhocGroup(GA_Group *group, bool ismetheowner);
280  void destroyAdhocGroup(const GA_Group *group);
281 
282  friend class gop_PendingNamePatternParse;
283 };
284 
285 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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:127
const GEO_Detail * myConstDetail
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)
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))
GLintptr offset
Definition: glcorearb.h:664
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:611
bool getParsedAdhocTokens() const
GLsizei const GLfloat * value
Definition: glcorearb.h:823
const GEO_Detail & getDetail() const
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:138
bool getParsedNameTokens() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Container class for all geometry.
Definition: GA_Detail.h:95
bool getInternal() const
Definition: GA_Group.h:45
#define UT_ASSERT_MSG_P(ZZ, MM)
Definition: UT_Assert.h:128