Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
FuzzyStringComparator Class Reference

Fuzzy comparison of strings, tolerates numeric differences. More...

#include <OpenMS/CONCEPT/FuzzyStringComparator.h>

Classes

struct  AbortComparison
 Internal exception class. More...
 
struct  InputLine
 Stores information about the current input line (i.e., stream for the line and the current position in the stream) More...
 
struct  PrefixInfo_
 Wrapper for the prefix information computed for the failure report. More...
 
struct  StreamElement_
 Stores information about characters, numbers, and whitesspaces loaded from the InputStream. More...
 

Public Member Functions

const doublegetAcceptableRelative () const
 Acceptable relative error (a number >= 1.0) More...
 
void setAcceptableRelative (const double rhs)
 Acceptable relative error (a number >= 1.0) More...
 
const doublegetAcceptableAbsolute () const
 Acceptable absolute difference (a number >= 0.0) More...
 
void setAcceptableAbsolute (const double rhs)
 Acceptable absolute difference (a number >= 0.0) More...
 
const StringListgetWhitelist () const
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
StringListgetWhitelist ()
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
void setWhitelist (const StringList &rhs)
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
const int & getVerboseLevel () const
 verbose level More...
 
void setVerboseLevel (const int rhs)
 verbose level More...
 
const int & getTabWidth () const
 get tab width (for column numbers) More...
 
void setTabWidth (const int rhs)
 set tab width (for column numbers) More...
 
const int & getFirstColumn () const
 get first column (for column numbers) More...
 
void setFirstColumn (const int rhs)
 set first column (for column numbers) More...
 
std::ostream & getLogDestination () const
 Log output is written to this destination. More...
 
void setLogDestination (std::ostream &rhs)
 Log output is written to this destination. More...
 
bool compareStrings (std::string const &lhs, std::string const &rhs)
 Compare two strings. More...
 
bool compareStreams (std::istream &input_1, std::istream &input_2)
 Compare two streams of input. More...
 
bool compareFiles (const std::string &filename_1, const std::string &filename_2)
 Simple diff-like application to compare two input files. Numeric differences are tolerated up to a certain ratio or absolute difference. More...
 
the fabulous four
 FuzzyStringComparator ()
 Constructor. More...
 
virtual ~FuzzyStringComparator ()
 Destructor. More...
 
 FuzzyStringComparator (const FuzzyStringComparator &rhs)
 Copy constructor intentionally not implemented. More...
 
FuzzyStringComparatoroperator= (const FuzzyStringComparator &rhs)
 Assignment operator intentionally not implemented. More...
 

Protected Member Functions

bool compareLines_ (std::string const &line_str_1, std::string const &line_str_2)
 Compare two lines of input. More...
 
void reportSuccess_ () const
 Report good news. More...
 
void reportFailure_ (char const *const message) const
 
void writeWhitelistCases_ (const std::string &prefix) const
 Write info about hits in the whitelist. More...
 
void readNextLine_ (std::istream &input_stream, std::string &line_string, int &line_number) const
 
bool openInputFileStream_ (const std::string &filename, std::ifstream &input_stream) const
 opens and checks an input file stream std::ifstream More...
 

Protected Attributes

std::ostream * log_dest_
 Log and results output goes here. More...
 
std::string input_1_name_
 Name of first input e.g., filename. More...
 
std::string input_2_name_
 Name of second input e.g., filename. More...
 
InputLine input_line_1_
 
InputLine input_line_2_
 
int line_num_1_
 
int line_num_2_
 
int line_num_1_max_
 
int line_num_2_max_
 
std::string line_str_1_max_
 
std::string line_str_2_max_
 
double ratio_max_allowed_
 Maximum ratio of numbers allowed, see ratio_max_. More...
 
double ratio_max_
 Maximum ratio of numbers observed so far, see ratio_max_allowed_. More...
 
double absdiff_max_allowed_
 Maximum absolute difference of numbers allowed, see absdiff_max_. More...
 
double absdiff_max_
 Maximum difference of numbers observed so far, see absdiff_max_allowed_. More...
 
StreamElement_ element_1_
 Stores information about characters, numbers, and whitesspaces loaded from the first input stream. More...
 
StreamElement_ element_2_
 Stores information about characters, numbers, and whitesspaces loaded from the second input stream. More...
 
bool is_absdiff_small_
 
int verbose_level_
 
int tab_width_
 
int first_column_
 
bool is_status_success_
 Has comparison been sucessful so far? Note: this flag is changed in reportFailure_();. More...
 
bool use_prefix_
 use a prefix when reporting More...
 
StringList whitelist_
 
std::map< String, UIntwhitelist_cases_
 

Friends

void Internal::ClassTest::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)
 
bool Internal::ClassTest::isFileSimilar (const std::string &, const std::string &)
 

Detailed Description

Fuzzy comparison of strings, tolerates numeric differences.

Constructor & Destructor Documentation

Constructor.

virtual ~FuzzyStringComparator ( )
virtual

Destructor.

Copy constructor intentionally not implemented.

Member Function Documentation

bool compareFiles ( const std::string &  filename_1,
const std::string &  filename_2 
)

Simple diff-like application to compare two input files. Numeric differences are tolerated up to a certain ratio or absolute difference.

