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 48 of file DQMStore.h.

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 51 of file DQMStore.h.

Constructor & Destructor Documentation

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

Definition at line 129 of file DQMStore.cc.

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

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

Definition at line 199 of file DQMStore.cc.

References NULL, and regexp_.

200 {
201  if (regexp_ != NULL)
202  delete regexp_;
203 }
#define NULL
Definition: scimark2.h:8
lat::Regexp * regexp_
Definition: DQMStore.h:67

Member Function Documentation

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

Definition at line 226 of file DQMStore.cc.

Referenced by match().

228 {
229  if (input.size() < pattern.size())
230  return false;
231 
232  // compare the two strings character by character for equalness:
233  // this does not create uneeded copies of std::string. The
234  // boost::algorithm implementation does.
235  std::string::const_iterator rit_pattern = pattern.begin();
236  std::string::const_iterator rit_input = input.begin();
237 
238  for (; rit_pattern < pattern.end(); rit_pattern++, rit_input++)
239  {
240  if (*rit_pattern != *rit_input)
241  // found a difference, fail
242  return false;
243  }
244  return true;
245 }
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 205 of file DQMStore.cc.

Referenced by match().

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

Definition at line 247 of file DQMStore.cc.

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

248 {
249  switch (matching_)
250  {
251  case OneStarStart:
253 
254  case OneStarEnd:
255  return compare_strings(fastString_, s);
256 
257  case TwoStar:
258  return (s.find(fastString_) != std::string::npos);
259 
260  default:
261  return regexp_->match(s);
262  }
263 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:205
MatchingHeuristicEnum matching_
Definition: DQMStore.h:69
lat::Regexp * regexp_
Definition: DQMStore.h:67
std::string fastString_
Definition: DQMStore.h:68
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:226

Member Data Documentation

std::string fastmatch::fastString_
private

Definition at line 68 of file DQMStore.h.

Referenced by fastmatch(), and match().

MatchingHeuristicEnum fastmatch::matching_
private

Definition at line 69 of file DQMStore.h.

Referenced by fastmatch(), and match().

lat::Regexp* fastmatch::regexp_
private

Definition at line 67 of file DQMStore.h.

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