test
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 131 of file DQMStore.cc.

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

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

References NULL, and regexp_.

202 {
203  if (regexp_ != NULL)
204  delete regexp_;
205 }
#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 228 of file DQMStore.cc.

Referenced by match().

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

Referenced by match().

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

Definition at line 249 of file DQMStore.cc.

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

250 {
251  switch (matching_)
252  {
253  case OneStarStart:
255 
256  case OneStarEnd:
257  return compare_strings(fastString_, s);
258 
259  case TwoStar:
260  return (s.find(fastString_) != std::string::npos);
261 
262  default:
263  return regexp_->match(s);
264  }
265 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:207
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:228

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().