Skip to content
Snippets Groups Projects
Commit d69f4972 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

parametrized output stream on compare

parent 10552987
No related branches found
No related tags found
No related merge requests found
...@@ -59,7 +59,7 @@ int main ( int argc, char * * argv ) { ...@@ -59,7 +59,7 @@ int main ( int argc, char * * argv ) {
measurements::end ( ); measurements::end ( );
measurements::start ( "Compare", measurements::Type::MAIN ); measurements::start ( "Compare", measurements::Type::MAIN );
   
res = compare::AutomatonCompare::compare ( automaton1, automaton2 ); res = compare::AutomatonCompare::compare ( automaton1, automaton2, std::cout );
} else if ( alib::XmlDataFactory::first < grammar::Grammar > ( tokens1 ) && alib::XmlDataFactory::first < grammar::Grammar > ( tokens2 ) ) { } else if ( alib::XmlDataFactory::first < grammar::Grammar > ( tokens1 ) && alib::XmlDataFactory::first < grammar::Grammar > ( tokens2 ) ) {
grammar::Grammar grammar1 = alib::XmlDataFactory::fromTokens ( std::move ( tokens1 ) ); grammar::Grammar grammar1 = alib::XmlDataFactory::fromTokens ( std::move ( tokens1 ) );
grammar::Grammar grammar2 = alib::XmlDataFactory::fromTokens ( std::move ( tokens2 ) ); grammar::Grammar grammar2 = alib::XmlDataFactory::fromTokens ( std::move ( tokens2 ) );
...@@ -67,7 +67,7 @@ int main ( int argc, char * * argv ) { ...@@ -67,7 +67,7 @@ int main ( int argc, char * * argv ) {
measurements::end ( ); measurements::end ( );
measurements::start ( "Compare", measurements::Type::MAIN ); measurements::start ( "Compare", measurements::Type::MAIN );
   
res = compare::GrammarCompare::compare ( grammar1, grammar2 ); res = compare::GrammarCompare::compare ( grammar1, grammar2, std::cout );
} else if ( alib::XmlDataFactory::first < string::String > ( tokens1 ) && alib::XmlDataFactory::first < string::String > ( tokens2 ) ) { } else if ( alib::XmlDataFactory::first < string::String > ( tokens1 ) && alib::XmlDataFactory::first < string::String > ( tokens2 ) ) {
string::String string1 = alib::XmlDataFactory::fromTokens ( std::move ( tokens1 ) ); string::String string1 = alib::XmlDataFactory::fromTokens ( std::move ( tokens1 ) );
string::String string2 = alib::XmlDataFactory::fromTokens ( std::move ( tokens2 ) ); string::String string2 = alib::XmlDataFactory::fromTokens ( std::move ( tokens2 ) );
...@@ -75,7 +75,7 @@ int main ( int argc, char * * argv ) { ...@@ -75,7 +75,7 @@ int main ( int argc, char * * argv ) {
measurements::end ( ); measurements::end ( );
measurements::start ( "Compare", measurements::Type::MAIN ); measurements::start ( "Compare", measurements::Type::MAIN );
   
res = compare::StringCompare::compare ( string1, string2 ); res = compare::StringCompare::compare ( string1, string2, std::cout );
} else { } else {
throw exception::CommonException ( "Only automata, grammars and strings can be compared." ); throw exception::CommonException ( "Only automata, grammars and strings can be compared." );
} }
......
...@@ -33,8 +33,8 @@ auto AutomatonCompareSinglePopNPDA = registration::OverloadRegister < AutomatonC ...@@ -33,8 +33,8 @@ auto AutomatonCompareSinglePopNPDA = registration::OverloadRegister < AutomatonC
   
auto AutomatonCompareOneTapeDTM = registration::OverloadRegister < AutomatonCompare, int, automaton::OneTapeDTM < >, automaton::OneTapeDTM < > > ( AutomatonCompare::compare ); auto AutomatonCompareOneTapeDTM = registration::OverloadRegister < AutomatonCompare, int, automaton::OneTapeDTM < >, automaton::OneTapeDTM < > > ( AutomatonCompare::compare );
   
int AutomatonCompare::compare(const automaton::Automaton& a, const automaton::Automaton& b) { int AutomatonCompare::compare(const automaton::Automaton& a, const automaton::Automaton& b, std::ostream & out ) {
return dispatch(a.getData(), b.getData()); return dispatch(a.getData(), b.getData(), out);
} }
   
} /* namespace compare */ } /* namespace compare */
This diff is collapsed.
...@@ -27,8 +27,8 @@ auto GrammarCompareContextPreservingUnrestrictedGrammar = registration::Overload ...@@ -27,8 +27,8 @@ auto GrammarCompareContextPreservingUnrestrictedGrammar = registration::Overload
   
auto GrammarCompareUnrestrictedGrammar = registration::OverloadRegister < GrammarCompare, int, grammar::UnrestrictedGrammar < >, grammar::UnrestrictedGrammar < > > ( GrammarCompare::compare ); auto GrammarCompareUnrestrictedGrammar = registration::OverloadRegister < GrammarCompare, int, grammar::UnrestrictedGrammar < >, grammar::UnrestrictedGrammar < > > ( GrammarCompare::compare );
   
int GrammarCompare::compare(const grammar::Grammar& a, const grammar::Grammar& b) { int GrammarCompare::compare(const grammar::Grammar& a, const grammar::Grammar& b, std::ostream & out ) {
return dispatch(a.getData(), b.getData()); return dispatch(a.getData(), b.getData(), out);
} }
   
} /* namespace compare */ } /* namespace compare */
This diff is collapsed.
...@@ -13,8 +13,8 @@ namespace compare { ...@@ -13,8 +13,8 @@ namespace compare {
auto StringCompareLinear = registration::OverloadRegister < StringCompare, int, string::LinearString < >, string::LinearString < > > ( StringCompare::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 StringCompareCyclic = registration::OverloadRegister < StringCompare, int, string::CyclicString < >, string::CyclicString < > > ( StringCompare::compare );
   
int StringCompare::compare ( const string::String & a, const string::String & b ) { int StringCompare::compare ( const string::String & a, const string::String & b, std::ostream & out ) {
return dispatch ( a.getData ( ), b.getData ( ) ); return dispatch ( a.getData ( ), b.getData ( ), out );
} }
   
} /* namespace compare */ } /* namespace compare */
...@@ -23,23 +23,23 @@ ...@@ -23,23 +23,23 @@
   
namespace compare { namespace compare {
   
class StringCompare : public alib::DoubleDispatch < StringCompare, int, const string::StringBase &, const string::StringBase & > { class StringCompare : public alib::MultipleDispatch < StringCompare, int, ext::tuple < >, ext::tuple < const string::StringBase &, const string::StringBase & >, ext::tuple < std::ostream & > > {
private: private:
template < class SymbolType > template < class SymbolType >
static bool testCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ); static bool testCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b );
template < class SymbolType > template < class SymbolType >
static void printCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ); static void printCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out );
   
template < class SymbolType > template < class SymbolType >
static bool testCompare ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b ); static bool testCompare ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b );
template < class SymbolType > template < class SymbolType >
static void printCompare ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b ); static void printCompare ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b, std::ostream & out );
   
