Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FuzzyStringComparator.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Clemens Groepl, Stephan Aiche $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
36 #define OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
37 
38 #include <OpenMS/CONCEPT/Types.h>
41 
42 #include <iosfwd>
43 #include <map>
44 
45 #ifdef OPENMS_HAS_STREAM_EXTRACTION_BUG
46 #include <boost/lexical_cast.hpp>
47 #endif // OPENMS_HAS_STREAM_EXTRACTION_BUG
48 
49 namespace OpenMS
50 {
51  namespace Internal
52  {
53  namespace ClassTest
54  {
55  void OPENMS_DLLAPI testStringSimilar(const char * file,
56  int line,
57  const std::string & string_1,
58  const char * string_1_stringified,
59  const std::string & string_2,
60  const char * string_2_stringified);
61 
62  bool OPENMS_DLLAPI isFileSimilar(const std::string &,
63  const std::string &);
64  }
65  }
66 
70  class OPENMS_DLLAPI FuzzyStringComparator
71  {
72 
73  friend void OPENMS_DLLAPI
75  const char * file,
76  int line,
77  const std::string & string_1,
78  const char * string_1_stringified,
79  const std::string & string_2,
80  const char * string_2_stringified);
81 
82  friend bool OPENMS_DLLAPI
83  Internal::ClassTest::isFileSimilar(const std::string &,
84  const std::string &);
85 
88  {
89  };
90 
91 public:
92 
94 
95 
98 
100  virtual
102 
105 
107  FuzzyStringComparator & operator=(const FuzzyStringComparator & rhs);
108 
110 
112  const double & getAcceptableRelative() const;
113 
115  void setAcceptableRelative(const double rhs);
116 
118  const double & getAcceptableAbsolute() const;
119 
121  void setAcceptableAbsolute(const double rhs);
122 
124  const StringList & getWhitelist() const;
125 
127  StringList & getWhitelist();
128 
130  void setWhitelist(const StringList & rhs);
131 
133  void setMatchedWhitelist(const std::vector< std::pair<std::string, std::string> >& rhs);
134 
136  const std::vector< std::pair<std::string, std::string> >& getMatchedWhitelist() const;
137 
146  const int & getVerboseLevel() const;
147 
156  void setVerboseLevel(const int rhs);
157 
161  const int & getTabWidth() const;
162 
166  void setTabWidth(const int rhs);
167 
171  const int & getFirstColumn() const;
172 
176  void setFirstColumn(const int rhs);
177 
184  std::ostream & getLogDestination() const;
185 
196  void setLogDestination(std::ostream & rhs);
197 
205  bool compareStrings(std::string const & lhs, std::string const & rhs);
206 
215  bool compareStreams(std::istream & input_1, std::istream & input_2);
216 
231  bool compareFiles(const std::string & filename_1,
232  const std::string & filename_2);
233 
234 protected:
235 
244  bool compareLines_(std::string const & line_str_1, std::string const & line_str_2);
245 
247  void reportSuccess_() const;
248 
251  void reportFailure_(char const * const message) const;
252 
254  void writeWhitelistCases_(const std::string & prefix) const;
255 
258  void readNextLine_(std::istream & input_stream, std::string & line_string, int & line_number) const;
259 
261  bool openInputFileStream_(const std::string & filename, std::ifstream & input_stream) const;
262 
264  std::ostream * log_dest_;
265 
267  std::string input_1_name_;
269  std::string input_2_name_;
270 
272  struct InputLine
273  {
274  std::stringstream line_;
275  std::ios::pos_type line_position_;
276 
277  InputLine();
278 
280  void setToString(const std::string & s);
281 
283  void updatePosition();
284 
286  void seekGToSavedPosition();
287 
295  bool ok() const;
296  };
297 
300 
303 
306 
307  std::string line_str_1_max_;
308  std::string line_str_2_max_;
309 
312 
314  double ratio_max_;
315 
318 
320  double absdiff_max_;
321 
324  {
325  double number;
326  unsigned char letter;
327  bool is_number;
328  bool is_space;
329 
330  StreamElement_();
331 
333  void reset();
334 #ifdef OPENMS_HAS_STREAM_EXTRACTION_BUG
335 
344  bool readdigits(InputLine & input_line, std::string & target_buffer, char & c_buffer);
345 
353  bool tryExtractDouble(InputLine & input_line, double & target);
354 #endif
355  void fillFromInputLine(InputLine & input_line);
357  };
358 
363 
365  struct PrefixInfo_
366  {
370 
371  PrefixInfo_(const InputLine & input_line, const int tab_width_, const int first_column_);
372  };
373 
375 
379 
385 
388 
392  std::map<String, UInt> whitelist_cases_;
393 
395  std::vector< std::pair<std::string, std::string> > matched_whitelist_;
396  }; // class FuzzyStringComparator
397 
398 } //namespace OpenMS
399 
400 #endif //OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
StreamElement_ element_2_
Stores information about characters, numbers, and white spaces loaded from the second input stream...
Definition: FuzzyStringComparator.h:362
int verbose_level_
Definition: FuzzyStringComparator.h:376
void testStringSimilar(const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified)
Compare strings using absdiff_max_allowed and ratio_max_allowed.
A more convenient string class.
Definition: String.h:57
Internal exception class.
Definition: FuzzyStringComparator.h:87
Stores information about the current input line (i.e., stream for the line and the current position i...
Definition: FuzzyStringComparator.h:272
double ratio_max_allowed_
Maximum ratio of numbers allowed, see ratio_max_.
Definition: FuzzyStringComparator.h:311
Stores information about characters, numbers, and white spaces loaded from the InputStream.
Definition: FuzzyStringComparator.h:323
double absdiff_max_
Maximum difference of numbers observed so far, see absdiff_max_allowed_.
Definition: FuzzyStringComparator.h:320
int line_column
Definition: FuzzyStringComparator.h:369
double absdiff_max_allowed_
Maximum absolute difference of numbers allowed, see absdiff_max_.
Definition: FuzzyStringComparator.h:317
OpenMS::String prefix
Definition: FuzzyStringComparator.h:367
bool use_prefix_
use a prefix when reporting
Definition: FuzzyStringComparator.h:387
std::ostream * log_dest_
Log and results output goes here.
Definition: FuzzyStringComparator.h:264
void setWhitelist(const char *const, const int line, const std::string &whitelist)
set the whitelist_
std::vector< std::pair< std::string, std::string > > matched_whitelist_
Alternative Whitelist.
Definition: FuzzyStringComparator.h:395
unsigned char letter
Definition: FuzzyStringComparator.h:326
std::ios::pos_type line_position_
Definition: FuzzyStringComparator.h:275
bool is_space
Definition: FuzzyStringComparator.h:328
Fuzzy comparison of strings, tolerates numeric differences.
Definition: FuzzyStringComparator.h:70
std::string line_str_2_max_
Definition: FuzzyStringComparator.h:308
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
int line_num_2_
Definition: FuzzyStringComparator.h:302
std::map< String, UInt > whitelist_cases_
Occurences of whitelist entries.
Definition: FuzzyStringComparator.h:392
bool is_number
Definition: FuzzyStringComparator.h:327
OpenMS::String prefix_whitespaces
Definition: FuzzyStringComparator.h:368
double number
Definition: FuzzyStringComparator.h:325
int first_column_
Definition: FuzzyStringComparator.h:378
int tab_width_
Definition: FuzzyStringComparator.h:377
double ratio_max_
Maximum ratio of numbers observed so far, see ratio_max_allowed_.
Definition: FuzzyStringComparator.h:314
int line_num_1_
Definition: FuzzyStringComparator.h:301
StreamElement_ element_1_
Stores information about characters, numbers, and white spaces loaded from the first input stream...
Definition: FuzzyStringComparator.h:360
StringList whitelist_
Whitelist.
Definition: FuzzyStringComparator.h:390
InputLine input_line_2_
Definition: FuzzyStringComparator.h:299
bool is_status_success_
Has comparison been successful so far? Note: this flag is changed in reportFailure_();.
Definition: FuzzyStringComparator.h:384
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
std::string input_2_name_
Name of second input e.g., filename.
Definition: FuzzyStringComparator.h:269
int line_num_1_max_
Definition: FuzzyStringComparator.h:304
std::string line_str_1_max_
Definition: FuzzyStringComparator.h:307
std::stringstream line_
Definition: FuzzyStringComparator.h:274
bool isFileSimilar(const std::string &filename_1, const std::string &filename_2)
Compare files using absdiff_max_allowed and ratio_max_allowed.
bool is_absdiff_small_
Definition: FuzzyStringComparator.h:374
Wrapper for the prefix information computed for the failure report.
Definition: FuzzyStringComparator.h:365
int line_num_2_max_
Definition: FuzzyStringComparator.h:305
InputLine input_line_1_
Definition: FuzzyStringComparator.h:298
std::string input_1_name_
Name of first input e.g., filename.
Definition: FuzzyStringComparator.h:267

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:00 using doxygen 1.8.13