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-2015.
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: Stephan Aiche $
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 
140  const int & getVerboseLevel() const;
141 
150  void setVerboseLevel(const int rhs);
151 
155  const int & getTabWidth() const;
156 
160  void setTabWidth(const int rhs);
161 
165  const int & getFirstColumn() const;
166 
170  void setFirstColumn(const int rhs);
171 
178  std::ostream & getLogDestination() const;
179 
190  void setLogDestination(std::ostream & rhs);
191 
199  bool compareStrings(std::string const & lhs, std::string const & rhs);
200 
209  bool compareStreams(std::istream & input_1, std::istream & input_2);
210 
225  bool compareFiles(const std::string & filename_1,
226  const std::string & filename_2);
227 
228 protected:
229 
238  bool compareLines_(std::string const & line_str_1, std::string const & line_str_2);
239 
241  void reportSuccess_() const;
242 
245  void reportFailure_(char const * const message) const;
246 
248  void writeWhitelistCases_(const std::string & prefix) const;
249 
252  void readNextLine_(std::istream & input_stream, std::string & line_string, int & line_number) const;
253 
255  bool openInputFileStream_(const std::string & filename, std::ifstream & input_stream) const;
256 
258  std::ostream * log_dest_;
259 
261  std::string input_1_name_;
263  std::string input_2_name_;
264 
266  struct InputLine
267  {
268  std::stringstream line_;
269  std::ios::pos_type line_position_;
270 
271  InputLine();
272 
274  void setToString(const std::string & s);
275 
277  void updatePosition();
278 
280  void seekGToSavedPosition();
281 
289  bool ok() const;
290  };
291 
294 
297 
300 
301  std::string line_str_1_max_;
302  std::string line_str_2_max_;
303 
306 
308  double ratio_max_;
309 
312 
314  double absdiff_max_;
315 
318  {
319  double number;
320  unsigned char letter;
321  bool is_number;
322  bool is_space;
323 
324  StreamElement_();
325 
327  void reset();
328 #ifdef OPENMS_HAS_STREAM_EXTRACTION_BUG
329 
338  bool readdigits(InputLine & input_line, std::string & target_buffer, char & c_buffer);
339 
347  bool tryExtractDouble(InputLine & input_line, double & target);
348 #endif
349  void fillFromInputLine(InputLine & input_line);
351  };
352 
357 
359  struct PrefixInfo_
360  {
364 
365  PrefixInfo_(const InputLine & input_line, const int tab_width_, const int first_column_);
366  };
367 
369 
373 
379 
382 
386  std::map<String, UInt> whitelist_cases_;
387 
388  }; // class FuzzyStringComparator
389 
390 } //namespace OpenMS
391 
392 #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:356
int verbose_level_
Definition: FuzzyStringComparator.h:370
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:266
double ratio_max_allowed_
Maximum ratio of numbers allowed, see ratio_max_.
Definition: FuzzyStringComparator.h:305
Stores information about characters, numbers, and white spaces loaded from the InputStream.
Definition: FuzzyStringComparator.h:317
void setWhitelist(const char *const , const int line, const std::string &whitelist)
set the whitelist_
double absdiff_max_
Maximum difference of numbers observed so far, see absdiff_max_allowed_.
Definition: FuzzyStringComparator.h:314
int line_column
Definition: FuzzyStringComparator.h:363
double absdiff_max_allowed_
Maximum absolute difference of numbers allowed, see absdiff_max_.
Definition: FuzzyStringComparator.h:311
OpenMS::String prefix
Definition: FuzzyStringComparator.h:361
bool use_prefix_
use a prefix when reporting
Definition: FuzzyStringComparator.h:381
std::ostream * log_dest_
Log and results output goes here.
Definition: FuzzyStringComparator.h:258
unsigned char letter
Definition: FuzzyStringComparator.h:320
std::ios::pos_type line_position_
Definition: FuzzyStringComparator.h:269
bool is_space
Definition: FuzzyStringComparator.h:322
Fuzzy comparison of strings, tolerates numeric differences.
Definition: FuzzyStringComparator.h:70
std::string line_str_2_max_
Definition: FuzzyStringComparator.h:302
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
int line_num_2_
Definition: FuzzyStringComparator.h:296
std::map< String, UInt > whitelist_cases_
Occurences of whitelist entries.
Definition: FuzzyStringComparator.h:386
bool is_number
Definition: FuzzyStringComparator.h:321
OpenMS::String prefix_whitespaces
Definition: FuzzyStringComparator.h:362
double number
Definition: FuzzyStringComparator.h:319
int first_column_
Definition: FuzzyStringComparator.h:372
int tab_width_
Definition: FuzzyStringComparator.h:371
double ratio_max_
Maximum ratio of numbers observed so far, see ratio_max_allowed_.
Definition: FuzzyStringComparator.h:308
int line_num_1_
Definition: FuzzyStringComparator.h:295
StreamElement_ element_1_
Stores information about characters, numbers, and white spaces loaded from the first input stream...
Definition: FuzzyStringComparator.h:354
StringList whitelist_
Whitelist.
Definition: FuzzyStringComparator.h:384
InputLine input_line_2_
Definition: FuzzyStringComparator.h:293
bool is_status_success_
Has comparison been successful so far? Note: this flag is changed in reportFailure_();.
Definition: FuzzyStringComparator.h:378
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:263
int line_num_1_max_
Definition: FuzzyStringComparator.h:298
std::string line_str_1_max_
Definition: FuzzyStringComparator.h:301
std::stringstream line_
Definition: FuzzyStringComparator.h:268
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:368
Wrapper for the prefix information computed for the failure report.
Definition: FuzzyStringComparator.h:359
int line_num_2_max_
Definition: FuzzyStringComparator.h:299
InputLine input_line_1_
Definition: FuzzyStringComparator.h:292
std::string input_1_name_
Name of first input e.g., filename.
Definition: FuzzyStringComparator.h:261

OpenMS / TOPP release 2.0.0 Documentation generated on Wed Mar 30 2016 12:49:23 using doxygen 1.8.11