HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_BundlePattern.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: OP_BundlePattern.h ( OP Library, C++)
7  *
8  * COMMENTS: Pattern tokens for a bundle. This breaks up the pattern string
9  * into managable tokens which can be processed easily
10  */
11 
12 #ifndef __OP_BundlePattern__
13 #define __OP_BundlePattern__
14 
15 #include "OP_API.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_SharedPtr.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_StringMap.h>
21 
22 class OP_Node;
23 class OP_BundleFilter;
24 class UT_Regex;
25 
27 public:
28  static OP_BundlePattern *allocPattern(const char *str,
29  bool ignore_case = false);
30  static void freePattern(OP_BundlePattern *pattern);
31 
32  int argc() const { return myPatterns.entries(); }
33  const char *argv(int i) const
34  {
35  return myPatterns(i).org_str;
36  }
37 
38  bool isAllPattern() const { return myAllPattern; }
39  bool isNullPattern() const { return myNullPattern; }
40 
41  bool hasPattern(const char *str) const;
42 
43  bool match(const OP_Node *node, const char *relativepath,
44  bool assume_kids_included) const;
45 
46  //
47  // Raw, single match function. This can be used in filter traversal.
48  bool matchNode(const OP_Node *node,
49  const char *relativetopath,
50  bool result_if_no_match,
51  int *excluded) const;
52 
53 protected:
54  OP_BundlePattern(const char *str, bool ignore_case);
56 
57 private:
58  struct Pattern
59  {
60  bool is_pattern; // false if just a plain string
61  bool is_negated; // negated pattern (starts with a ^)
62  bool is_relative; // Relative pattern (starts with './')
63  const char *org_str; // The original string
64  const char *str; // Adjusted string (for carat)
65  const char *rel_str; // Relative string (incl carat)
67  UT_SharedPtr<UT_Regex> rel_pattern;
68  };
69 
70  const char *myPatternToken;
71 
72  // A copy of the original string. Just used as a storage for the tokenized
73  // parts.
74  UT_String myPattern;
75 
76  // Extra storage for modified strings
77  UT_StringArray myModifiedPatterns;
78 
79  // The list of sub-patterns.
80  UT_Array<Pattern> myPatterns;
81 
82  // Here we store a map into the pattern array of strings that are
83  // "plain" and contain no glob/regex characters.
84  typedef UT_StringMap<exint> PlainPatternMap;
85 
86  PlainPatternMap myPlainPatterns;
87  PlainPatternMap myRelPatterns;
88 
89  int myRefCount;
90  bool myAllPattern;
91  bool myNullPattern;
92  bool myIgnoreCase;
93 };
94 #endif
95 
std::string ignore_case(std::string item)
Helper function to allow ignore_case to be passed to IsMember or Transform.
Definition: CLI11.h:3456
const char * argv(int i) const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
int argc() const
GLushort pattern
Definition: glad.h:2583
bool isNullPattern() const
#define OP_API
Definition: OP_API.h:10
bool isAllPattern() const