CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
fastmatch Class Reference

#include <DQMStore.h>

Public Member Functions

 fastmatch (std::string const &_fastString)
 
bool match (std::string const &s) const
 
 ~fastmatch ()
 

Private Types

enum  MatchingHeuristicEnum { UseFull, OneStarStart, OneStarEnd, TwoStar }
 

Private Member Functions

bool compare_strings (std::string const &pattern, std::string const &input) const
 
bool compare_strings_reverse (std::string const &pattern, std::string const &input) const
 

Private Attributes

std::string fastString_
 
MatchingHeuristicEnum matching_
 
lat::Regexp * regexp_
 

Detailed Description

Implements RegEx patterns which occur often in a high-performant mattern. For all other expressions, the full RegEx engine is used. Note: this class can only be used for lat::Regexp::Wildcard-like patterns.

Definition at line 46 of file DQMStore.h.

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 49 of file DQMStore.h.

Constructor & Destructor Documentation

fastmatch::fastmatch ( std::string const &  _fastString)

Definition at line 122 of file DQMStore.cc.

References alignCSCRings::e, fastString_, matching_, NULL, OneStarEnd, OneStarStart, raiseDQMError(), regexp_, and TwoStar.

122  :
123  fastString_ (_fastString), matching_ (UseFull)
124 {
125  try
126  {
127  regexp_ = NULL;
128  regexp_ = new lat::Regexp(fastString_, 0, lat::Regexp::Wildcard);
129  regexp_->study();
130  }
131  catch (lat::Error &e)
132  {
133  delete regexp_;
134  raiseDQMError("DQMStore", "Invalid wildcard pattern '%s' in quality"
135  " test specification", fastString_.c_str());
136  }
137 
138  // count stars ( "*" )
139  size_t starCount = 0;
140  int pos = -1;
141  while (true)
142  {
143  pos = fastString_.find("*", pos + 1 );
144  if ((size_t)pos == std::string::npos)
145  break;
146  starCount ++;
147  }
148 
149  // investigate for heuristics
150  if ((fastString_.find('"') != std::string::npos) ||
151  (fastString_.find(']') != std::string::npos) ||
152  (fastString_.find('?') != std::string::npos) ||
153  (fastString_.find('\\') != std::string::npos) ||
154  (starCount > 2))
155  {
156  // no fast version can be used
157  return;
158  }
159 
160  // match for pattern "*MyString" and "MyString*"
161  if (starCount == 1)
162  {
163  if (boost::algorithm::starts_with(fastString_, "*"))
164  {
166  fastString_.erase(0,1);
167  return;
168  }
169 
170  if (boost::algorithm::ends_with(fastString_, "*"))
171  {
173  fastString_.erase(fastString_.length()-1,1);
174  return;
175  }
176  }
177 
178  // match for pattern "*MyString*"
179  if (starCount == 2)
180  {
181  if (boost::algorithm::starts_with(fastString_, "*") &&
182  boost::algorithm::ends_with(fastString_, "*"))
183  {
184  matching_ = TwoStar;
185  fastString_.erase(0,1);
186  fastString_.erase(fastString_.size() - 1, 1);
187  return;
188  }
189  }
190 }
MatchingHeuristicEnum matching_
Definition: DQMStore.h:67
#define NULL
Definition: scimark2.h:8
lat::Regexp * regexp_
Definition: DQMStore.h:65
std::string fastString_
Definition: DQMStore.h:66
void raiseDQMError(const char *context, const char *fmt,...)
Definition: DQMError.cc:11
fastmatch::~fastmatch ( )

Definition at line 192 of file DQMStore.cc.

References NULL, and regexp_.

193 {
194  if (regexp_ != NULL)
195  delete regexp_;
196 }
#define NULL
Definition: scimark2.h:8
lat::Regexp * regexp_
Definition: DQMStore.h:65

Member Function Documentation

bool fastmatch::compare_strings ( std::string const &  pattern,
std::string const &  input 
) const
private

Definition at line 219 of file DQMStore.cc.

Referenced by match().

221 {
222  if (input.size() < pattern.size())
223  return false;
224 
225  // compare the two strings character by character for equalness:
226  // this does not create uneeded copies of std::string. The
227  // boost::algorithm implementation does.
228  std::string::const_iterator rit_pattern = pattern.begin();
229  std::string::const_iterator rit_input = input.begin();
230 
231  for (; rit_pattern < pattern.end(); rit_pattern++, rit_input++)
232  {
233  if (*rit_pattern != *rit_input)
234  // found a difference, fail
235  return false;
236  }
237  return true;
238 }
static std::string const input
Definition: EdmProvDump.cc:44
bool fastmatch::compare_strings_reverse ( std::string const &  pattern,
std::string const &  input 
) const
private

Definition at line 198 of file DQMStore.cc.

Referenced by match().

200 {
201  if (input.size() < pattern.size())
202  return false;
203 
204  // compare the two strings character by character for equalness:
205  // this does not create uneeded copies of std::string. The
206  // boost::algorithm implementation does
207  std::string::const_reverse_iterator rit_pattern = pattern.rbegin();
208  std::string::const_reverse_iterator rit_input = input.rbegin();
209 
210  for (; rit_pattern < pattern.rend(); rit_pattern++, rit_input++)
211  {
212  if (*rit_pattern != *rit_input)
213  // found a difference, fail
214  return false;
215  }
216  return true;
217 }
static std::string const input
Definition: EdmProvDump.cc:44
bool fastmatch::match ( std::string const &  s) const

Definition at line 240 of file DQMStore.cc.

References compare_strings(), compare_strings_reverse(), fastString_, matching_, OneStarEnd, OneStarStart, regexp_, and TwoStar.

241 {
242  switch (matching_)
243  {
244  case OneStarStart:
246 
247  case OneStarEnd:
248  return compare_strings(fastString_, s);
249 
250  case TwoStar:
251  return (s.find(fastString_) != std::string::npos);
252 
253  default:
254  return regexp_->match(s);
255  }
256 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:198
MatchingHeuristicEnum matching_
Definition: DQMStore.h:67
lat::Regexp * regexp_
Definition: DQMStore.h:65
std::string fastString_
Definition: DQMStore.h:66
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:219

Member Data Documentation

std::string fastmatch::fastString_
private

Definition at line 66 of file DQMStore.h.

Referenced by fastmatch(), and match().

MatchingHeuristicEnum fastmatch::matching_
private

Definition at line 67 of file DQMStore.h.

Referenced by fastmatch(), and match().

lat::Regexp* fastmatch::regexp_
private

Definition at line 65 of file DQMStore.h.

Referenced by fastmatch(), match(), and ~fastmatch().