HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributePattern Class Reference

#include <PDG_AttributePattern.h>

+ Inheritance diagram for PDG_AttributePattern:

Classes

struct  ComponentMatch
 

Public Types

enum  MatchType : uint8 {
  eMatchAll, eMatchPrefix, eMatchSuffix, eMatchBoth,
  eMatchPlain
}
 For compound matching, e.g. foobar or bin*:float. More...
 
using ComponentMap = UT_StringMap< ComponentMatch >
 Map of attribute name to ComponentMatch. More...
 

Public Member Functions

 PDG_AttributePattern ()
 Constructs a default-initialized, invalid pattern. More...
 
 PDG_AttributePattern (const UT_StringHolder &pattern, MatchType default_match_type=eMatchPlain, bool strict=true)
 Parses a pattern into a PDG_AttributePattern instance. More...
 
bool reset (const UT_StringHolder &pattern, MatchType default_match_type=eMatchPlain, bool strict=true)
 Clears the pattern and recompiles it from the specified pattern string. More...
 
bool tryReset (const UT_StringHolder &pattern, MatchType default_match_type=eMatchPlain, bool strict=true)
 
bool contains (const UT_StringHolder &name, PDG_AttributeType type=PDG_AttributeType::eUndefined) const
 Returns true if the attribute/type is include in the pattern. More...
 
bool components (ComponentMatch &components, const UT_StringHolder &name, PDG_AttributeType type=PDG_AttributeType::eUndefined) const
 
void multiMatch (UT_StringArray &match_results, const UT_StringArray &input_names, bool keep_plain) const
 
void multiMatch (ComponentMap &match_components, const UT_StringArray &input_names, bool keep_plain) const
 
- Public Member Functions inherited from PDG_BasePattern
 PDG_BasePattern (const UT_StringHolder &pattern)
 Constructs a default-initialized, invalid pattern. More...
 
bool isValid () const
 
const UT_WorkBuffererrors () const
 If the pattern is invalid, contains parse errors. More...
 
const UT_StringHolderpattern () const
 Returns the pattern used to construct this object. More...
 
bool hasPattern () const
 Returns true if there is a pattern set. More...
 
void reset (const UT_StringHolder &pattern)
 Resets the pattern. More...
 

Additional Inherited Members

- Protected Types inherited from PDG_BasePattern
enum  ParseTokens : uint8 {
  eStarToken = '*', eExcludeToken = '^', eSeparatorToken = ':', eRangeToken = '-',
  eQuoteToken = '"', eEscapeToken = '\\', eRangeBeginToken = '[', eRangeEndToken = ']',
  eAttributeToken = '@', eComponentToken = '.'
}
 Special tokens, in addition to alphanumeric and whitespace. More...
 
- Protected Attributes inherited from PDG_BasePattern
UT_WorkBuffer myErrors
 Parse errors. More...
 
UT_StringHolder myPattern
 The pattern used to construct this object. More...
 
bool myIsValid
 Whether or not the pattern is valid. More...
 

Detailed Description

Pattern for matching a list of attributes. A pattern object is constructed from a valid pattern string, such as: * ^foo.

A pattern is a whitespace seperated sequence of match conditions. Each condition can:

  • Optionally begin with a ^
  • Be a single * character
  • Or, be a valid attribute name with an optional leading *, trailing * or both a leading a trailing *
  • Optionally end with a : followed by a valid type name, for example float, integer or string.

The following are valid:

 *
 * ^foo:float
 * ^*foo ^bar* ^*foobar* ^*:string
 *:integer
 foo ^bar *:python

The following are not: ^ foo*bar ** f*o ^:integer ^*:foobar

Pattern rules are applied left to right when checking if an attribute name matches.

If the pattern matcher is constructed with the strict option set to false, then all characters except for * an ^ are valid for attribute names. This also disables the type specifier : character, and type name parsing.

Definition at line 62 of file PDG_AttributePattern.h.

Member Typedef Documentation

Map of attribute name to ComponentMatch.

Definition at line 98 of file PDG_AttributePattern.h.

Member Enumeration Documentation

For compound matching, e.g. foobar or bin*:float.

Enumerator
eMatchAll 

The pattern is just a *.

eMatchPrefix 

The pattern is a * followed by a string name.

eMatchSuffix 

The pattern is a string name, followed by a *.

eMatchBoth 

The pattern is a string name with both a prefix and suffix.

eMatchPlain 

The pattern has no *.

Definition at line 66 of file PDG_AttributePattern.h.

Constructor & Destructor Documentation

PDG_AttributePattern::PDG_AttributePattern ( )

Constructs a default-initialized, invalid pattern.

PDG_AttributePattern::PDG_AttributePattern ( const UT_StringHolder pattern,
MatchType  default_match_type = eMatchPlain,
bool  strict = true 
)

Parses a pattern into a PDG_AttributePattern instance.

Member Function Documentation

bool PDG_AttributePattern::components ( ComponentMatch components,
const UT_StringHolder name,
PDG_AttributeType  type = PDG_AttributeType::eUndefined 
) const

Returns true if the attribute/type is included in the pattern, and writes the match components.

bool PDG_AttributePattern::contains ( const UT_StringHolder name,
PDG_AttributeType  type = PDG_AttributeType::eUndefined 
) const

Returns true if the attribute/type is include in the pattern.

void PDG_AttributePattern::multiMatch ( UT_StringArray match_results,
const UT_StringArray input_names,
bool  keep_plain 
) const

Applies the pattern to the specified list of input names, and returns the final list of names that matched the pattern. If keep_plain is true, then any non-glob pattern pattern entries are always included even if they don't appear in the input names list.

void PDG_AttributePattern::multiMatch ( ComponentMap match_components,
const UT_StringArray input_names,
bool  keep_plain 
) const

Applies the pattern to the specified list of input names, and returns a map of matched components for each name. If keep_plain is true, then any non-glob pattern entries are always included even if they don't appear in the input names list.

bool PDG_AttributePattern::reset ( const UT_StringHolder pattern,
MatchType  default_match_type = eMatchPlain,
bool  strict = true 
)

Clears the pattern and recompiles it from the specified pattern string.

bool PDG_AttributePattern::tryReset ( const UT_StringHolder pattern,
MatchType  default_match_type = eMatchPlain,
bool  strict = true 
)

Resets the pattern if doesn't match the specified pattern string and configuration arguments.


The documentation for this class was generated from the following file: