diff --git a/acompare2/src/acompare.cpp b/acompare2/src/acompare.cpp index 99de76702e8b9b4c69e3df1e3a0770458ee89729..a2a6a1b8edfc9360e49671fb64b6a993d128cfc3 100644 --- a/acompare2/src/acompare.cpp +++ b/acompare2/src/acompare.cpp @@ -15,7 +15,7 @@ #include <compare/AutomatonDiff.h> #include <compare/GrammarDiff.h> -#include <compare/StringCompare.h> +#include <compare/StringDiff.h> int main ( int argc, char * * argv ) { try { @@ -75,7 +75,7 @@ int main ( int argc, char * * argv ) { measurements::end ( ); measurements::start ( "Compare", measurements::Type::MAIN ); - res = compare::StringCompare::compare ( string1, string2, std::cout ); + res = compare::StringDiff::diff ( string1, string2, std::cout ); } else { throw exception::CommonException ( "Only automata, grammars and strings can be compared." ); } diff --git a/alib2aux/src/compare/StringCompare.cpp b/alib2aux/src/compare/StringCompare.cpp index ab1226a913cc9ff12a83348f95675fed17a34d84..d4603b6dd0f3ca2dbe203ff5fcfb848589594699 100644 --- a/alib2aux/src/compare/StringCompare.cpp +++ b/alib2aux/src/compare/StringCompare.cpp @@ -10,11 +10,11 @@ namespace compare { -auto StringCompareLinear = registration::OverloadRegister < StringCompare, int, string::LinearString < >, string::LinearString < > > ( StringCompare::compare ); -auto StringCompareCyclic = registration::OverloadRegister < StringCompare, int, string::CyclicString < >, string::CyclicString < > > ( StringCompare::compare ); +auto StringCompareLinear = registration::OverloadRegister < StringCompare, bool, string::LinearString < >, string::LinearString < > > ( StringCompare::compare ); +auto StringCompareCyclic = registration::OverloadRegister < StringCompare, bool, string::CyclicString < >, string::CyclicString < > > ( StringCompare::compare ); -int StringCompare::compare ( const string::String & a, const string::String & b, std::ostream & out ) { - return dispatch ( a.getData ( ), b.getData ( ), out ); +bool StringCompare::compare ( const string::String & a, const string::String & b ) { + return dispatch ( a.getData ( ), b.getData ( ) ); } } /* namespace compare */ diff --git a/alib2aux/src/compare/StringCompare.h b/alib2aux/src/compare/StringCompare.h index 0de4ec9afd537770fa755e3862f511f7ecf36b21..ccd5a7d095f589339ce3cd6145fa5acb60454853 100644 --- a/alib2aux/src/compare/StringCompare.h +++ b/alib2aux/src/compare/StringCompare.h @@ -10,81 +10,35 @@ #include <core/multipleDispatch.hpp> -#include <compare/DiffAux.h> - #include <string/String.h> #include <string/StringFeatures.h> -#include <utility> -#include <vector> -#include <ostream> - #include "string/CyclicString.h" #include "string/LinearString.h" namespace compare { -class StringCompare : public alib::MultipleDispatch < StringCompare, int, ext::tuple < >, ext::tuple < const string::StringBase &, const string::StringBase & >, ext::tuple < std::ostream & > > { -private: - template < class SymbolType > - static bool testDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ); +class StringCompare : public alib::MultipleDispatch < StringCompare, bool, ext::tuple < >, ext::tuple < const string::StringBase &, const string::StringBase & >, ext::tuple < > > { +public: template < class SymbolType > - static void printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out ); + static bool compare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ); template < class SymbolType > - static bool testDiff ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b ); - template < class SymbolType > - static void printDiff ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b, std::ostream & out ); + static bool compare ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b ); -public: - template < class T > - static int compare ( const T & a, const T & b, std::ostream & out ); - - static int compare ( const string::String & a, const string::String & b, std::ostream & out ); + static bool compare ( const string::String & a, const string::String & b ); }; template < class SymbolType > -bool StringCompare::testDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ) { +bool StringCompare::compare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ) { return a.getAlphabet ( ) == b.getAlphabet ( ) && a.getContent ( ) == b.getContent ( ) ; } template < class SymbolType > -bool StringCompare::testDiff ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > & ) { - throw "NYI"; -} - -template < class SymbolType > -void StringCompare::printDiff ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > &, std::ostream & ) { +bool StringCompare::compare ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > & ) { throw "NYI"; } -template < class SymbolType > -void StringCompare::printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out ) { - out << "StringsComparer" << std::endl; - - if ( a.getAlphabet ( ) != b.getAlphabet ( ) ) { - out << "Alphabet" << std::endl; - - DiffAux::setDiff ( a.getAlphabet ( ), b.getAlphabet ( ) ); - } - - if ( a.getContent ( ) != b.getContent ( ) ) { - out << "Content" << std::endl; - - DiffAux::vectorDiff ( a.getContent ( ), b.getContent ( ) ); - } -} - -template < class T > -int StringCompare::compare ( const T & a, const T & b, std::ostream & out ) { - if ( !StringCompare::testDiff ( a, b ) ) { - StringCompare::printDiff ( a, b, out ); - return 1; - } else { - return 0; - } -} - } /* namespace compare */ -#endif /* GRAMMAR_COMPARE_H_ */ +#endif /* STRING_COMPARE_H_ */ diff --git a/alib2aux/src/compare/StringDiff.cpp b/alib2aux/src/compare/StringDiff.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4e0464583dc18f86cc3d4bfb8e78358ee5340ea --- /dev/null +++ b/alib2aux/src/compare/StringDiff.cpp @@ -0,0 +1,20 @@ +/* + * StringDiff.cpp + * + * Created on: Apr 4, 2017 + * Author: Tomas Pecka + */ + +#include "StringDiff.h" +#include <registration/AlgoRegistration.hpp> + +namespace compare { + +auto StringDiffLinear = registration::OverloadRegister < StringDiff, int, string::LinearString < >, string::LinearString < > > ( StringDiff::diff ); +auto StringDiffCyclic = registration::OverloadRegister < StringDiff, int, string::CyclicString < >, string::CyclicString < > > ( StringDiff::diff ); + +int StringDiff::diff ( const string::String & a, const string::String & b, std::ostream & out ) { + return dispatch ( a.getData ( ), b.getData ( ), out ); +} + +} /* namespace compare */ diff --git a/alib2aux/src/compare/StringDiff.h b/alib2aux/src/compare/StringDiff.h new file mode 100644 index 0000000000000000000000000000000000000000..883f9cfc8a64f3fdb0af828bebee380b0c0c42c2 --- /dev/null +++ b/alib2aux/src/compare/StringDiff.h @@ -0,0 +1,76 @@ +/* + * StringDiff.h + * + * Created on: Apr 4, 2017 + * Author: Tomas Pecka + */ + +#ifndef STRING_DIFF_H_ +#define STRING_DIFF_H_ + +#include <core/multipleDispatch.hpp> + +#include <compare/DiffAux.h> +#include <compare/StringCompare.h> + +#include <string/String.h> +#include <string/StringFeatures.h> +#include <utility> +#include <vector> +#include <ostream> + +#include "string/CyclicString.h" +#include "string/LinearString.h" + +namespace compare { + +class StringDiff : public alib::MultipleDispatch < StringDiff, int, ext::tuple < >, ext::tuple < const string::StringBase &, const string::StringBase & >, ext::tuple < std::ostream & > > { +private: + template < class SymbolType > + static void printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out ); + + template < class SymbolType > + static void printDiff ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b, std::ostream & out ); + +public: + template < class T > + static int diff ( const T & a, const T & b, std::ostream & out ); + + static int diff ( const string::String & a, const string::String & b, std::ostream & out ); +}; + +template < class SymbolType > +void StringDiff::printDiff ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > &, std::ostream & ) { + throw "NYI"; +} + +template < class SymbolType > +void StringDiff::printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out ) { + out << "StringsComparer" << std::endl; + + if ( a.getAlphabet ( ) != b.getAlphabet ( ) ) { + out << "Alphabet" << std::endl; + + DiffAux::setDiff ( a.getAlphabet ( ), b.getAlphabet ( ) ); + } + + if ( a.getContent ( ) != b.getContent ( ) ) { + out << "Content" << std::endl; + + DiffAux::vectorDiff ( a.getContent ( ), b.getContent ( ) ); + } +} + +template < class T > +int StringDiff::diff ( const T & a, const T & b, std::ostream & out ) { + if ( !StringCompare::compare ( a, b ) ) { + StringDiff::printDiff ( a, b, out ); + return 1; + } else { + return 0; + } +} + +} /* namespace compare */ + +#endif /* STRING_DIFF_H_ */