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_GroupUPtr createGroup(GA_GroupType type) const;
105 
106  // Like createGroup except that you can directly cast it to the
107  // expected element group type ptr.
108  template <typename ElemGroup>
110  {
111  return UT_UniquePtr<ElemGroup>(UTverify_cast<ElemGroup *>(
112  createGroup(type).release()));
113  }
114 
115  const GEO_Detail &getDetail() const
116  {
117  UT_ASSERT(myConstDetail);
118  return *myConstDetail;
119  }
120 
123  };
124 
125 
127  {
128  myManager = manager;
129  };
131 
132  // Build a string that contains the id's of the primitives/points in a
133  // primitive/point group or a primitive/point selection. The offset is
134  // the amount to add to the id of each primitive/point in the selection.
135  static void buildPrimGroupToken(const GEO_Detail *gdp,
136  const GA_PrimitiveGroup *primgrp,
137  UT_String &token,
138  GA_Index offset = GA_Index(0),
139  bool ordered=true);
140  static void buildPointGroupToken(const GEO_Detail *gdp,
141  const GA_PointGroup *ptgrp,
142  UT_String &token,
143  GA_Index offset = GA_Index(0),
144  bool ordered=true);
145 
146  // Build a string representing a single primitive/point element. The offset
147  // is the amount to add to the id of the primitive/point.
148  static void buildPrimElementToken(const GEO_Detail *gdp,
149  GA_Offset prim,
150  UT_String &token,
151  GA_Index offset = GA_Index(0));
152  static void buildPointElementToken(const GEO_Detail *gdp,
153  GA_Offset point,
154  UT_String &token,
155  GA_Index offset = GA_Index(0));
156 
157  // Parse an attribute such as 'P.z' or 'P[2]'. Returns the component of the
158  // vector, or -1 if the index is invalid.
159  static int parseVectorAttributeComponent(
160  const GA_AttributeDict *dict,
161  UT_WorkBuffer &attribname,
162  const GA_Attribute *&attrib);
163 
164  const GA_PrimitiveGroup *parsePrimitiveGroups(const char *pat,
165  const GroupCreator &creator,
166  bool numok,
167  bool ordered,
168  bool strict,
169  GA_Index offset = GA_Index(0),
170  ParseInfo *info = NULL)
171  {
172  return static_cast<const GA_PrimitiveGroup *>
173  (parseGroups(pat, GA_GROUP_PRIMITIVE, creator,
174  numok, true, ordered, strict, offset, info));
175  }
176  const GA_PointGroup *parsePointGroups(const char *pat,
177  const GroupCreator &creator,
178  bool numok,
179  bool ordered,
180  bool strict,
181  GA_Index offset = GA_Index(0),
182  ParseInfo *info = NULL)
183  {
184  return static_cast<const GA_PointGroup *>
185  (parseGroups(pat, GA_GROUP_POINT, creator,
186  numok, true, ordered, strict, offset, info));
187  }
188 
189  const GA_EdgeGroup *parseEdgeGroups(const char *pat,
190  const GroupCreator &creator,
191  bool strict,
192  GA_Index prim_offset = GA_Index(0),
193  GA_Index point_offset = GA_Index(0),
194  ParseInfo *info = NULL);
195 
196  //
197  // Similar to above, except the caller is free to modify its contents
198  //
199 
201  const GroupCreator &creator,
202  bool numok,
203  bool ordered,
204  bool strict,
205  GA_Index offset = GA_Index(0))
206  {
207  return static_cast<GA_PrimitiveGroup *>
208  (constCastParseGroups(pat, GA_GROUP_PRIMITIVE, creator,
209  numok, false, ordered, strict, offset));
210  }
211 
213  const GroupCreator &creator,
214  bool numok,
215  bool ordered,
216  bool strict,
217  GA_Index offset = GA_Index(0))
218  {
219  return static_cast<GA_PointGroup *>
220  (constCastParseGroups(pat, GA_GROUP_POINT, creator,
221  numok, false, ordered, strict, offset));
222  }
223 
224  GA_EdgeGroup *parseEdgeGroupsCopy(const char *pat,
225  const GroupCreator &creator,
226  bool strict,
227  GA_Index prim_offset = GA_Index(0),
228  GA_Index point_offset = GA_Index(0),
229  ParseInfo *info = 0);
230 
231  void expandGroupMask(const char *pattern,
232  UT_String &outNames,
234  const GEO_Detail *gdp);
235 
236  /// Simple helpers to check if the string given is a group string literal
237  /// of a certain type, as output by build*GroupToken. This is call is
238  /// not a definitive arbiter of which group literal string is which type,
239  /// since their definitions are ambiguous.
240  /// Points and primitives: "<num> ..."
241  /// Edges: "[<num>e<num>|p<num>[-<num>...]] ..."
242  /// Vertices: "[<num>|<num>v<num>[-<num>]] ..."
243  /// Breakpoints: "[<num>b[<num>|\[<num>,<num>\]]] ..."
244 
245  static bool isGroupLiteral(const char *pattern, GA_GroupType type);
246 
247  static bool isGroupNumeric(const char* pattern);
248 
249  static void matchGroups(
250  const char *pattern,
251  const GA_GroupTable &group_table,
252  UT_ValArray<const GA_Group *> &match_list);
253 
254  static bool hasAttributePattern(const char *pattern)
255  { return (::strchr(pattern, '@') != nullptr); }
256 
257 private:
258 
259  GOP_Manager *myManager;
260 
261  const GA_Group *parseGroups(const char *inpattern, GA_GroupType type,
262  const GroupCreator &creator,
263  bool allow_numeric,
264  bool allow_reference,
265  bool ordered,
266  bool strict,
268  ParseInfo *info = NULL);
269  GA_Group *constCastParseGroups(const char *inpattern,
271  const GroupCreator &creator,
272  bool allow_numeric,
273  bool allow_reference,
274  bool ordered,
275  bool strict,
277  ParseInfo *info = NULL)
278  {
279  const GA_Group *group = parseGroups(
280  inpattern, type, creator, allow_numeric,
281  allow_reference, ordered, strict, offset, info);
282  UT_ASSERT_MSG_P(!group || group->getInternal(),
283  "This group must be a newly-created, ad-hoc group!");
284  return SYSconst_cast(group);
285  }
286 
287  // Parse a block of consecutive numeric patterns, updating group. Returns
288  // a pointer to the first non-whitespace character in pattern following
289  // the parsed block.
290  //
291  // An optional pointer to gop_PendingParse object may be provided to have
292  // that parse be processed before any numeric patterns.
293  //
294  // PRE: *pattern is 0 or a non-whitespace character.
295  char *parseNumericBlock(char *pattern, bool is_prim,
296  const GroupCreator &creator,
297  GA_ElementGroup *&group,
298  bool &adhoc_flag,
299  bool ordered, GA_Index offset,
300  gop_PendingParse *pending_parse);
301 
302  // Parse a single attribute pattern, updating group. Returns a pointer
303  // to the character in pattern immediately following the block.
304  //
305  // PRE: *pattern == '@' && group != NULL
306  char *parseAttributeGroup(GA_Group *group,
307  char *pattern, bool isPrim,
308  const GA_Detail &gdp, bool remove, bool invert,
309  bool ordered, ParseInfo *info = NULL);
310 
311  GA_Group *createAdhocGroup(const GroupCreator &creator,
312  GA_GroupType type);
313  void appendAdhocGroup(GA_Group *group, bool ismetheowner);
314  void destroyAdhocGroup(const GA_Group *group);
315 
316  friend class gop_PendingNamePatternParse;
317 };
318 
319 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
const UT_StringArray & getAttributeTokens() const
void setParsedNumericToken(bool value=true)
GLboolean invert
Definition: glcorearb.h:549
GA_PointGroup * parsePointGroupsCopy(const char *pat, const GroupCreator &creator, bool numok, bool ordered, bool strict, GA_Index offset=GA_Index(0))
GLsizei const GLfloat * value
Definition: glcorearb.h:824
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
GLdouble s
Definition: glad.h:3009
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
#define UT_ASSERT_MSG_P(ZZ,...)
Definition: UT_Assert.h:158
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)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#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:641
GOP_GroupParse(GOP_Manager *manager)
GLintptr offset
Definition: glcorearb.h:665
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)
GLushort pattern
Definition: glad.h:2583
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:635
bool getParsedAdhocTokens() const
UT_UniquePtr< GA_Group > GA_GroupUPtr
Definition: GA_Group.h:199
const GEO_Detail & getDetail() const
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:160
bool getParsedNameTokens() const
Container class for all geometry.
Definition: GA_Detail.h:96
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Definition: core.h:1131
type
Definition: core.h:1059
bool getInternal() const
Definition: GA_Group.h:46
UT_UniquePtr< ElemGroup > createElemGroup(GA_GroupType type) const