Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
StringDiff.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <compare/DiffAux.h>
10
11#include <ostream>
12
13#include <ext/utility>
14
15#include <alib/vector>
16
17#include "string/CyclicString.h"
18#include "string/LinearString.h"
19
20namespace compare {
21
23private:
24 template < class SymbolType >
25 static void printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, ext::ostream & out );
26
27 template < class SymbolType >
28 static void printDiff ( const string::CyclicString < SymbolType > & a, const string::CyclicString < SymbolType > & b, ext::ostream & out );
29
30public:
31 template<class T>
32 static void diff(const T & a, const T & b, ext::ostream & out );
33
34 template < class T >
35 static std::string diff ( const T & a, const T & b );
36};
37
38template < class SymbolType >
39void StringDiff::printDiff ( const string::CyclicString < SymbolType > &, const string::CyclicString < SymbolType > &, ext::ostream & ) {
40 throw "NYI";
41}
42
43template < class SymbolType >
44void StringDiff::printDiff ( const string::LinearString < SymbolType > & a, const string::LinearString < SymbolType > & b, ext::ostream & out ) {
45 out << "StringsComparer" << std::endl;
46
47 if ( a.getAlphabet ( ) != b.getAlphabet ( ) ) {
48 out << "Alphabet" << std::endl;
49
50 DiffAux::setDiff ( out, a.getAlphabet ( ), b.getAlphabet ( ) );
51 }
52
53 if ( a.getContent ( ) != b.getContent ( ) ) {
54 out << "Content" << std::endl;
55
56 DiffAux::vectorDiff ( out, a.getContent ( ), b.getContent ( ) );
57 }
58}
59
60template < class T >
61void StringDiff::diff ( const T & a, const T & b, ext::ostream & out ) {
62 if ( !StringCompare::compare ( a, b ) ) {
63 StringDiff::printDiff ( a, b, out );
64 }
65}
66
67template < class T >
68std::string StringDiff::diff ( const T & a, const T & b ) {
70 diff ( a, b, ss );
71 return ss.str ( );
72}
73
74} /* namespace compare */
75
static void setDiff(ext::ostream &out, const ext::set< T > &a, const ext::set< T > &b)
Definition: DiffAux.h:33
static void vectorDiff(ext::ostream &out, const ext::vector< T > &a, const ext::vector< T > &b)
Definition: DiffAux.h:50
static bool compare(const string::LinearString< SymbolType > &a, const string::LinearString< SymbolType > &b)
Definition: StringCompare.h:23
Definition: StringDiff.h:22
static void diff(const T &a, const T &b, ext::ostream &out)
Definition: StringDiff.h:61
Definition: ostream.h:14
Definition: sstream.h:15
std::string str() const &
Definition: sstream.cpp:29
Cyclic string.
Definition: CyclicString.h:60
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: AutomatonCompare.h:29