11 Commits

Author SHA1 Message Date
Tatsuhiko Kubo
ebbde693a5 ci: switch to GitHub Actions. 2021-02-17 23:26:09 +09:00
Tatsuhiko Kubo
b83e617aab Merge pull request #7 from wlawski/custom-storage
Allow saving SES to provided data storage
2020-09-22 13:37:29 +09:00
Wiktor Lawski
ea5975a080 Add strdiff_storage to list of build targets of SCons 2020-09-21 21:25:20 +02:00
Tatsuhiko Kubo
ef50138616 Merge pull request #6 from wlawski/custom-change-printer-example-improvement
Make custom change printer example more mature
2020-09-21 15:35:11 +09:00
Wiktor Lawski
ca3fa6846a Allow saving SES to provided data storage
It is not always efficient (or possible) to use standard output
streams. Moreover, such generated result may be now further
processed.
2020-09-12 19:50:31 +02:00
Wiktor Lawski
afddfbccf6 Make custom change printer example more mature
printers.hpp does not depend anymore on includes or usings order
inside strdiff_cp.cpp file.
2020-09-12 16:47:17 +02:00
Tatsuhiko Kubo
6b030d6397 travis-ci: fixed CI failure. 2019-09-29 23:18:04 +09:00
Tatsuhiko Kubo
1bcddbf879 Merge pull request #4 from jamesjer/master
test: use python 3 compatible print statements.
2019-09-29 23:15:45 +09:00
Jerry James
61c30c7836 test: use python 3 compatible print statements. 2019-09-16 12:13:18 -06:00
Tatsuhiko Kubo
9cf6da7279 doc: fixed link. 2017-07-16 23:33:21 +09:00
Tatsuhiko Kubo
45c54b42d3 doc: adjusted indent. 2017-07-16 23:32:29 +09:00
11 changed files with 166 additions and 68 deletions

30
.github/workflows/cpp.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: C++
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install scons and gtest
run: |
sudo apt-get install -y scons
sudo apt-get install -y cmake scons
wget https://github.com/google/googletest/archive/release-1.8.0.zip
unzip -q release-1.8.0.zip
cd googletest-release-1.8.0
cmake .
make
sudo make install
- name: Build examples
run: |
cd examples
scons
- name: Test
run: |
cd test
scons check

View File

@@ -1,18 +0,0 @@
language: cpp
compiler:
- gcc
- clang
before_script:
- sudo apt-get install -y cmake
- wget https://github.com/google/googletest/archive/release-1.8.0.zip
- unzip -q release-1.8.0.zip
- cd googletest-release-1.8.0
- cmake .
- make
- sudo make install
- cd ..
script:
- cd examples
- scons
- cd ../test
- scons check

View File

