cPatternMatcher Class Reference

Glob-style pattern matching class, adopted to special OMNeT++ requirements. More...

#include <cpatternmatcher.h>

List of all members.

Public Member Functions

 cPatternMatcher ()
 cPatternMatcher (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive)
 ~cPatternMatcher ()
void setPattern (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive)
bool matches (const char *line)
const char * patternPrefixMatches (const char *line, int suffixoffset)
std::string debugStr ()
void dump ()

Static Public Member Functions

static bool containsWildcards (const char *pattern)

Detailed Description

Glob-style pattern matching class, adopted to special OMNeT++ requirements.

One instance represents a pattern to match.

Pattern syntax:

The "except '.'" phrases in the above rules apply only in "dottedpath" mode (see below).

There are three option switches (see setPattern() method):

Rule details:


Member Function Documentation

static bool cPatternMatcher::containsWildcards ( const char *  pattern  )  [static]

Utility function to determine whether a given string contains wildcards.

If it does not, a simple strcmp() might be a faster option than using cPatternMatcher.

std::string cPatternMatcher::debugStr (  ) 

Returns the internal representation of the pattern as a string.

May be useful for debugging purposes.

void cPatternMatcher::dump (  ) 

Prints the internal representation of the pattern on the standard output.

May be useful for debugging purposes.

bool cPatternMatcher::matches ( const char *  line  ) 

Returns true if the line matches the pattern with the given settings.

See setPattern().

const char* cPatternMatcher::patternPrefixMatches ( const char *  line,
int  suffixoffset 
)

Similar to matches(): it returns non-NULL iif (1) the pattern ends in a string literal (and not, say, '*' or '**') which contains the line suffix (which begins at suffixoffset characters of line) and (2) pattern matches the whole line, except that (3) in matching the pattern's last string literal, it is also accepted if line is shorter than the pattern.

If the above conditions hold, it returns the rest of the pattern. The returned pointer is valid until the next call to this method.

This method is used by cIniFile's getEntriesWithPrefix(), used e.g. to find RNG mapping entries for a module. For that, we have to find all ini file entries (keys) like "net.host1.gen.rng-NN" where NN=0,1,2,... In cIniFile, every entry is a pattern ("**.host*.gen.rng-1", "**.*.gen.rng-0", etc.). So we'd invoke patternPrefixMatches("net.host1.gen.rng-", 13) (i.e. suffix=".rng-") to find those entries (patterns) which can expand to "net.host1.gen.rng-0", "net.host1.gen.rng-1", etc.

See matches().

void cPatternMatcher::setPattern ( const char *  pattern,
bool  dottedpath,
bool  fullstring,
bool  casesensitive 
)

Sets the pattern to be used by subsequent calls to matches().

See the general class description for the meaning of the rest of the arguments. Throws cException if the pattern is bogus.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:29 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3