where

Parameters
filename_1first input file
filename_2second input file
Returns
true in case of no differences found
See Also
ratio_max_allowed_
absdiff_max_allowed_
verbose_level_
bool compareLines_ ( std::string const &  line_str_1,
std::string const &  line_str_2 
)
protected

Compare two lines of input.

This implements the core functionality. Intended to be used for a single line of input.

returns true (non-zero) in case of success

bool compareStreams ( std::istream &  input_1,
std::istream &  input_2 
)

Compare two streams of input.

This compares all lines of the input. Intended to be used for file streams.

returns true in case of no differences found

bool compareStrings ( std::string const &  lhs,
std::string const &  rhs 
)

Compare two strings.

This compares all lines of the input.

returns true in case of no differences found

const double& getAcceptableAbsolute ( ) const
inline

Acceptable absolute difference (a number >= 0.0)

const double& getAcceptableRelative ( ) const
inline

Acceptable relative error (a number >= 1.0)

const int& getFirstColumn ( ) const
inline

get first column (for column numbers)

std::ostream& getLogDestination ( ) const
inline

Log output is written to this destination.

The default is std::cout. Use std::ostringstream etc. to save the output in a string.

const int& getTabWidth ( ) const
inline

get tab width (for column numbers)

const int& getVerboseLevel ( ) const
inline

verbose level

  • 0 = very quiet mode (absolutely no output)
  • 1 = quiet mode (no output unless differences detected)
  • 2 = default (include summary at end)
  • 3 = continue after errors
const StringList& getWhitelist ( ) const
inline

White list. If both lines contain the same element from this list, they are skipped over.

StringList& getWhitelist ( )
inline

White list. If both lines contain the same element from this list, they are skipped over.

bool openInputFileStream_ ( const std::string &  filename,
std::ifstream &  input_stream 
) const
protected

opens and checks an input file stream std::ifstream

FuzzyStringComparator& operator= ( const FuzzyStringComparator rhs)

Assignment operator intentionally not implemented.

void readNextLine_ ( std::istream &  input_stream,
std::string &  line_string,
int &  line_number 
) const
protected

read the next line in input stream, skipping over empty lines and lines consisting of whitespace only

void reportFailure_ ( char const *const  message) const
protected

Report bad news.

Exceptions
AbortComparison
void reportSuccess_ ( ) const
protected

Report good news.

void setAcceptableAbsolute ( const double  rhs)
inline

Acceptable absolute difference (a number >= 0.0)

void setAcceptableRelative ( const double  rhs)
inline

Acceptable relative error (a number >= 1.0)

void setFirstColumn ( const int  rhs)
inline

set first column (for column numbers)

void setLogDestination ( std::ostream &  rhs)
inline

Log output is written to this destination.

The default is std::cout. Use std::ostringstream etc. to save the output in a string.

There seems to be an issue with this under Windows, see comment in FuzzyStringComparator_test.C

void setTabWidth ( const int  rhs)
inline

set tab width (for column numbers)

void setVerboseLevel ( const int  rhs)
inline

verbose level

  • 0 = very quiet mode (absolutely no output)
  • 1 = quiet mode (no output unless differences detected)
  • 2 = default (include summary at end)
  • 3 = continue after errors
void setWhitelist ( const StringList rhs)
inline

White list. If both lines contain the same element from this list, they are skipped over.

void writeWhitelistCases_ ( const std::string &  prefix) const
protected

Write info about hits in the whitelist.

Friends And Related Function Documentation

bool Internal::ClassTest::isFileSimilar ( const std::string &  ,
const std::string &   
)
friend
void Internal::ClassTest::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 
)
friend

Member Data Documentation

double absdiff_max_
protected

Maximum difference of numbers observed so far, see absdiff_max_allowed_.

double absdiff_max_allowed_
protected

Maximum absolute difference of numbers allowed, see absdiff_max_.

StreamElement_ element_1_
protected

Stores information about characters, numbers, and whitesspaces loaded from the first input stream.

StreamElement_ element_2_
protected

Stores information about characters, numbers, and whitesspaces loaded from the second input stream.

int first_column_
protected
std::string input_1_name_
protected

Name of first input e.g., filename.

std::string input_2_name_
protected

Name of second input e.g., filename.

InputLine input_line_1_
protected
InputLine input_line_2_
protected
bool is_absdiff_small_
protected
bool is_status_success_
protected

Has comparison been sucessful so far? Note: this flag is changed in reportFailure_();.

int line_num_1_
protected
int line_num_1_max_
protected
int line_num_2_
protected
int line_num_2_max_
protected
std::string line_str_1_max_
protected
std::string line_str_2_max_
protected
std::ostream* log_dest_
protected

Log and results output goes here.

double ratio_max_
protected

Maximum ratio of numbers observed so far, see ratio_max_allowed_.

double ratio_max_allowed_
protected

Maximum ratio of numbers allowed, see ratio_max_.

int tab_width_
protected
bool use_prefix_
protected

use a prefix when reporting

int verbose_level_
protected
StringList whitelist_
protected
std::map<String, UInt> whitelist_cases_
protected

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:28 using doxygen 1.8.5