Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

FuzzyStringComparator.h (Maintainer: Clemens Groepl)

Go to the documentation of this file.
00001 // -*- mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2007 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Clemens Groepl $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
00028 #define OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
00029 
00030 #include <OpenMS/CONCEPT/Types.h>
00031 #include <OpenMS/DATASTRUCTURES/String.h>
00032 
00033 #include <cstdlib> // for strtod()
00034 #include <fstream>
00035 #include <iostream>
00036 #include <ctype.h> // for isspace()
00037 #include <limits> // for NaN
00038 #include <sstream>
00039 
00040 namespace OpenMS
00041 {
00046   class FuzzyStringComparator
00047   {
00049     struct AbortComparison{};
00050     
00051    public:
00052 
00054 
00055 
00057     FuzzyStringComparator();
00058 
00060     virtual ~FuzzyStringComparator();
00061 
00063     FuzzyStringComparator(const FuzzyStringComparator& rhs);
00064 
00066     FuzzyStringComparator & operator=(const FuzzyStringComparator& rhs);
00067 
00069 
00071     const double & getAcceptableRelative() const
00072     {
00073       return ratio_max_allowed;
00074     }
00075 
00077     void setAcceptableRelative(const double rhs)
00078     {
00079       this->ratio_max_allowed = rhs;
00080       if ( ratio_max_allowed < 1.0 ) ratio_max_allowed = 1/ratio_max_allowed;
00081 
00082     }
00083 
00085     const double & getAcceptableAbsolute() const
00086     {
00087       return absdiff_max_allowed;
00088     }
00089 
00091     void setAcceptableAbsolute(const double rhs)
00092     {
00093       this->absdiff_max_allowed = rhs;
00094       if ( absdiff_max_allowed < 0.0 ) absdiff_max_allowed = -absdiff_max_allowed;
00095     }
00096 
00105     const int & getVerboseLevel() const
00106     {
00107       return verbose_level;
00108     }
00109 
00118     void setVerboseLevel(const int rhs)
00119     {
00120       this->verbose_level = rhs;
00121     }
00122 
00128     std::ostream & getLogDestination() const
00129     {
00130       return *log_dest_;
00131     }
00132 
00138     void setLogDestination(std::ostream & rhs)
00139     {
00140       this->log_dest_ = &rhs;
00141     }
00142 
00149     bool compare_strings( std::string const & lhs, std::string const & rhs );
00150     
00158     bool compare_streams( std::istream & input_1, std::istream & input_2 );
00159     
00173     bool compare_files( const std::string & filename_1, const std::string & filename_2);
00174 
00175    protected:
00176 
00184     bool compare_lines_( std::string const & line_str_1,
00185                          std::string const & line_str_2
00186                        );
00187 
00189     void report_success_() const;
00190 
00192     void report_failure_( char const * const message ) const throw(AbortComparison);
00193 
00195     std::ostream * log_dest_;
00196 
00198     std::string input_1_name;
00200     std::string input_2_name;
00201 
00202     std::stringstream line_1;
00203     std::stringstream line_2;
00204 
00205     std::ios::pos_type line_1_pos;
00206     std::ios::pos_type line_2_pos;
00207 
00209     double ratio_max_allowed;
00210 
00212     double ratio_max;
00213 
00215     double absdiff_max_allowed;
00216 
00218     double absdiff_max;
00219 
00220     double number_1;
00221     char letter_1;
00222     bool is_number_1;
00223     bool is_space_1;
00224 
00225     double number_2;
00226     char letter_2;
00227     bool is_number_2;
00228     bool is_space_2;
00229 
00230     bool is_absdiff_small; 
00231 
00232     int line_num_1;
00233     int line_num_2;
00234 
00235     int line_num_1_max;
00236     int line_num_2_max;
00237 
00238     int verbose_level;
00239     
00243     bool is_status_success;
00244 
00245     std::string line_str_1_max;
00246     std::string line_str_2_max;
00247 
00248   }; // class FuzzyStringComparator
00249 
00250 }//namespace OpenMS
00251 
00252 #endif //OPENMS_CONCEPT_FUZZYSTRINGCOMPARATOR_H
00253 

Generated Tue Apr 1 15:36:34 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1