From 087f132a32511546ea277e43ed6a267ef3631d0f Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 3 Jun 2024 09:59:35 -0500 Subject: [PATCH] move to cmake --- .cspell/words.txt | 11 ++ .gitignore | 47 +++++---- CMakeLists.txt | 24 +++++ ChangeLog | 8 +- SConstruct | 7 -- compile_commands.json | 188 +++++++++++++++++++++++++++++++++ examples/CMakeLists.txt | 107 +++++++++++++++++++ examples/SConstruct | 43 -------- examples/bdiff.cpp | 31 ++---- examples/common.cpp | 3 +- examples/common.hpp | 8 +- examples/fpatch.cpp | 33 +++--- examples/intdiff.cpp | 27 ++--- examples/intdiff3.cpp | 38 +++---- examples/patch.cpp | 23 ++-- examples/printers.hpp | 4 +- examples/st2ses.cpp | 22 ++-- examples/storage.hpp | 2 +- examples/strdiff.cpp | 19 ++-- examples/strdiff3.cpp | 15 +-- examples/strdiff_cp.cpp | 14 +-- examples/strdiff_storage.cpp | 17 ++- examples/unidiff.cpp | 47 ++++----- examples/unistrdiff.cpp | 16 +-- {dtl => include}/Diff.hpp | 29 +++-- {dtl => include}/Diff3.hpp | 4 +- {dtl => include}/Lcs.hpp | 3 + {dtl => include}/Sequence.hpp | 2 +- {dtl => include}/Ses.hpp | 5 +- {dtl => include}/dtl.hpp | 18 ++++ {dtl => include}/functors.hpp | 10 +- {dtl => include}/variables.hpp | 6 -- test/CMakeLists.txt | 20 ++++ test/Objdifftest.cpp | 3 +- test/SConstruct | 40 ------- test/Strdiff3test.cpp | 3 +- test/Strdifftest.cpp | 3 +- test/comparators.hpp | 8 +- test/dtl_test.cpp | 6 +- test/dtl_test_common.cpp | 1 - test/dtl_test_common.hpp | 10 +- 41 files changed, 558 insertions(+), 367 deletions(-) create mode 100644 .cspell/words.txt create mode 100644 CMakeLists.txt delete mode 100644 SConstruct create mode 100644 compile_commands.json create mode 100644 examples/CMakeLists.txt delete mode 100644 examples/SConstruct rename {dtl => include}/Diff.hpp (96%) rename {dtl => include}/Diff3.hpp (98%) rename {dtl => include}/Lcs.hpp (97%) rename {dtl => include}/Sequence.hpp (98%) rename {dtl => include}/Ses.hpp (97%) rename {dtl => include}/dtl.hpp (85%) rename {dtl => include}/functors.hpp (94%) rename {dtl => include}/variables.hpp (97%) create mode 100644 test/CMakeLists.txt delete mode 100644 test/SConstruct diff --git a/.cspell/words.txt b/.cspell/words.txt new file mode 100644 index 0000000..f93a3b0 --- /dev/null +++ b/.cspell/words.txt @@ -0,0 +1,11 @@ +bdiff +cmake_current_source_dir +fpatch +intdiff +intdifftest +kubo +st2ses +strdiff +tatsuhiko +unidiff +unistrdiff diff --git a/.gitignore b/.gitignore index 71353d4..c8d19a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,35 @@ -examples/unidiff -examples/unistrdiff -examples/strdiff -examples/strdiff_cp -examples/strdiff3 -examples/intdiff -examples/bdiff -examples/intdiff3 -examples/patch -examples/fpatch -examples/st2ses -examples/strdiff_storage -test/strdiff3_test -test/*/*/*_ *.o *.orig -*~ -.semantic.cache -.DS_Store *.swp +*~ +.DS_Store +.cache/ +.sconf_temp +.sconsign.dblite +.semantic.cache GPATH GRTAGS GSYMS GTAGS TAGS -dtl_test -.sconsign.dblite -.sconf_temp -config.log -^\# \#$ \.\# +^\# +build/ +config.log +cspell.json +dtl_test +examples/bdiff +examples/fpatch +examples/intdiff +examples/intdiff3 +examples/patch +examples/st2ses +examples/strdiff +examples/strdiff3 +examples/strdiff_cp +examples/strdiff_storage +examples/unidiff +examples/unistrdiff +test/*/*/*_ +test/strdiff3_test diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8a1c48f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.20) +cmake_policy(SET CMP0048 NEW) + +project( + dtl + VERSION 1.21 +) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include) + +option(DTL_ENABLE_TESTING "Enable DTL unit tests" OFF) +if(DTL_ENABLE_TESTING) + include(test/CMakeLists.txt) +endif() + +option(DTL_ENABLE_EXAMPLES "Enable DTL examples" OFF) +if(DTL_ENABLE_EXAMPLES) + include(examples/CMakeLists.txt) +endif() diff --git a/ChangeLog b/ChangeLog index f9f1d97..d3a5ed0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,12 @@ -2024-06-03 Scott E. Graves +2024-06-03 Scott E. Graves - * bugfix pr's: fixed compilation issues with GCC 14 + * pr: fixed compilation issues * https://github.com/cubicdaiya/dtl/pull/22 * https://github.com/cubicdaiya/dtl/pull/18 - * pr: initialize variables to prevent warnings + * pr: initialize variables * https://github.com/cubicdaiya/dtl/pull/16 + * move to CMake build system + * added clang-format and clang-tidy * 1.21 released diff --git a/SConstruct b/SConstruct deleted file mode 100644 index 3e0b29e..0000000 --- a/SConstruct +++ /dev/null @@ -1,7 +0,0 @@ -import os - -# install script - -prefix = ARGUMENTS.get('prefix', '/usr/local') -headers = Glob('dtl/*.hpp') -Alias('install', Install(os.path.join(prefix, 'dtl', 'include'), headers)) diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..53c1865 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,188 @@ +[ +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/Intdifftest.cpp.obj -c C:/src/dtl/test/Intdifftest.cpp", + "file": "C:/src/dtl/test/Intdifftest.cpp", + "output": "CMakeFiles/dtl_test.dir/test/Intdifftest.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/Objdifftest.cpp.obj -c C:/src/dtl/test/Objdifftest.cpp", + "file": "C:/src/dtl/test/Objdifftest.cpp", + "output": "CMakeFiles/dtl_test.dir/test/Objdifftest.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/Patchtest.cpp.obj -c C:/src/dtl/test/Patchtest.cpp", + "file": "C:/src/dtl/test/Patchtest.cpp", + "output": "CMakeFiles/dtl_test.dir/test/Patchtest.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/Strdiff3test.cpp.obj -c C:/src/dtl/test/Strdiff3test.cpp", + "file": "C:/src/dtl/test/Strdiff3test.cpp", + "output": "CMakeFiles/dtl_test.dir/test/Strdiff3test.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/Strdifftest.cpp.obj -c C:/src/dtl/test/Strdifftest.cpp", + "file": "C:/src/dtl/test/Strdifftest.cpp", + "output": "CMakeFiles/dtl_test.dir/test/Strdifftest.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/dtl_test.cpp.obj -c C:/src/dtl/test/dtl_test.cpp", + "file": "C:/src/dtl/test/dtl_test.cpp", + "output": "CMakeFiles/dtl_test.dir/test/dtl_test.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe -DGTEST_LINKED_AS_SHARED_LIBRARY=1 @CMakeFiles/dtl_test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles/dtl_test.dir/test/dtl_test_common.cpp.obj -c C:/src/dtl/test/dtl_test_common.cpp", + "file": "C:/src/dtl/test/dtl_test_common.cpp", + "output": "CMakeFiles/dtl_test.dir/test/dtl_test_common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/bdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/bdiff.dir/examples/bdiff.cpp.obj -c C:/src/dtl/examples/bdiff.cpp", + "file": "C:/src/dtl/examples/bdiff.cpp", + "output": "CMakeFiles/bdiff.dir/examples/bdiff.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/bdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/bdiff.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/bdiff.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/fpatch.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/fpatch.dir/examples/fpatch.cpp.obj -c C:/src/dtl/examples/fpatch.cpp", + "file": "C:/src/dtl/examples/fpatch.cpp", + "output": "CMakeFiles/fpatch.dir/examples/fpatch.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/fpatch.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/fpatch.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/fpatch.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/intdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/intdiff.dir/examples/intdiff.cpp.obj -c C:/src/dtl/examples/intdiff.cpp", + "file": "C:/src/dtl/examples/intdiff.cpp", + "output": "CMakeFiles/intdiff.dir/examples/intdiff.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/intdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/intdiff.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/intdiff.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/intdiff3.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/intdiff3.dir/examples/intdiff3.cpp.obj -c C:/src/dtl/examples/intdiff3.cpp", + "file": "C:/src/dtl/examples/intdiff3.cpp", + "output": "CMakeFiles/intdiff3.dir/examples/intdiff3.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/intdiff3.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/intdiff3.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/intdiff3.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/patch.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/patch.dir/examples/patch.cpp.obj -c C:/src/dtl/examples/patch.cpp", + "file": "C:/src/dtl/examples/patch.cpp", + "output": "CMakeFiles/patch.dir/examples/patch.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/patch.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/patch.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/patch.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/st2ses.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/st2ses.dir/examples/st2ses.cpp.obj -c C:/src/dtl/examples/st2ses.cpp", + "file": "C:/src/dtl/examples/st2ses.cpp", + "output": "CMakeFiles/st2ses.dir/examples/st2ses.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/st2ses.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/st2ses.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/st2ses.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff.dir/examples/strdiff.cpp.obj -c C:/src/dtl/examples/strdiff.cpp", + "file": "C:/src/dtl/examples/strdiff.cpp", + "output": "CMakeFiles/strdiff.dir/examples/strdiff.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/strdiff.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff3.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff3.dir/examples/strdiff3.cpp.obj -c C:/src/dtl/examples/strdiff3.cpp", + "file": "C:/src/dtl/examples/strdiff3.cpp", + "output": "CMakeFiles/strdiff3.dir/examples/strdiff3.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff3.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff3.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/strdiff3.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff_cp.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff_cp.dir/examples/strdiff_cp.cpp.obj -c C:/src/dtl/examples/strdiff_cp.cpp", + "file": "C:/src/dtl/examples/strdiff_cp.cpp", + "output": "CMakeFiles/strdiff_cp.dir/examples/strdiff_cp.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff_cp.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff_cp.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/strdiff_cp.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff_storage.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff_storage.dir/examples/strdiff_storage.cpp.obj -c C:/src/dtl/examples/strdiff_storage.cpp", + "file": "C:/src/dtl/examples/strdiff_storage.cpp", + "output": "CMakeFiles/strdiff_storage.dir/examples/strdiff_storage.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/strdiff_storage.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/strdiff_storage.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/strdiff_storage.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/unidiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/unidiff.dir/examples/unidiff.cpp.obj -c C:/src/dtl/examples/unidiff.cpp", + "file": "C:/src/dtl/examples/unidiff.cpp", + "output": "CMakeFiles/unidiff.dir/examples/unidiff.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/unidiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/unidiff.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/unidiff.dir/examples/common.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/unistrdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/unistrdiff.dir/examples/unistrdiff.cpp.obj -c C:/src/dtl/examples/unistrdiff.cpp", + "file": "C:/src/dtl/examples/unistrdiff.cpp", + "output": "CMakeFiles/unistrdiff.dir/examples/unistrdiff.cpp.obj" +}, +{ + "directory": "C:/src/dtl/build", + "command": "C:/Users/sgra3018/scoop/apps/msys2/2024-05-07/mingw64/bin/c++.exe @CMakeFiles/unistrdiff.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/unistrdiff.dir/examples/common.cpp.obj -c C:/src/dtl/examples/common.cpp", + "file": "C:/src/dtl/examples/common.cpp", + "output": "CMakeFiles/unistrdiff.dir/examples/common.cpp.obj" +} +] \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..4a2da0e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,107 @@ +add_executable(bdiff + examples/bdiff.cpp + examples/common.cpp +) + +target_include_directories(bdiff BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(fpatch + examples/fpatch.cpp + examples/common.cpp +) + +target_include_directories(fpatch BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(intdiff + examples/intdiff.cpp + examples/common.cpp +) + +target_include_directories(intdiff BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(intdiff3 + examples/intdiff3.cpp + examples/common.cpp +) + +target_include_directories(intdiff3 BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(patch + examples/patch.cpp + examples/common.cpp +) + +target_include_directories(patch BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(st2ses + examples/st2ses.cpp + examples/common.cpp +) + +target_include_directories(st2ses BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(strdiff + examples/strdiff.cpp + examples/common.cpp +) + +target_include_directories(strdiff BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(strdiff3 + examples/strdiff3.cpp + examples/common.cpp +) + +target_include_directories(strdiff3 BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(strdiff_cp + examples/strdiff_cp.cpp + examples/common.cpp +) + +target_include_directories(strdiff_cp BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(strdiff_storage + examples/strdiff_storage.cpp + examples/common.cpp +) + +target_include_directories(strdiff_storage BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(unidiff + examples/unidiff.cpp + examples/common.cpp +) + +target_include_directories(unidiff BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) + +add_executable(unistrdiff + examples/unistrdiff.cpp + examples/common.cpp +) + +target_include_directories(unistrdiff BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/examples +) diff --git a/examples/SConstruct b/examples/SConstruct deleted file mode 100644 index c0c720e..0000000 --- a/examples/SConstruct +++ /dev/null @@ -1,43 +0,0 @@ -import os - -# SConstruct for dtl examples - -env = Environment(CPPPATH='..') -debug = ARGUMENTS.get('debug', 'n') -if debug == 'y' or debug == 'yes': - env.Append(CPPFLAGS = ['-Wall', '-g']) -else: - env.Append(CPPFLAGS = ['-Wall', '-O2']) - -if os.sys.platform != "win32": - env.Append(CPPDEFINES = ['HAVE_UNISTD_H']) - -conf = Configure(env); - -if not conf.CheckCXX(): - print("The C++ compiler is not installed!") - Exit(1) - -libs = ['stdc++'] -for lib in libs: - if not conf.CheckLib(lib): - print("library " + lib + " not installed!") - Exit(1) - -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 - 'strdiff_storage' : ['strdiff_storage.cpp', 'common.cpp'], # diff between two string sequences with custom storage - } - -[ env.Program(target, targets[target]) for target in targets ] diff --git a/examples/bdiff.cpp b/examples/bdiff.cpp index 638b930..1e8d1cd 100644 --- a/examples/bdiff.cpp +++ b/examples/bdiff.cpp @@ -1,24 +1,9 @@ - #include "common.hpp" -#include - -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif // HAVE_UNISTD_H - -using namespace std; using dtl::Diff; typedef unsigned char elem; -typedef vector sequence; +typedef std::vector sequence; static int create_byte_seq(const char *fs, sequence &seq); static int create_byte_seq(const char *fs, sequence &seq) { @@ -26,7 +11,7 @@ static int create_byte_seq(const char *fs, sequence &seq) { int siz; elem buf[BUFSIZ]; if ((fd = open(fs, O_RDONLY)) == -1) { - cout << "Opening failed." << endl; + std::cout << "Opening failed." << std::endl; return -1; } while ((siz = read(fd, buf, sizeof(buf))) > 0) { @@ -36,7 +21,7 @@ static int create_byte_seq(const char *fs, sequence &seq) { } if (siz < 0) { close(fd); - cout << "Read error." << endl; + std::cout << "Read error." << std::endl; return -1; } close(fd); @@ -46,12 +31,12 @@ static int create_byte_seq(const char *fs, sequence &seq) { int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } - string fs1(argv[1]); - string fs2(argv[2]); + std::string fs1(argv[1]); + std::string fs2(argv[2]); sequence seq1; sequence seq2; @@ -62,9 +47,9 @@ int main(int argc, char *argv[]) { d.compose(); if (d.getEditDistance() == 0) { - cout << fs1 << " is the same as " << fs2 << endl; + std::cout << fs1 << " is the same as " << fs2 << std::endl; } else { - cout << fs1 << " is different from " << fs2 << endl; + std::cout << fs1 << " is different from " << fs2 << std::endl; } return 0; diff --git a/examples/common.cpp b/examples/common.cpp index 4cf47d5..5c0117d 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -1,7 +1,6 @@ - #include "common.hpp" -bool isFileExist(string &fs) { +bool isFileExist(std::string &fs) { FILE *fp; if ((fp = fopen(fs.c_str(), "r")) == NULL) { return false; diff --git a/examples/common.hpp b/examples/common.hpp index 56fb9f2..b0875f3 100644 --- a/examples/common.hpp +++ b/examples/common.hpp @@ -1,13 +1,9 @@ - #ifndef DTL_EXAMPLE_COMMON_H #define DTL_EXAMPLE_COMMON_H -#include -#include +#include "dtl.hpp" -using namespace std; - -bool isFileExist(string &fs); +bool isFileExist(std::string &fs); bool isFewArgs(int argc, int limit = 3); #endif diff --git a/examples/fpatch.cpp b/examples/fpatch.cpp index a5b7a41..97c771d 100644 --- a/examples/fpatch.cpp +++ b/examples/fpatch.cpp @@ -1,34 +1,25 @@ - #include "common.hpp" -#include -#include -#include -#include -#include -#include - -using namespace std; using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } - string A(argv[1]); - string B(argv[2]); + std::string A(argv[1]); + std::string B(argv[2]); bool fileExist = true; if (!isFileExist(A)) { - cerr << "file A does not exist" << endl; + std::cerr << "file A does not exist" << std::endl; fileExist = false; } if (!isFileExist(B)) { - cerr << "file B does not exist" << endl; + std::cerr << "file B does not exist" << std::endl; fileExist = false; } @@ -36,14 +27,14 @@ int main(int argc, char *argv[]) { return -1; } - typedef string elem; - typedef vector sequence; + typedef std::string elem; + typedef std::vector sequence; - ifstream Aifs(A.c_str()); - ifstream Bifs(B.c_str()); + std::ifstream Aifs(A.c_str()); + std::ifstream Bifs(B.c_str()); elem buf; sequence ALines, BLines; - ostringstream ossLine, ossInfo; + std::ostringstream ossLine, ossInfo; while (getline(Aifs, buf)) { ALines.push_back(buf); @@ -60,14 +51,14 @@ int main(int argc, char *argv[]) { // fpatch assert(BLines == s2); - cout << "fpatch succeeded" << endl; + std::cout << "fpatch succeeded" << std::endl; d.composeUnifiedHunks(); sequence s3 = d.uniPatch(s1); // unipatch assert(BLines == s3); - cout << "unipatch succeeded" << endl; + std::cout << "unipatch succeeded" << std::endl; return 0; } diff --git a/examples/intdiff.cpp b/examples/intdiff.cpp index af56f5a..ba21b7f 100644 --- a/examples/intdiff.cpp +++ b/examples/intdiff.cpp @@ -1,9 +1,4 @@ - -#include -#include -#include - -using namespace std; +#include "common.hpp" using dtl::Diff; @@ -14,16 +9,16 @@ int main(int, char **) { int asiz = sizeof(a) / sizeof(int); int bsiz = sizeof(b) / sizeof(int); for (int i = 0; i < asiz; ++i) { - cout << a[i] << " "; + std::cout << a[i] << " "; } - cout << endl; + std::cout << std::endl; for (int i = 0; i < bsiz; ++i) { - cout << b[i] << " "; + std::cout << b[i] << " "; } - cout << endl; + std::cout << std::endl; typedef int elem; - typedef vector sequence; + typedef std::vector sequence; sequence A(&a[0], &a[asiz]); sequence B(&b[0], &b[bsiz]); @@ -31,18 +26,18 @@ int main(int, char **) { d.compose(); // editDistance - cout << "editDistance:" << d.getEditDistance() << endl; + std::cout << "editDistance:" << d.getEditDistance() << std::endl; // Longest Common Subsequence sequence lcs_v = d.getLcsVec(); - cout << "LCS: "; + std::cout << "LCS: "; for (sequence::iterator vit = lcs_v.begin(); vit != lcs_v.end(); ++vit) { - cout << *vit << " "; + std::cout << *vit << " "; } - cout << endl; + std::cout << std::endl; // Shortest Edit Script - cout << "SES" << endl; + std::cout << "SES" << std::endl; d.printSES(); return 0; diff --git a/examples/intdiff3.cpp b/examples/intdiff3.cpp index 2c0c324..38c5ae9 100644 --- a/examples/intdiff3.cpp +++ b/examples/intdiff3.cpp @@ -1,10 +1,4 @@ - -#include -#include -#include -#include - -using namespace std; +#include "common.hpp" using dtl::Diff3; @@ -15,24 +9,24 @@ int main(int, char **) { int c[10] = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10}; int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10}; - cout << "a:"; + std::cout << "a:"; for (int i = 0; i < 10; ++i) { - cout << a[i] << " "; + std::cout << a[i] << " "; } - cout << endl; - cout << "b:"; + std::cout << std::endl; + std::cout << "b:"; for (int i = 0; i < 10; ++i) { - cout << b[i] << " "; + std::cout << b[i] << " "; } - cout << endl; - cout << "c:"; + std::cout << std::endl; + std::cout << "c:"; for (int i = 0; i < 10; ++i) { - cout << c[i] << " "; + std::cout << c[i] << " "; } - cout << endl; + std::cout << std::endl; typedef int elem; - typedef vector sequence; + typedef std::vector sequence; sequence A(&a[0], &a[10]); sequence B(&b[0], &b[10]); sequence C(&c[0], &c[10]); @@ -40,18 +34,18 @@ int main(int, char **) { Diff3 diff3(A, B, C); diff3.compose(); if (!diff3.merge()) { - cerr << "conflict." << endl; + std::cerr << "conflict." << std::endl; return -1; } sequence s = diff3.getMergedSequence(); - cout << "s:"; + std::cout << "s:"; for (sequence::iterator it = s.begin(); it != s.end(); ++it) { - cout << *it << " "; + std::cout << *it << " "; } - cout << endl; + std::cout << std::endl; assert(s == Answer); - cout << "intdiff3 OK" << endl; + std::cout << "intdiff3 OK" << std::endl; return 0; } diff --git a/examples/patch.cpp b/examples/patch.cpp index a1b2d7f..7be8695 100644 --- a/examples/patch.cpp +++ b/examples/patch.cpp @@ -1,23 +1,16 @@ - #include "common.hpp" -#include -#include -#include -#include - -using namespace std; using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -30,15 +23,15 @@ int main(int argc, char *argv[]) { d.composeUnifiedHunks(); sequence s3 = d.uniPatch(s1); - cout << "before:" << s1 << endl; - cout << "after :" << s2 << endl; + std::cout << "before:" << s1 << std::endl; + std::cout << "after :" << s2 << std::endl; assert(B == s2); - cout << "patch succeeded" << endl; + std::cout << "patch succeeded" << std::endl; - cout << "before:" << s1 << endl; - cout << "after :" << s3 << endl; + std::cout << "before:" << s1 << std::endl; + std::cout << "after :" << s3 << std::endl; assert(B == s3); - cout << "unipatch succeeded" << endl; + std::cout << "unipatch succeeded" << std::endl; return 0; } diff --git a/examples/printers.hpp b/examples/printers.hpp index 7f50457..32d4444 100644 --- a/examples/printers.hpp +++ b/examples/printers.hpp @@ -1,9 +1,9 @@ #ifndef DTL_PRINTERS #define DTL_PRINTERS -#include +#include "common.hpp" -template +template class customChangePrinter : public dtl::Printer { public: customChangePrinter() : dtl::Printer() {} diff --git a/examples/st2ses.cpp b/examples/st2ses.cpp index dc64479..1b4b004 100644 --- a/examples/st2ses.cpp +++ b/examples/st2ses.cpp @@ -1,35 +1,27 @@ - #include "common.hpp" -#include -#include -#include -#include -#include -#include -using namespace std; using namespace dtl; int main(int argc, char *argv[]) { if (isFewArgs(argc, 2)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } - typedef string elem; - typedef vector sequence; + typedef std::string elem; + typedef std::vector sequence; - string s(argv[1]); + std::string s(argv[1]); if (!isFileExist(s)) { - cerr << s << " is invalid." << endl; + std::cerr << s << " is invalid." << std::endl; return -1; } - ifstream fs(s.c_str()); + std::ifstream fs(s.c_str()); const Ses ses = - Diff::composeSesFromStream(fs); + Diff::composeSesFromStream(fs); dtl::Diff::printSES(ses); return 0; diff --git a/examples/storage.hpp b/examples/storage.hpp index 349f473..6767500 100644 --- a/examples/storage.hpp +++ b/examples/storage.hpp @@ -1,7 +1,7 @@ #ifndef DTL_STORAGE #define DTL_STORAGE -#include +#include "common.hpp" template class CustomStorage : public dtl::Storage { diff --git a/examples/strdiff.cpp b/examples/strdiff.cpp index fdeea0c..f47508a 100644 --- a/examples/strdiff.cpp +++ b/examples/strdiff.cpp @@ -1,23 +1,16 @@ - #include "common.hpp" -#include -#include -#include -#include - -using namespace std; using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -27,15 +20,15 @@ int main(int argc, char *argv[]) { d.compose(); // editDistance - cout << "editDistance:" << d.getEditDistance() << endl; + std::cout << "editDistance:" << d.getEditDistance() << std::endl; // Longest Common Subsequence - vector lcs_v = d.getLcsVec(); + std::vector lcs_v = d.getLcsVec(); sequence lcs_s(lcs_v.begin(), lcs_v.end()); - cout << "LCS:" << lcs_s << endl; + std::cout << "LCS:" << lcs_s << std::endl; // Shortest Edit Script - cout << "SES" << endl; + std::cout << "SES" << std::endl; d.printSES(); return 0; diff --git a/examples/strdiff3.cpp b/examples/strdiff3.cpp index c6fc02b..a77044d 100644 --- a/examples/strdiff3.cpp +++ b/examples/strdiff3.cpp @@ -1,23 +1,16 @@ - #include "common.hpp" -#include -#include -#include -#include - -using namespace std; using dtl::Diff3; int main(int argc, char *argv[]) { if (isFewArgs(argc, 4)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -26,10 +19,10 @@ int main(int argc, char *argv[]) { Diff3 diff3(A, B, C); diff3.compose(); if (!diff3.merge()) { - cerr << "conflict." << endl; + std::cerr << "conflict." << std::endl; return 0; } - cout << "result:" << diff3.getMergedSequence() << endl; + std::cout << "result:" << diff3.getMergedSequence() << std::endl; return 0; } diff --git a/examples/strdiff_cp.cpp b/examples/strdiff_cp.cpp index d3929e1..dc7ce91 100644 --- a/examples/strdiff_cp.cpp +++ b/examples/strdiff_cp.cpp @@ -1,24 +1,18 @@ #include "common.hpp" -#include -#include -#include -#include #include "printers.hpp" -using namespace std; - using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -27,9 +21,9 @@ int main(int argc, char *argv[]) { d.compose(); // Shortest Edit Script - cout << "SES" << endl; + std::cout << "SES" << std::endl; - d.printSES(cout); + d.printSES(std::cout); return 0; } diff --git a/examples/strdiff_storage.cpp b/examples/strdiff_storage.cpp index 285b67b..480ef0b 100644 --- a/examples/strdiff_storage.cpp +++ b/examples/strdiff_storage.cpp @@ -1,23 +1,18 @@ #include "common.hpp" -#include -#include -#include #include "storage.hpp" -using namespace std; - using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -26,13 +21,13 @@ int main(int argc, char *argv[]) { d.compose(); // Shortest Edit Script - cout << "SES" << endl; + std::cout << "SES" << std::endl; - string result; + std::string result; - d.storeSES(result); + d.storeSES(result); - cout << result; + std::cout << result; return 0; } diff --git a/examples/unidiff.cpp b/examples/unidiff.cpp index c07ac26..4d146e4 100644 --- a/examples/unidiff.cpp +++ b/examples/unidiff.cpp @@ -1,24 +1,13 @@ - #include "common.hpp" -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; using dtl::Diff; using dtl::elemInfo; using dtl::uniHunk; -static void showStats(string fp1, string fp2); -static void unifiedDiff(string fp1, string fp2); +static void showStats(std::string fp1, std::string fp2); +static void unifiedDiff(std::string fp1, std::string fp2); -static void showStats(string fp1, string fp2) { +static void showStats(std::string fp1, std::string fp2) { const int MAX_LENGTH = 255; char time_format[] = "%Y-%m-%d %H:%M:%S %z"; time_t rawtime[2]; @@ -26,11 +15,11 @@ static void showStats(string fp1, string fp2) { struct stat st[2]; if (stat(fp1.c_str(), &st[0]) == -1) { - cerr << "argv1 is invalid." << endl; + std::cerr << "argv1 is invalid." << std::endl; exit(-1); } if (stat(fp2.c_str(), &st[1]) == -1) { - cerr << "argv2 is invalid" << endl; + std::cerr << "argv2 is invalid" << std::endl; exit(-1); } @@ -38,20 +27,20 @@ static void showStats(string fp1, string fp2) { rawtime[0] = st[0].st_mtime; timeinfo[0] = localtime(&rawtime[0]); strftime(buf[0], MAX_LENGTH, time_format, timeinfo[0]); - cout << "--- " << fp1 << '\t' << buf[0] << endl; + std::cout << "--- " << fp1 << '\t' << buf[0] << std::endl; rawtime[1] = st[1].st_mtime; timeinfo[1] = localtime(&rawtime[1]); strftime(buf[1], MAX_LENGTH, time_format, timeinfo[1]); - cout << "+++ " << fp2 << '\t' << buf[1] << endl; + std::cout << "+++ " << fp2 << '\t' << buf[1] << std::endl; } -static void unifiedDiff(string fp1, string fp2) { - typedef string elem; - typedef vector sequence; - typedef pair sesElem; +static void unifiedDiff(std::string fp1, std::string fp2) { + typedef std::string elem; + typedef std::vector sequence; + typedef std::pair sesElem; - ifstream Aifs(fp1.c_str()); - ifstream Bifs(fp2.c_str()); + std::ifstream Aifs(fp1.c_str()); + std::ifstream Bifs(fp2.c_str()); elem buf; sequence ALines, BLines; @@ -80,21 +69,21 @@ static void unifiedDiff(string fp1, string fp2) { int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } - string s1(argv[1]); - string s2(argv[2]); + std::string s1(argv[1]); + std::string s2(argv[2]); bool fileExist = true; if (!isFileExist(s1)) { - cerr << s1 << " is invalid." << endl; + std::cerr << s1 << " is invalid." << std::endl; fileExist = false; } if (!isFileExist(s2)) { - cerr << s2 << " is invalid." << endl; + std::cerr << s2 << " is invalid." << std::endl; fileExist = false; } diff --git a/examples/unistrdiff.cpp b/examples/unistrdiff.cpp index f45122c..4457d2d 100644 --- a/examples/unistrdiff.cpp +++ b/examples/unistrdiff.cpp @@ -1,22 +1,16 @@ - #include "common.hpp" -#include -#include -#include - -using namespace std; using dtl::Diff; int main(int argc, char *argv[]) { if (isFewArgs(argc)) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return -1; } typedef char elem; - typedef string sequence; + typedef std::string sequence; sequence A(argv[1]); sequence B(argv[2]); @@ -26,12 +20,12 @@ int main(int argc, char *argv[]) { d.composeUnifiedHunks(); // editDistance - cout << "editDistance:" << d.getEditDistance() << endl; + std::cout << "editDistance:" << d.getEditDistance() << std::endl; // Longest Common Subsequence - vector lcs_v = d.getLcsVec(); + std::vector lcs_v = d.getLcsVec(); sequence lcs_s(lcs_v.begin(), lcs_v.end()); - cout << "LCS:" << lcs_s << endl; + std::cout << "LCS:" << lcs_s << std::endl; // print Unified Format d.printUnifiedFormat(); diff --git a/dtl/Diff.hpp b/include/Diff.hpp similarity index 96% rename from dtl/Diff.hpp rename to include/Diff.hpp index 44ef022..2bd516c 100644 --- a/dtl/Diff.hpp +++ b/include/Diff.hpp @@ -38,13 +38,19 @@ #ifndef DTL_DIFF_H #define DTL_DIFF_H +#include "variables.hpp" + +#include "Lcs.hpp" +#include "Ses.hpp" +#include "functors.hpp" + namespace dtl { /** * diff class template * sequence must support random_access_iterator. */ -template , +template , typename comparator = Compare> class Diff { private: @@ -225,7 +231,7 @@ public: oy = 0; long long p = -1; fp = new long long[M + N + 3]; - fill(&fp[0], &fp[M + N + 3], -1); + std::fill(&fp[0], &fp[M + N + 3], -1); path = editPath(M + N + 3); fill(path.begin(), path.end(), -1); ONP: @@ -346,7 +352,7 @@ public: sesElemVec change; sesElemVec ses_v = ses.getSequence(); long long l_cnt = 1; - long long length = distance(ses_v.begin(), ses_v.end()); + long long length = std::distance(ses_v.begin(), ses_v.end()); long long middle = 0; bool isMiddle, isAfter; elemInfo einfo; @@ -407,7 +413,8 @@ public: } common[0].push_back(*it); } else { - rotate(common[0].begin(), common[0].begin() + 1, common[0].end()); + std::rotate(common[0].begin(), common[0].begin() + 1, + common[0].end()); common[0].pop_back(); common[0].push_back(*it); ++a; @@ -463,7 +470,7 @@ public: if (c == 0) ++c; if (wasSwapped()) - swap(a, c); + std::swap(a, c); hunk.a = a; hunk.b = b; hunk.c = c; @@ -493,7 +500,7 @@ public: Ses ret; long long x_idx, y_idx; x_idx = y_idx = 1; - while (getline(st, line)) { + while (std::getline(st, line)) { elem mark(line.begin(), line.begin() + 1); elem e(line.begin() + 1, line.end()); if (mark == SES_MARK_DELETE) { @@ -517,12 +524,12 @@ private: */ void init() { M = distance(A.begin(), A.end()); - N = distance(B.begin(), B.end()); + N = std::distance(B.begin(), B.end()); if (M < N) { swapped = false; } else { swap(A, B); - swap(M, N); + std::swap(M, N); swapped = true; } editDistance = 0; @@ -543,7 +550,7 @@ private: const long long &below) { long long r = above > below ? path[(size_t)k - 1 + offset] : path[(size_t)k + 1 + offset]; - long long y = max(above, below); + long long y = std::max(above, below); long long x = y - k; while ((size_t)x < M && (size_t)y < N && (swapped ? cmp.impl(B[(size_t)y], A[(size_t)x]) @@ -636,12 +643,12 @@ private: A = A_; B = B_; M = distance(A.begin(), A.end()); - N = distance(B.begin(), B.end()); + N = std::distance(B.begin(), B.end()); delta = N - M; offset = M + 1; delete[] fp; fp = new long long[M + N + 3]; - fill(&fp[0], &fp[M + N + 3], -1); + std::fill(&fp[0], &fp[M + N + 3], -1); fill(path.begin(), path.end(), -1); ox = x_idx - 1; oy = y_idx - 1; diff --git a/dtl/Diff3.hpp b/include/Diff3.hpp similarity index 98% rename from dtl/Diff3.hpp rename to include/Diff3.hpp index 8c8fc62..01b1a98 100644 --- a/dtl/Diff3.hpp +++ b/include/Diff3.hpp @@ -38,13 +38,15 @@ #ifndef DTL_DIFF3_H #define DTL_DIFF3_H +#include "Diff.hpp" + namespace dtl { /** * diff3 class template * sequence must support random_access_iterator. */ -template , +template , typename comparator = Compare> class Diff3 { private: diff --git a/dtl/Lcs.hpp b/include/Lcs.hpp similarity index 97% rename from dtl/Lcs.hpp rename to include/Lcs.hpp index 2ae422e..7a601c7 100644 --- a/dtl/Lcs.hpp +++ b/include/Lcs.hpp @@ -38,6 +38,9 @@ #ifndef DTL_LCS_H #define DTL_LCS_H +#include "variables.hpp" +#include "Sequence.hpp" + namespace dtl { /** diff --git a/dtl/Sequence.hpp b/include/Sequence.hpp similarity index 98% rename from dtl/Sequence.hpp rename to include/Sequence.hpp index c2f29d0..1a34ce9 100644 --- a/dtl/Sequence.hpp +++ b/include/Sequence.hpp @@ -45,7 +45,7 @@ namespace dtl { */ template class Sequence { public: - typedef vector elemVec; + typedef std::vector elemVec; Sequence() {} virtual ~Sequence() {} diff --git a/dtl/Ses.hpp b/include/Ses.hpp similarity index 97% rename from dtl/Ses.hpp rename to include/Ses.hpp index 7781a43..54df713 100644 --- a/dtl/Ses.hpp +++ b/include/Ses.hpp @@ -38,6 +38,9 @@ #ifndef DTL_SES_H #define DTL_SES_H +#include "variables.hpp" +#include "Sequence.hpp" + namespace dtl { /** @@ -46,7 +49,7 @@ namespace dtl { template class Ses : public Sequence { private: typedef pair sesElem; - typedef vector sesElemVec; + typedef std::vector sesElemVec; public: Ses() : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(false) { diff --git a/dtl/dtl.hpp b/include/dtl.hpp similarity index 85% rename from dtl/dtl.hpp rename to include/dtl.hpp index 1f37ac2..b1b7c43 100644 --- a/dtl/dtl.hpp +++ b/include/dtl.hpp @@ -36,6 +36,24 @@ #ifndef DTL_H #define DTL_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif // HAVE_UNISTD_H + #include "Diff.hpp" #include "Diff3.hpp" #include "Lcs.hpp" diff --git a/dtl/functors.hpp b/include/functors.hpp similarity index 94% rename from dtl/functors.hpp rename to include/functors.hpp index 7e789f3..84ef207 100644 --- a/dtl/functors.hpp +++ b/include/functors.hpp @@ -38,14 +38,16 @@ #ifndef DTL_FUNCTORS_H #define DTL_FUNCTORS_H +#include "variables.hpp" + namespace dtl { /** * printer class template */ -template class Printer { +template class Printer { public: - Printer() : out_(cout) {} + Printer() : out_(std::cout) {} Printer(stream &out) : out_(out) {} virtual ~Printer() {} virtual void operator()(const sesElem &se) const = 0; @@ -57,7 +59,7 @@ protected: /** * common element printer class template */ -template +template class CommonPrinter : public Printer { public: CommonPrinter() : Printer() {} @@ -71,7 +73,7 @@ public: /** * ses element printer class template */ -template +template class ChangePrinter : public Printer { public: ChangePrinter() : Printer() {} diff --git a/dtl/variables.hpp b/include/variables.hpp similarity index 97% rename from dtl/variables.hpp rename to include/variables.hpp index e93f843..2f69803 100644 --- a/dtl/variables.hpp +++ b/include/variables.hpp @@ -38,12 +38,6 @@ #ifndef DTL_VARIABLES_H #define DTL_VARIABLES_H -#include -#include -#include -#include -#include - namespace dtl { using std::cout; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..2a73724 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +enable_testing() +find_package(GTest REQUIRED) + +add_executable(dtl_test + test/Intdifftest.cpp + test/Objdifftest.cpp + test/Patchtest.cpp + test/Strdiff3test.cpp + test/Strdifftest.cpp + test/dtl_test.cpp + test/dtl_test_common.cpp +) + +target_include_directories(dtl_test BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/test +) + +target_link_libraries(dtl_test GTest::gtest GTest::gtest_main) + +add_test(AllTests dtl_test) diff --git a/test/Objdifftest.cpp b/test/Objdifftest.cpp index 8e23415..ae734a6 100644 --- a/test/Objdifftest.cpp +++ b/test/Objdifftest.cpp @@ -1,6 +1,7 @@ -#include "comparators.hpp" #include "dtl_test_common.hpp" +#include "comparators.hpp" + class Objdifftest : public ::testing::Test { protected: dtl_test_typedefs(string, vector) typedef struct case_t { diff --git a/test/SConstruct b/test/SConstruct deleted file mode 100644 index b9541d6..0000000 --- a/test/SConstruct +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# SConstrunct for dtl test - -import os - - -def path_chomp(path): - if path[-1] == '/': - return path[:-1] - return path - - -env = Environment( - CPPFLAGS=['-Wall', '-O2'], - CPPPATH=['..'], - CXXFLAGS="-std=c++11", -) - -conf = Configure(env) - -if not conf.CheckCXX(): - 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!") - Exit(1) - -conf.Finish() - -test = env.Program( - 'dtl_test', - [Glob('*.cpp')], -) - -test_alias = env.Alias('check', test, test[0].abspath) - -env.AlwaysBuild(test_alias) diff --git a/test/Strdiff3test.cpp b/test/Strdiff3test.cpp index 6ad77c5..cb15f04 100644 --- a/test/Strdiff3test.cpp +++ b/test/Strdiff3test.cpp @@ -1,6 +1,7 @@ -#include "comparators.hpp" #include "dtl_test_common.hpp" +#include "comparators.hpp" + class Strdiff3test : public ::testing::Test { protected: dtl_test_typedefs(char, string) typedef struct case_t { diff --git a/test/Strdifftest.cpp b/test/Strdifftest.cpp index 4f1fdf7..4f9d576 100644 --- a/test/Strdifftest.cpp +++ b/test/Strdifftest.cpp @@ -1,6 +1,7 @@ -#include "comparators.hpp" #include "dtl_test_common.hpp" +#include "comparators.hpp" + class Strdifftest : public ::testing::Test { protected: dtl_test_typedefs(char, string) typedef struct case_t { diff --git a/test/comparators.hpp b/test/comparators.hpp index 0a32344..36edd99 100644 --- a/test/comparators.hpp +++ b/test/comparators.hpp @@ -1,16 +1,18 @@ #ifndef DTL_COMPARATORS #define DTL_COMPARATORS +#include "functors.hpp" + class CaseInsensitive : public dtl::Compare { public: virtual bool impl(const char &a, const char &b) const { - return tolower(a) == tolower(b); + return std::tolower(a) == std::tolower(b); } }; -class StringCaseInsensitive : public dtl::Compare { +class StringCaseInsensitive : public dtl::Compare { public: - virtual bool impl(const string &a, const string &b) const { + virtual bool impl(const std::string &a, const std::string &b) const { if (a.length() == b.length()) { bool equal = (strncasecmp(a.c_str(), b.c_str(), a.length()) == 0); return equal; diff --git a/test/dtl_test.cpp b/test/dtl_test.cpp index 47c7573..5906b20 100644 --- a/test/dtl_test.cpp +++ b/test/dtl_test.cpp @@ -1,8 +1,4 @@ -/** - * It is necessary to use googletest to run tests. - */ - -#include +#include "dtl_test_common.hpp" int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); diff --git a/test/dtl_test_common.cpp b/test/dtl_test_common.cpp index 84f8794..b5ea6d8 100644 --- a/test/dtl_test_common.cpp +++ b/test/dtl_test_common.cpp @@ -1,4 +1,3 @@ - #include "dtl_test_common.hpp" string create_path(const string &test_name, string diff_name, enum type_diff t, diff --git a/test/dtl_test_common.hpp b/test/dtl_test_common.hpp index 20adaea..2df90fc 100644 --- a/test/dtl_test_common.hpp +++ b/test/dtl_test_common.hpp @@ -1,15 +1,9 @@ - #ifndef DTL_TEST_COMMON #define DTL_TEST_COMMON -#include -#include -#include #include -#include -#include -#include -#include + +#include "dtl.hpp" using std::cerr; using std::endl;