public: public:
template < class T > template < class T >
static int compare ( const T & a, const T & b ); static int compare ( const T & a, const T & b, std::ostream & out );
   
static int compare ( const string::String & a, const string::String & b ); static int compare ( const string::String & a, const string::String & b, std::ostream & out );
}; };
   
template < class SymbolType > template < class SymbolType >
...@@ -54,31 +54,31 @@ bool StringCompare::testCompare ( const string::CyclicString < SymbolType > &, c ...@@ -54,31 +54,31 @@ bool StringCompare::testCompare ( const string::CyclicString < SymbolType > &, c
} }
   
template < class SymbolType > template < class SymbolType >
void StringCompare::printCompare ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > & ) { void StringCompare::printCompare ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > &, std::ostream & ) {
throw "NYI"; throw "NYI";
} }
   
template < class SymbolType > template < class SymbolType >
void StringCompare::printCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b ) { void StringCompare::printCompare ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, std::ostream & out ) {
std::cout << "StringCompare" << std::endl; out << "StringCompare" << std::endl;
   
if ( a.getAlphabet ( ) != b.getAlphabet ( ) ) { if ( a.getAlphabet ( ) != b.getAlphabet ( ) ) {
std::cout << "Alphabet" << std::endl; out << "Alphabet" << std::endl;
   
AuxCompare::setCompare ( a.getAlphabet ( ), b.getAlphabet ( ) ); AuxCompare::setCompare ( a.getAlphabet ( ), b.getAlphabet ( ) );
} }
   
if ( a.getContent ( ) != b.getContent ( ) ) { if ( a.getContent ( ) != b.getContent ( ) ) {
std::cout << "Content" << std::endl; out << "Content" << std::endl;
   
AuxCompare::vectorCompare ( a.getContent ( ), b.getContent ( ) ); AuxCompare::vectorCompare ( a.getContent ( ), b.getContent ( ) );
} }
} }
   
template < class T > template < class T >
int StringCompare::compare ( const T & a, const T & b ) { int StringCompare::compare ( const T & a, const T & b, std::ostream & out ) {
if ( !StringCompare::testCompare ( a, b ) ) { if ( !StringCompare::testCompare ( a, b ) ) {
StringCompare::printCompare ( a, b ); StringCompare::printCompare ( a, b, out );
return 1; return 1;
} else { } else {
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment