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

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 54 of file DQMStore.h.

Constructor & Destructor Documentation

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

Definition at line 128 of file DQMStore.cc.

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

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

Definition at line 198 of file DQMStore.cc.

References NULL, and regexp_.

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

Member Function Documentation

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

Definition at line 225 of file DQMStore.cc.

Referenced by match().

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

Referenced by match().

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

Definition at line 246 of file DQMStore.cc.

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

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

Member Data Documentation

std::string fastmatch::fastString_
private

Definition at line 71 of file DQMStore.h.

Referenced by fastmatch(), and match().

MatchingHeuristicEnum fastmatch::matching_
private

Definition at line 72 of file DQMStore.h.

Referenced by fastmatch(), and match().

lat::Regexp* fastmatch::regexp_
private

Definition at line 70 of file DQMStore.h.

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