HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_BasePattern.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_BASE_PATTERN_H__
10 #define __PDG_BASE_PATTERN_H__
11 
12 #include "PDG_API.h"
13 
14 #include <UT/UT_StringHolder.h>
15 #include <UT/UT_WorkBuffer.h>
16 
17 /**
18  * Base class for pattern matching utilities
19  */
21 {
22 public:
23  /// Constructs a default-initialized, invalid pattern.
25  : myPattern(pattern)
26  , myIsValid(false) {}
27 
28  /// Returns true if the pattern is valid, else false. If the pattern is
29  /// invalid the errors() contains a string representation of any parse
30  /// errors
31  bool isValid() const
32  { return myIsValid; }
33 
34  /// If the pattern is invalid, contains parse errors
35  const UT_WorkBuffer& errors() const
36  { return myErrors; }
37 
38  /// Returns the pattern used to construct this object
39  const UT_StringHolder& pattern() const
40  { return myPattern; }
41 
42  /// Returns true if there is a pattern set
43  bool hasPattern() const
44  { return myPattern.isstring() &&
45  !myPattern.isEmpty(); }
46 
47  /// Resets the pattern
49  {
50  myPattern = pattern;
51  myIsValid = false;
52  myErrors.clear();
53  }
54 
55 protected:
56  /// Special tokens, in addition to alphanumeric and whitespace
58  {
59  /// Star token for globbing
60  eStarToken = '*',
61 
62  /// Exclusion token
63  eExcludeToken = '^',
64 
65  /// Type or range split token
66  eSeparatorToken = ':',
67 
68  /// Value range token
69  eRangeToken = '-',
70 
71  /// Double quote token
72  eQuoteToken = '"',
73 
74  /// Escape token
75  eEscapeToken = '\\',
76 
77  /// Range begin token
78  eRangeBeginToken = '[',
79 
80  /// Range end token
81  eRangeEndToken = ']',
82 
83  /// Attribute name token
84  eAttributeToken = '@',
85 
86  /// Attribute component token
87  eComponentToken = '.',
88  };
89 
90 protected:
91  /// Parse errors
93 
94  /// The pattern used to construct this object
96 
97  /// Whether or not the pattern is valid
98  bool myIsValid;
99 };
100 
101 #endif
UT_WorkBuffer myErrors
Parse errors.
#define PDG_API
Definition: PDG_API.h:23
void reset(const UT_StringHolder &pattern)
Resets the pattern.
bool hasPattern() const
Returns true if there is a pattern set.
bool isValid() const
bool myIsValid
Whether or not the pattern is valid.
unsigned char uint8
Definition: SYS_Types.h:36
ParseTokens
Special tokens, in addition to alphanumeric and whitespace.
GLushort pattern
Definition: glad.h:2583
const UT_WorkBuffer & errors() const
If the pattern is invalid, contains parse errors.
UT_StringHolder myPattern
The pattern used to construct this object.
const UT_StringHolder & pattern() const
Returns the pattern used to construct this object.
PDG_BasePattern(const UT_StringHolder &pattern)
Constructs a default-initialized, invalid pattern.