@@ -8,30 +8,30 @@
* [Features](#features)
* [Getting started](#getting-started)
* [Compare two strings](#compare-two-strings)
* [Compare two data has arbitrary type](#compare-two-data-has-arbitrary-type)
* [Merge three sequences](#merge-three-sequences)
* [Patch function](#patch-function)
* [Difference as Unified Format](#difference-as-unified-format)
* [Compare large sequences](#compare-large-sequences)
* [Unserious difference](#unserious-difference)
* [Calculate only Edit Distance](#calculate-only-edit-distance)
* [Compare two strings](#compare-two-strings)
* [Compare two data has arbitrary type](#compare-two-data-has-arbitrary-type)
* [Merge three sequences](#merge-three-sequences)
* [Patch function](#patch-function)
* [Difference as Unified Format](#difference-as-unified-format)
* [Compare large sequences](#compare-large-sequences)
* [Unserious difference](#unserious-difference)
* [Calculate only Edit Distance](#calculate-only-edit-distance)
* [Algorithm](#algorithm)
* [Computational complexity](#computational-complexity)
* [Comparison when difference between two sequences is very large](#comparison-when-difference-between-two-sequences-is-very-large)
* [Implementations with various programming languages](#implementations-with-various-programming-languages)
* [Computational complexity](#computational-complexity)
* [Comparison when difference between two sequences is very large](#comparison-when-difference-between-two-sequences-is-very-large)
* [Implementations with various programming languages](#implementations-with-various-programming-languages)
* [Examples](#examples)
* [strdiff](#strdiff)
* [intdiff](#intdiff)
* [unidiff](#unidiff)
* [unistrdiff](#unistrdiff)
* [strdiff3](#strdiff3)
* [intdiff3](#intdiff3)
* [patch](#patch)
* [fpatch](#fpatch)
* [strdiff](#strdiff)
* [intdiff](#intdiff)
* [unidiff](#unidiff)
* [unistrdiff](#unistrdiff)
* [strdiff3](#strdiff3)
* [intdiff3](#intdiff3)
* [patch](#patch)
* [fpatch](#fpatch)
* [Running tests](#running-tests)
* [Building test programs](#building-test-programs)
* [Running test programs](#running-test-programs)
* [Building test programs](#building-test-programs)
* [Running test programs](#running-test-programs)
* [Old commit histories](#old-commit-histories)
* [License](#license)

View File

@@ -340,6 +340,15 @@ namespace dtl {
sesElemVec ses_v = ses.getSequence ();
for_each (ses_v.begin (), ses_v.end(), PT < sesElem, stream > (out));
}
/**
* store difference between A and B as an SES with custom storage
*/
template < typename storedData, template < typename SEET, typename STRT > class ST >
void storeSES(storedData& sd) const {
sesElemVec ses_v = ses.getSequence();
for_each(ses_v.begin(), ses_v.end(), ST < sesElem, storedData >(sd));
}
/**
* print difference between A and B in the Unified Format

View File

@@ -118,6 +118,20 @@ namespace dtl {
private :
stream& out_;
};
/**
* storage class template
*/
template <typename sesElem, typename storedData >
class Storage
{
public:
Storage(storedData& sd) : storedData_(sd) {}
virtual ~Storage() {}
virtual void operator() (const sesElem& se) const = 0;
protected:
storedData& storedData_;
};
/**
* compare class template

View File

@@ -26,17 +26,18 @@ for lib in libs:
conf.Finish()
targets = { 'strdiff' : ['strdiff.cpp', 'common.cpp'], # diff between two string sequences
'intdiff' : ['intdiff.cpp'], # diff between two integer sequences
'unidiff' : ['unidiff.cpp', 'common.cpp'], # unified diff between two files
'unistrdiff' : ['unistrdiff.cpp', 'common.cpp'], # unified diff between two strings
'bdiff' : ['bdiff.cpp', 'common.cpp'], # diff between two byte sequences
'strdiff3' : ['strdiff3.cpp', 'common.cpp'], # three-way string diff program using dtl
'intdiff3' : ['intdiff3.cpp'], # three-way integer diff program using dtl
'patch' : ['patch.cpp', 'common.cpp'], # string patch program using dtl
'fpatch' : ['fpatch.cpp', 'common.cpp'], # file patch program using dtl
'st2ses' : ['st2ses.cpp', 'common.cpp'], # convert SES format file to SES instance
'strdiff_cp' : ['strdiff_cp.cpp', 'common.cpp'], # diff between two string sequences with custom printer
targets = { 'strdiff' : ['strdiff.cpp', 'common.cpp'], # diff between two string sequences
'intdiff' : ['intdiff.cpp'], # diff between two integer sequences
'unidiff' : ['unidiff.cpp', 'common.cpp'], # unified diff between two files
'unistrdiff' : ['unistrdiff.cpp', 'common.cpp'], # unified diff between two strings
'bdiff' : ['bdiff.cpp', 'common.cpp'], # diff between two byte sequences
'strdiff3' : ['strdiff3.cpp', 'common.cpp'], # three-way string diff program using dtl
'intdiff3' : ['intdiff3.cpp'], # three-way integer diff program using dtl
'patch' : ['patch.cpp', 'common.cpp'], # string patch program using dtl
'fpatch' : ['fpatch.cpp', 'common.cpp'], # file patch program using dtl
'st2ses' : ['st2ses.cpp', 'common.cpp'], # convert SES format file to SES instance
'strdiff_cp' : ['strdiff_cp.cpp', 'common.cpp'], # diff between two string sequences with custom printer
'strdiff_storage' : ['strdiff_storage.cpp', 'common.cpp'], # diff between two string sequences with custom storage
}
[ env.Program(target, targets[target]) for target in targets ]

View File

@@ -1,23 +1,25 @@
#ifndef DTL_PRINTERS
#define DTL_PRINTERS
#include <dtl/dtl.hpp>
template <typename sesElem, typename stream = ostream >
class customChangePrinter : public Printer < sesElem, stream >
class customChangePrinter : public dtl::Printer < sesElem, stream >
{
public :
customChangePrinter () : Printer < sesElem, stream > () {}
customChangePrinter (stream& out) : Printer < sesElem, stream > (out) {}
customChangePrinter () : dtl::Printer < sesElem, stream > () {}
customChangePrinter (stream& out) : dtl::Printer < sesElem, stream > (out) {}
~customChangePrinter () {}
void operator() (const sesElem& se) const {
switch (se.second.type) {
case SES_ADD:
this->out_ << "Add: " << se.first << endl;
case dtl::SES_ADD:
this->out_ << "Add: " << se.first << std::endl;
break;
case SES_DELETE:
this->out_ << "Delete: " << se.first << endl;
case dtl::SES_DELETE:
this->out_ << "Delete: " << se.first << std::endl;
break;
case SES_COMMON:
this->out_ << "Common: " << se.first << endl;
case dtl::SES_COMMON:
this->out_ << "Common: " << se.first << std::endl;
break;
}
}

27
examples/storage.hpp Normal file
View File

@@ -0,0 +1,27 @@
#ifndef DTL_STORAGE
#define DTL_STORAGE
#include <dtl/dtl.hpp>
template <typename sesElem, typename storedData >
class CustomStorage : public dtl::Storage < sesElem, storedData >
{
public :
CustomStorage(storedData& sd) : dtl::Storage < sesElem, storedData > (sd) {}
~CustomStorage() {}
void operator() (const sesElem& se) const {
switch (se.second.type) {
case dtl::SES_ADD:
this->storedData_ = this->storedData_ + "Add: " + se.first + "\n";
break;
case dtl::SES_DELETE:
this->storedData_ = this->storedData_ + "Delete: " + se.first + "\n";
break;
case dtl::SES_COMMON:
this->storedData_ = this->storedData_ + "Common: " + se.first + "\n";
break;
}
}
};
#endif // DTL_STORAGE

View File

@@ -1,19 +1,14 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include "printers.hpp"
using namespace std;
using dtl::Diff;
using dtl::SES_ADD;
using dtl::SES_DELETE;
using dtl::SES_COMMON;
using dtl::Printer;
#include "printers.hpp"
int main(int argc, char *argv[]){

View File

@@ -0,0 +1,38 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <iostream>
#include <string>
#include "storage.hpp"
using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;
}
typedef char elem;
typedef string sequence;
sequence A(argv[1]);
sequence B(argv[2]);
Diff< elem, sequence > d(A, B);
d.compose();
// Shortest Edit Script
cout << "SES" << endl;
string result;
d.storeSES < string, CustomStorage > (result);
cout << result;
return 0;
}

View File

@@ -16,13 +16,13 @@ env = Environment(
conf = Configure(env);
if not conf.CheckCXX():
print "c++ compiler is not installed!"
print("c++ compiler is not installed!")
Exit(1)
libs = ['stdc++', 'pthread', 'gtest']
for lib in libs:
if not conf.CheckLib(lib):
print "library " + lib + " not installed!"
print("library " + lib + " not installed!")
Exit(1)
conf.Finish()