diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/.gitignore" "b/C++/codes/2024-07/\351\273\204\345\261\261/.gitignore" index 1cb83798b6420225ff38b8b0a8ad98d3ef42ebfd..8a7b61dabd9d12a377ff3ee1ff218e878a2460ae 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/.gitignore" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/.gitignore" @@ -1,2 +1,3 @@ bin/ -build/ \ No newline at end of file +build/ +.vscode/ \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/CMakeLists.txt" index 58966d20fd0f961fe90f6bd55e58404423d3f833..dd784aca2997ace9409612821dbebaaaae5c4c7b 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/CMakeLists.txt" @@ -1,7 +1,9 @@ cmake_minimum_required(VERSION 3.5.0) project(cpp_exercise VERSION 0.1.0 LANGUAGES C CXX) -file(GLOB chapters ${PROJECT_SOURCE_DIR}/chapter*) +file(GLOB chapters ${PROJECT_SOURCE_DIR}/src/chapter*) + +set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) foreach(subdirs ${chapters}) add_subdirectory(${subdirs}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/CMakeLists.txt" index 499fdbe9b240f6a492a4f3a747dba119875fa2ac..f7cb63afec308d747300f77f5e2aaa571f3ca789 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter10) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/include/move.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/include/move.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/include/move.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/include/move.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-6/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-6/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/include/list.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/include/list.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/include/list.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/include/list.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/src/list.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/src/list.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/src/list.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/src/list.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter10/codes/10-8/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter10/codes/10-8/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/CMakeLists.txt" index 2f13cd9301be6536e40666b30943b3bfafb49a3d..31aa39bd460900605f6d28e156a08aef58d7ce48 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter11) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/include/complex0.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/include/complex0.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/include/complex0.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/include/complex0.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/src/complex0.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/src/complex0.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/src/complex0.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/src/complex0.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter11/codes/11-7/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter11/codes/11-7/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/CMakeLists.txt" index d959d93f1b0bc40a54616f3ea2934a4317f30b81..33e402882cd5256c586c69f69a63dce5f1b0b719 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter12) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/include/stack.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/include/stack.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/include/stack.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/include/stack.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/src/stack.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/src/stack.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter12/codes/12-4/src/stack.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter12/codes/12-4/src/stack.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/CMakeLists.txt" index 2c660b1f9e168e211977b333daf3014bb36e6751..3a90145a0d0af09b5e88da953137d10a54e53e5a 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter13) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/include/cd.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/include/cd.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/include/cd.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/include/cd.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/include/classic.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/include/classic.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/include/classic.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/include/classic.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/cd.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/cd.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/cd.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/cd.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/classic.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/classic.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/classic.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/classic.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-1/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-1/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/include/port.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/include/port.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/include/port.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/include/port.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/include/vintageport.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/include/vintageport.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/include/vintageport.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/include/vintageport.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/port.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/port.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/port.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/port.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/vintageport.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/vintageport.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter13/codes/13-4/src/vintageport.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter13/codes/13-4/src/vintageport.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/CMakeLists.txt" index 6bccff8d98ef34493a84641476cb29a94e61f14c..f4b218ab4e4c9a542c6f537c1501fed3fd32d856 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter16) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-10/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-10/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-10/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-10/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-10/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-10/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-10/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-10/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-9/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-9/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-9/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-9/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-9/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-9/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter16/codes/16-9/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter16/codes/16-9/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter7/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter7/CMakeLists.txt" similarity index 84% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter7/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter7/CMakeLists.txt" index f6794178a806d403207c2753e9631559d22f60dc..46199ad6170ddf5af4481cf767d331c2a93ea3c2 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter7/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter7/CMakeLists.txt" @@ -3,4 +3,4 @@ PROJECT(exercises_7_10) SET(SRC_LIST src/7-10.cpp) ADD_EXECUTABLE(exercise_7_10 ${SRC_LIST}) -set_target_properties(exercise_7_10 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") +set_target_properties(exercise_7_10 PROPERTIES RUNTIME_OUTPUT_DIRECTORY BINARY_OUTPUT_PATH) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter7/src/7-10.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter7/src/7-10.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter7/src/7-10.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter7/src/7-10.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/CMakeLists.txt" similarity index 67% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/CMakeLists.txt" index 53ac84f583b5b29e2e32644b81f5e3b379266c6d..2ed5106fbcf1d9c9c6a330ad87ae9af8e06df0e0 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/CMakeLists.txt" @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.10) project(chapter8) -set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) -set(BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) - -file(MAKE_DIRECTORY ${BINARY_DIR}) +set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) file(GLOB SOURCES "${SOURCE_DIR}/*.cpp") @@ -14,6 +11,6 @@ foreach(SOURCE_FILE ${SOURCES}) add_executable("exercise_${FILENAME}" ${SOURCE_FILE}) set_target_properties("exercise_${FILENAME}" PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${BINARY_DIR} + RUNTIME_OUTPUT_DIRECTORY ${BINARY_OUTPUT_PATH} ) endforeach() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/src/8-4.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/src/8-4.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/src/8-4.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/src/8-4.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/src/8-6.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/src/8-6.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter8/src/8-6.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter8/src/8-6.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/CMakeLists.txt" similarity index 78% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/CMakeLists.txt" index 4743253664be4bf61d079f354338b649f651362c..6fd76da3a2c035808b226a24f5c433123c69e770 100644 --- "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/CMakeLists.txt" +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/CMakeLists.txt" @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(chapter9) -set(BINARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) - file(GLOB children ${PROJECT_SOURCE_DIR}/codes/*) foreach(subdirs ${children}) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/include/golf.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/include/golf.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/include/golf.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/include/golf.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/src/golf.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/src/golf.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/src/golf.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/src/golf.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-1/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-1/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/CMakeLists.txt" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/CMakeLists.txt" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/CMakeLists.txt" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/include/sales.h" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/include/sales.h" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/include/sales.h" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/include/sales.h" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/src/main.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/src/main.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/src/main.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/src/main.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/src/sales.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/src/sales.cpp" similarity index 100% rename from "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/chapter9/codes/9-4/src/sales.cpp" rename to "C++/codes/2024-07/\351\273\204\345\261\261/C++_exercise/src/chapter9/codes/9-4/src/sales.cpp" diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-format" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-format" new file mode 100644 index 0000000000000000000000000000000000000000..8d709151f7012d4b1569304afb200af0ce97e47d --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-format" @@ -0,0 +1,24 @@ +--- +BasedOnStyle: Google +AlignAfterOpenBracket: 'AlwaysBreak' +AllowAllConstructorInitializersOnNextLine: 'false' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AlignConsecutiveMacros: 'true' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: 'None' +AllowShortIfStatementsOnASingleLine: 'Never' +AllowShortLoopsOnASingleLine: 'false' +BreakBeforeBraces: Allman +BinPackArguments: 'false' +BinPackParameters: 'false' +Cpp11BracedListStyle: 'false' +ColumnLimit: 125 +NamespaceIndentation: All +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeCtorInitializerColon: 'true' +SpaceBeforeInheritanceColon: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'true' +SpaceInEmptyBlock: true +Standard: 'Latest' +... diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-tidy" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-tidy" new file mode 100644 index 0000000000000000000000000000000000000000..d85b250a5e402bd6911755b0f44ac98dcc8aec4c --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.clang-tidy" @@ -0,0 +1,6 @@ +--- +Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-llvmlibc-*' +CheckOptions: [{ key: misc-non-private-member-variables-in-classes, value: IgnoreClassesWithAllMemberVariablesBeingPublic }] +WarningsAsErrors: '*' +HeaderFilterRegex: '' +FormatStyle: none diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/bug_report.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/bug_report.md" new file mode 100644 index 0000000000000000000000000000000000000000..7532789bdb4353ca0a42dcdfa23a38093f26f7b2 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/bug_report.md" @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Create a report to help me improve +title: "[BUG]" +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +* OS: [e.g. Windows] +* Version [e.g. 10] + +**Additional context** +Add any other context about the problem here. diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/custom.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/custom.md" new file mode 100644 index 0000000000000000000000000000000000000000..48d5f81fa422964dd1eea360efdecfc5dc9a6c87 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/custom.md" @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/feature_request.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/feature_request.md" new file mode 100644 index 0000000000000000000000000000000000000000..e75a04b91982fd762ac1b841b1bcffc806cc442f --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/ISSUE_TEMPLATE/feature_request.md" @@ -0,0 +1,25 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE]" +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated +when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Provide usage examples** +A few examples of how the feature should be used. Please make sure they are clear +and concise. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/macos.yml" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/macos.yml" new file mode 100644 index 0000000000000000000000000000000000000000..e20fc40b3dd8b6ae6e9801a6e9bb35f97b4388ee --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/macos.yml" @@ -0,0 +1,53 @@ +name: MacOS + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + BUILD_TYPE: Release + INSTALL_LOCATION: .local + +jobs: + build: + + runs-on: macos-latest + if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - uses: actions/checkout@v2 + + - name: cache dependencies + uses: actions/cache@v2 + id: cache + with: + path: ${{ github.workspace }}/${{ env.INSTALL_LOCATION }} + key: ${{ runner.os }}-dependencies + + - name: install GoogleTest + if: ${{ steps.cache.output.cache-hit != 'true' }} + run: | + cd .. + git clone https://github.com/google/googletest.git --branch release-1.10.0 + cd googletest + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/$INSTALL_LOCATION + cmake --build build --config Release + cmake --build build --target install --config Release + cd ../modern-cpp-template + + - name: configure + run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/$INSTALL_LOCATION + + - name: build + run: cmake --build build --config $BUILD_TYPE -j4 + + - name: run tests + run: | + cd build + ctest -C $BUILD_TYPE -VV + + - name: install project + run: cmake --build build --target install --config Release + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/release.yml" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/release.yml" new file mode 100644 index 0000000000000000000000000000000000000000..433c451c70012e7313d5fa387fe0fdfae800ac25 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/release.yml" @@ -0,0 +1,189 @@ +name: Release + +on: + push: + tags: + - 'v*' + +env: + PROJECT_NAME: "modern-cpp-template" + BUILD_TYPE: Release + +jobs: + build: + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + strategy: + fail-fast: false + matrix: + config: + - { + name: "Windows Latest MSVC", + artifact_ext: '.zip', + os: windows-latest, + cc: "cl", + cxx: "cl", + environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat", + } + - { + name: "Ubuntu Latest GCC", + artifact_ext: '.tar.gz', + os: ubuntu-latest, + cc: "gcc", + cxx: "g++", + } + - { + name: "macOS Latest Clang", + artifact_ext: '.tar.gz', + os: macos-latest, + cc: "clang", + cxx: "clang++", + } + + steps: + - name: set version name (Windows) + id: version_win + if: ${{ runner.os == 'Windows' }} + run: | + $TAG = (${env:GITHUB_REF} -replace 'refs/tags/', '') + echo "::set-output name=name::$TAG" + + - name: set version name + id: version + if: ${{ runner.os != 'Windows' }} + run: echo ::set-output name=name::${GITHUB_REF#refs/tags/} + + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: cache dependencies + uses: actions/cache@v2 + id: cache + with: + path: ${{ github.HOME }}/.local + key: ${{ runner.os }}-dependencies + + - name: install GoogleTest + if: ${{ steps.cache.output.cache-hit != 'true' }} + run: | + cd .. + git clone https://github.com/google/googletest.git --branch release-1.10.0 + cd googletest + cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/.local" -Dgtest_force_shared_crt=1 + cmake --build build --config Release + cmake --build build --target install --config Release + cd ../modern-cpp-template + + - name: configure + run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/.local" + + - name: build + run: cmake --build build --config "$env:BUILD_TYPE" -j4 + + - name: run tests + run: | + cd build + ctest -C "$env:BUILD_TYPE" -VV + + # for a release not containing directly the source code, replace the files archived + # with the actual files needed (i.e. *.lib/*.a and *.h(pp)) + + - name: generate archive (Windows) + if: ${{ runner.os == 'Windows' }} + run: | + rmdir -r -fo build + 7z a -tzip $HOME/artifact.zip * + + + - name: generate archive + if: ${{ runner.os != 'Windows' }} + run: | + rm -rf build + tar -cvzf $HOME/artifact.tar.gz . + + - name: upload artifacts + uses: actions/upload-artifact@v2 + if: ${{ runner.os == 'Windows' }} + with: + name: ${{ runner.os }}-${{ steps.version_win.outputs.name }} + path: '~/artifact.*' + + - name: upload artifacts + uses: actions/upload-artifact@v2 + if: ${{ runner.os != 'Windows' }} + with: + name: ${{ runner.os }}-${{ steps.version.outputs.name }} + path: '~/artifact.*' + + release: + if: contains(github.ref, 'tags/v') + runs-on: ubuntu-latest + needs: build + + steps: + - name: set version name + id: version + run: echo ::set-output name=name::${GITHUB_REF#refs/tags/} + + - name: create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ steps.version.outputs.name }} + # if needed, you can set the release body here + #body: "Release notes" + draft: false + prerelease: false + + - name: download artifact + uses: actions/download-artifact@v2 + with: + name: "Linux-${{ steps.version.outputs.name }}" + path: ./ + + - name: upload ubuntu release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "artifact.tar.gz" + asset_name: "${{ env.PROJECT_NAME }}-Linux-${{ steps.version.outputs.name }}.tar.gz" + asset_content_type: application/x-tar + + - name: download artifact + uses: actions/download-artifact@v2 + with: + name: "Windows-${{ steps.version.outputs.name }}" + path: ./ + + - name: upload windows release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "artifact.zip" + asset_name: "${{ env.PROJECT_NAME }}-Windows-${{ steps.version.outputs.name }}.zip" + asset_content_type: application/zip + + - name: download artifact + uses: actions/download-artifact@v2 + with: + name: "macOS-${{ steps.version.outputs.name }}" + path: ./ + + - name: upload macos release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "./artifact.tar.gz" + asset_name: "${{ env.PROJECT_NAME }}-macOS-${{ steps.version.outputs.name }}.tar.gz" + asset_content_type: application/x-tar diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/ubuntu.yml" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/ubuntu.yml" new file mode 100644 index 0000000000000000000000000000000000000000..2aa85426176babe9583805e400353bd23f9c6601 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/ubuntu.yml" @@ -0,0 +1,55 @@ +name: Ubuntu + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + BUILD_TYPE: Release + INSTALL_LOCATION: .local + +jobs: + build: + + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - uses: actions/checkout@v2 + + - name: cache dependencies + uses: actions/cache@v2 + id: cache + with: + path: ${{ github.workspace }}/${{ env.INSTALL_LOCATION }} + key: ${{ runner.os }}-dependencies + + - name: install GoogleTest + if: ${{ steps.cache.output.cache-hit != 'true' }} + run: | + cd .. + git clone https://github.com/google/googletest.git --branch release-1.10.0 + cd googletest + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/$INSTALL_LOCATION + cmake --build build --config Release + cmake --build build --target install --config Release + + - name: configure + run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/$INSTALL_LOCATION -DProject_ENABLE_CODE_COVERAGE=1 + + - name: build + run: cmake --build build --config $BUILD_TYPE -j4 + + - name: run tests + run: | + cd build + ctest -C $BUILD_TYPE -VV + + - name: Code coverage using Codecov + run: bash <(curl -s https://codecov.io/bash) + + - name: install project + run: cmake --build build --target install --config Release + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/windows.yml" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/windows.yml" new file mode 100644 index 0000000000000000000000000000000000000000..d2da57413294e8aca76bef2bec2f29cf196d5a5c --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.github/workflows/windows.yml" @@ -0,0 +1,53 @@ +name: Windows + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + BUILD_TYPE: Release + INSTALL_LOCATION: ".local" + +jobs: + build: + + runs-on: windows-latest + if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - uses: actions/checkout@v2 + + - name: cache dependencies + uses: actions/cache@v2 + id: cache + with: + path: ${{env.INSTALL_LOCATION}} + key: ${{runner.os}}-dependencies + + - name: install GoogleTest + if: ${{steps.cache.output.cache-hit != 'true'}} + run: | + cd .. + git clone https://github.com/google/googletest.git --branch release-1.10.0 + cd googletest + cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/$env:INSTALL_LOCATION" -Dgtest_force_shared_crt=1 + cmake --build build --config Release + cmake --build build --target install --config Release + cd ../modern-cpp-template + + - name: configure + run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/$env:INSTALL_LOCATION" + + - name: build + run: cmake --build build --config "$env:BUILD_TYPE" -j4 + + - name: run tests + run: | + cd build + ctest -C "$env:BUILD_TYPE" -VV + + - name: install project + run: cmake --build build --target install --config Release + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.gitignore" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..f483f29764570b9e36883d13b4cb9928265c1250 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/.gitignore" @@ -0,0 +1,370 @@ +[Bb]uild/* +[Dd]ocs/* +CMakeCache.* +CMakeFiles/* +[Tt]esting/* + +### VisualStudioCode ### +.vscode/* +.vscode/settings.json +.vscode/tasks.json +.vscode/launch.json +.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +#KDevelop +*.kdev4 +.kdev4/* + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +Assignment_3/ \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CMakeLists.txt" new file mode 100644 index 0000000000000000000000000000000000000000..afb8bf6185581e57c53a44d242f183d47000b30b --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CMakeLists.txt" @@ -0,0 +1,363 @@ +cmake_minimum_required(VERSION 3.15) + +# +# Project details +# + +project( + "optimalPath" + VERSION 0.1.0 + LANGUAGES CXX +) + +# +# Set project options +# + +include(cmake/StandardSettings.cmake) +include(cmake/StaticAnalyzers.cmake) +include(cmake/Utils.cmake) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() +message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...\n") + +if (UNIX) + add_compile_options("$<$:-D_DEBUG>") #this will allow to use same _DEBUG macro available in both Linux as well as Windows - MSCV environment. Easy to put Debug specific code. +endif (UNIX) + + +# +# Setup alternative names +# + +if(${PROJECT_NAME}_USE_ALT_NAMES) + string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE) + string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERCASE) +else() + set(PROJECT_NAME_LOWERCASE ${PROJECT_NAME}) + set(PROJECT_NAME_UPPERCASE ${PROJECT_NAME}) +endif() + +# +# Prevent building in the source directory +# + +if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n") +endif() + +# +# Enable package managers +# + +include(cmake/Conan.cmake) +include(cmake/Vcpkg.cmake) + +# +# Create library, setup header and source files +# + +# Find all headers and implementation files +include(cmake/SourcesAndHeaders.cmake) + +if(${PROJECT_NAME}_BUILD_EXECUTABLE) + add_executable(${PROJECT_NAME} ${exe_sources}) + + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + verbose_message("Found the following sources:") + foreach(source IN LISTS exe_sources) + verbose_message("* ${source}") + endforeach() + endif() + + if(${PROJECT_NAME}_ENABLE_UNIT_TESTING) + add_library(${PROJECT_NAME}_LIB ${headers} ${sources}) + + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + verbose_message("Found the following headers:") + foreach(header IN LISTS headers) + verbose_message("* ${header}") + endforeach() + endif() + endif() +elseif(${PROJECT_NAME}_BUILD_HEADERS_ONLY) + add_library(${PROJECT_NAME} INTERFACE) + + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + verbose_message("Found the following headers:") + foreach(header IN LIST headers) + verbose_message("* ${header}") + endforeach() + endif() +else() + add_library( + ${PROJECT_NAME} + ${headers} + ${sources} + ) + + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + verbose_message("Found the following sources:") + foreach(source IN LISTS sources) + verbose_message("* ${source}") + endforeach() + verbose_message("Found the following headers:") + foreach(header IN LISTS headers) + verbose_message("* ${header}") + endforeach() + endif() +endif() + +set_target_properties( + ${PROJECT_NAME} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}" +) +if(${PROJECT_NAME}_BUILD_EXECUTABLE AND ${PROJECT_NAME}_ENABLE_UNIT_TESTING) + set_target_properties( + ${PROJECT_NAME}_LIB + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" + OUTPUT_NAME ${PROJECT_NAME} + ) +endif() + +message(STATUS "Added all header and implementation files.\n") + +# +# Set the project standard and warnings +# + +if(${PROJECT_NAME}_BUILD_HEADERS_ONLY) + target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) +else() + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) + + if(${PROJECT_NAME}_BUILD_EXECUTABLE AND ${PROJECT_NAME}_ENABLE_UNIT_TESTING) + target_compile_features(${PROJECT_NAME}_LIB PUBLIC cxx_std_17) + endif() +endif() +include(cmake/CompilerWarnings.cmake) +set_project_warnings(${PROJECT_NAME}) + +verbose_message("Applied compiler warnings. Using standard ${CMAKE_CXX_STANDARD}.\n") + +# +# Enable Doxygen +# + +include(cmake/Doxygen.cmake) + +# +# Model project dependencies +# + +# Identify and link with the specific "packages" the project uses +#find_package(package_name package_version REQUIRED package_type [other_options]) +#target_link_libraries( +# ${PROJECT_NAME} +# PUBLIC +# dependency1 ... +# PRIVATE +# dependency2 ... +# ${PROJECT_NAME}_PROJECT_OPTIONS +# ${PROJECT_NAME}_PROJECT_WARNINGS +#) +#if(${PROJECT_NAME}_BUILD_EXECUTABLE AND ${PROJECT_NAME}_ENABLE_UNIT_TESTING) +# target_link_libraries( +# ${PROJECT_NAME}_LIB +# PUBLIC +# dependency1 ... +# ) +#endif() + +# For Windows, it is necessary to link with the MultiThreaded library. +# Depending on how the rest of the project's dependencies are linked, it might be necessary +# to change the line to statically link with the library. +# +# This is done as follows: +# +# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# +# On Linux and Mac this variable is ignored. If any issues rise from it, try commenting it out +# and letting CMake decide how to link with it. +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + +verbose_message("Successfully added all dependencies and linked against them.") + +# +# Set the build/user include directories +# + +# Allow usage of header files in the `src` directory, but only for utilities +if(${PROJECT_NAME}_BUILD_HEADERS_ONLY) + target_include_directories( + ${PROJECT_NAME} + INTERFACE + $ + $ + ) +else() + target_include_directories( + ${PROJECT_NAME} + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + if(${PROJECT_NAME}_BUILD_EXECUTABLE AND ${PROJECT_NAME}_ENABLE_UNIT_TESTING) + target_include_directories( + ${PROJECT_NAME}_LIB + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + endif() +endif() + +message(STATUS "Finished setting up include directories.") + +# +# Provide alias to library for +# + +if(${PROJECT_NAME}_BUILD_EXECUTABLE) + add_executable(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +else() + add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +endif() + +verbose_message("Project is now aliased as ${PROJECT_NAME}::${PROJECT_NAME}.\n") + +# +# Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format) +# + +add_clang_format_target() + +# +# Install library for easy downstream inclusion +# + +include(GNUInstallDirs) +install( + TARGETS + ${PROJECT_NAME} + EXPORT + ${PROJECT_NAME}Targets + LIBRARY DESTINATION + ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION + ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION + include + PUBLIC_HEADER DESTINATION + include +) + +install( + EXPORT + ${PROJECT_NAME}Targets + FILE + ${PROJECT_NAME}Targets.cmake + NAMESPACE + ${PROJECT_NAME}:: + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +# +# Add version header +# + +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/version.hpp.in + include/${PROJECT_NAME_LOWERCASE}/version.hpp + @ONLY +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME_LOWERCASE}/version.hpp + DESTINATION + include/${PROJECT_NAME_LOWERCASE} +) + +# +# Install the `include` directory +# + +install( + DIRECTORY + include/${PROJECT_NAME_LOWERCASE} + DESTINATION + include +) + +verbose_message("Install targets successfully built. Install with `cmake --build --target install --config `.") + +# +# Quick `ConfigVersion.cmake` creation +# + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${PROJECT_NAME}ConfigVersion.cmake + VERSION + ${PROJECT_VERSION} + COMPATIBILITY + SameMajorVersion +) + +configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +# +# Generate export header if specified +# + +if(${PROJECT_NAME}_GENERATE_EXPORT_HEADER) + include(GenerateExportHeader) + generate_export_header(${PROJECT_NAME}) + install( + FILES + ${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWERCASE}_export.h + DESTINATION + include + ) + + message(STATUS "Generated the export header `${PROJECT_NAME_LOWERCASE}_export.h` and installed it.") +endif() + +message(STATUS "Finished building requirements for installing the package.\n") + +# +# Unit testing setup +# + +if(${PROJECT_NAME}_ENABLE_UNIT_TESTING) + enable_testing() + message(STATUS "Build unit tests for the project. Tests should always be found in the test folder\n") + add_subdirectory(test) +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CONTRIBUTING.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CONTRIBUTING.md" new file mode 100644 index 0000000000000000000000000000000000000000..8743dc3b1db97d87d617db2c54e5916652f2f4ba --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/CONTRIBUTING.md" @@ -0,0 +1,203 @@ +# Contributing to [INSERT PROJECT NAME] + +The [INSERT PROJECT NAME] team encourages community feedback and contributions. +Thank you for your interest in making [INSERT PROJECT NAME] better! There are several +ways you can get involved. + +If you are looking for a good way to contribute to the project, please: + +* have a look at the [available issue templates](https://github.com/filipdutescu/modern-cpp-template/issues/new/choose) +and checkout the [examples of good first issues](https://github.com/filipdutescu/modern-cpp-template/contribute) +(or [click here](https://github.com/filipdutescu/modern-cpp-template/labels/good%20first%20issue)). + +* look through the [issues that need help](https://github.com/filipdutescu/modern-cpp-template/labels/help%20wanted). + +* take a look at a [Pull Request template](PULL_REQUEST_TEMPLATE.md) to get yourself +started. + +## Reporting issues and suggesting new features + +If you find that the project is not working properly, please file a report using +the [Bug Report template](https://github.com/filipdutescu/modern-cpp-template/issues/new?assignees=&labels=bug&template=bug_report.md&title=[BUG]). +Should the template provided not suit your needs, feel free to make a +[custom Bug Report](https://github.com/filipdutescu/modern-cpp-template/issues/new/choose), +but please label it accordingly. + +We are happy to hear your ideas for how to further improve [INSERT PROJECT NAME], +ensuring it suits your needs. Check the [Issues](https://github.com/filipdutescu/modern-cpp-template/issues) +and see if others have submitted similar feedback. You can upvote existing feedback +(using the thumbs up reaction/by commenting) or [submit a new suggestion](https://github.com/filipdutescu/modern-cpp-template/labels/feature). + +We always look at upvoted items in [Issues](https://github.com/filipdutescu/modern-cpp-template/issues) +when we decide what to work on next. We read the comments and we look forward to +hearing your input. + +## Finding issues you can help with + +Looking for something to work on? +Issues marked [`good first issue`](https://github.com/filipdutescu/modern-cpp-template/labels/good%20first%20issue) +are a good place to start. + +You can also check the [`help wanted`](https://github.com/filipdutescu/modern-cpp-template/labels/help%20wanted) +tag to find other issues to help with. If you're interested in working on a fix, +leave a comment to let everyone know and to help avoid duplicated effort from others. + +## Contributions we accept + +We highly appreciate any contributions that help us improve the end product, with +a high emphasis being put on any bug fixes you can manage to create and direct +improvements which address the top issues reported by Calculator users. Some general +guidelines: + +### DOs + +* **DO** create one pull request per Issue, and ensure that the Issue is linked +in the pull request. You can follow the [Pull Request Template](PULL_REQUEST_TEMPLATE.md) +for this. + +* **DO** follow our [Coding and Style](#style-guidelines) guidelines, and keep code +changes as small as possible. + +* **DO** include corresponding tests whenever possible. + +* **DO** check for additional occurrences of the same problem in other parts of the +codebase before submitting your PR. + +* **DO** link the issue you are addressing in the pull request. + +* **DO** write a good description for your pull request. More detail is better. +Describe *why* the change is being made and *why* you have chosen a particular solution. +Describe any manual testing you performed to validate your change. + +### DO NOTs + +* **DO NOT** merge multiple changes into one PR unless they have the same root cause. +* **DO NOT** merge directly into the master branch. + +> Submitting a pull request for an approved Issue is not a guarantee it will be approved. +> The change must meet our high bar for code quality, architecture and performance. + +## Making changes to the code + +### Preparing your development environment + +To learn how to build the code and run tests, follow the instructions in the [README](README.md). + +### Style guidelines + +The code in this project uses several different coding styles, depending on the +age and history of the code. Please attempt to match the style of surrounding +code as much as possible. In new components, prefer the patterns described in the +[C++ core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines). + +### Code formatting + +***Run clang-format*** + +Use the following commands from the project's root directory to run clang-format +(must be installed on the host system). + +**1. Run the CMake target for `clang-format`:** + +```bash +cmake --build build --target clang-format +``` + +**2. Using clang-format:** + +```bash +# !!! clang-format does not run recursively in subdirectories !!! +# for each .cpp file modified +clang-format -i *.cpp + +# for each .h file modified +clang-format -i *.h + +# for each .hpp file modified +clang-format -i *.hpp +``` + +**3. Using TheLartians' Format.cmake:** + +```bash +cmake -Htest -Bbuild/test + +# view changes +cmake --build build/test --target format + +# apply changes +cmake --build build/test --target fix-format +``` + +See [Format.cmake](https://github.com/TheLartians/Format.cmake) for more options. + +### Testing + +Your change should include tests to verify new functionality wherever possible. +Code should be structured so that it can be unit tested independently of the UI. +Manual test cases should be used where automated testing is not feasible. + +### Git workflow + +The core principle of the project, when it comes to Git workflows is that the +`master` branch should always be in a healthy state which is ready for release. +Every commit on master should be deployable on push. To ensure this, pull request +**must not** be made directly on master. **Each change** should either be made in +the **development branch** (named a variation of development, i.e. `dev`) or in a +separate branch, named as a short summary of the change. + +If your change is complex, please clean up the branch history before submitting a +pull request. You can use [git rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) +to group your changes into a small number of commits which we can review one at a +time. + +When completing a pull request, we will generally squash your changes into a single +commit. After confirming that the change works as intended, the branch *might* be +deleted, in order to prevent branch polluting. Please let us know if your pull request +needs to be merged as separate commits. + +### Continuous Integration + +For this project, CI is provided by [GitHub Actions](https://github.com/features/actions), +with workflows found in the [`.github/workflows` folder](.github/workflows). Workflows +are run automatically on every commit made on the master branch, unless told to skip +for that particular commit. + +To skip CI runs on a particular commit, include either `[skip ci]` or `[ci skip]` +in the commit message. + +```bash +# an example of a commit message that would not trigger CI workflows +git commit -m "my normal commit message [skip ci]" +# or +git commit -m "my normal commit message [ci skip]" +``` + +## Review process + +After submitting a pull request, members of the team will review your code. We will +assign the request to an appropriate reviewer (if applicable). Any member of the +community may participate in the review, but at least one member of the project team +will ultimately approve the request. + +Often, multiple iterations or discussions will be needed to responding to feedback +from reviewers. Try looking at [past pull requests](https://github.com/filipdutescu/modern-cpp-template/pulls?q=is%3Apr+is%3Aclosed) +to see what the experience might be like. + +## Contributor License Agreement + +Before we can review and accept a pull request from you, you'll need to sign a +Contributor License Agreement (CLA). The CLA ensures that the community is free +to use your contributions. Signing the CLA is a manual process, and you need to +do it for each pull request made. This is done by checking the boxes in the +[Pull Request Readiness Checklist of a Pull Request](PULL_REQUEST_TEMPLATE.md#Pull-Request-Readiness-Checklist). + +### IMPORTANT + +***Checking the aforementioned boxes means that you agree to provide your change +and/or code FREE TO USE and SUBJECT TO CHANGES for the entire community!*** + +You don't need to sign a CLA until you're ready to create a pull request. When your +pull request is created, it is reviewed by a team member which, if the change is +trivial (i.e. you just fixed a typo) will be labelled as `cla-not-required`. +Otherwise, it's classified as `cla-required`, if not already signed. diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Dockerfile" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Dockerfile" new file mode 100644 index 0000000000000000000000000000000000000000..44076e54f4314649babe435b9ec0158fb34eb3d5 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Dockerfile" @@ -0,0 +1,52 @@ +FROM ubuntu:18.04 + +RUN echo "Updating Ubuntu" +RUN apt-get update && apt-get upgrade -y + +RUN echo "Installing dependencies..." +RUN apt install -y \ + ccache \ + clang \ + clang-format \ + clang-tidy \ + cppcheck \ + curl \ + doxygen \ + gcc \ + git \ + graphviz \ + make \ + ninja-build \ + python3 \ + python3-pip \ + tar \ + unzip \ + vim + +RUN echo "Installing dependencies not found in the package repos..." + +RUN apt install -y wget tar build-essential libssl-dev && \ + wget https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0.tar.gz && \ + tar -zxvf cmake-3.15.0.tar.gz && \ + cd cmake-3.15.0 && \ + ./bootstrap && \ + make && \ + make install + +RUN pip3 install conan + +RUN git clone https://github.com/catchorg/Catch2.git && \ + cd Catch2 && \ + cmake -Bbuild -H. -DBUILD_TESTING=OFF && \ + cmake --build build/ --target install + +# Disabled pthread support for GTest due to linking errors +RUN git clone https://github.com/google/googletest.git --branch release-1.10.0 && \ + cd googletest && \ + cmake -Bbuild -Dgtest_disable_pthreads=1 && \ + cmake --build build --config Release && \ + cmake --build build --target install --config Release + +RUN git clone https://github.com/microsoft/vcpkg -b 2020.06 && \ + cd vcpkg && \ + ./bootstrap-vcpkg.sh -disableMetrics -useSystemBinaries diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/LICENSE" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/LICENSE" new file mode 100644 index 0000000000000000000000000000000000000000..471f09f4cfb55e0f1eada17d06022eccead0c747 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/LICENSE" @@ -0,0 +1,25 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Makefile" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Makefile" new file mode 100644 index 0000000000000000000000000000000000000000..d2bdaefdfe4a176a55de809abfbcf76565f9f5e7 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/Makefile" @@ -0,0 +1,63 @@ +.PHONY: install coverage test docs help +.DEFAULT_GOAL := help + +define BROWSER_PYSCRIPT +import os, webbrowser, sys + +try: + from urllib import pathname2url +except: + from urllib.request import pathname2url + +webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) +endef +export BROWSER_PYSCRIPT + +define PRINT_HELP_PYSCRIPT +import re, sys + +for line in sys.stdin: + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) + if match: + target, help = match.groups() + print("%-20s %s" % (target, help)) +endef +export PRINT_HELP_PYSCRIPT + +BROWSER := python -c "$$BROWSER_PYSCRIPT" +INSTALL_LOCATION := ~/.local + +help: + @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) + +test: ## run tests quickly with ctest + rm -rf build/ + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) -Dmodern-cpp-template_ENABLE_UNIT_TESTING=1 -DCMAKE_BUILD_TYPE="Release" + cmake --build build --config Release + cd build/ && ctest -C Release -VV + +coverage: ## check code coverage quickly GCC + rm -rf build/ + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) -Dmodern-cpp-template_ENABLE_CODE_COVERAGE=1 + cmake --build build --config Release + cd build/ && ctest -C Release -VV + cd .. && (bash -c "find . -type f -name '*.gcno' -exec gcov -pb {} +" || true) + +docs: ## generate Doxygen HTML documentation, including API docs + rm -rf docs/ + rm -rf build/ + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) -DProject_ENABLE_DOXYGEN=1 + cmake --build build --config Release + cmake --build build --target doxygen-docs + $(BROWSER) docs/html/index.html + +install: ## install the package to the `INSTALL_LOCATION` + rm -rf build/ + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) + cmake --build build --config Release + cmake --build build --target install --config Release + +format: ## format the project sources + rm -rf build/ + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) + cmake --build build --target clang-format diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/PULL_REQUEST_TEMPLATE.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/PULL_REQUEST_TEMPLATE.md" new file mode 100644 index 0000000000000000000000000000000000000000..85a258275d1f99e79cff3d9fa4e502a42b0da558 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/PULL_REQUEST_TEMPLATE.md" @@ -0,0 +1,72 @@ +**IMPORTANT: Please do not create a Pull Request without creating an issue first.** + +*Any change needs to be discussed before proceeding. Failure to do so may result +in the rejection of the pull request.* + +Please provide enough information so that others can review your pull request. You +can skip this if you're fixing a typo or adding an app to the Showcase. + +Explain the **details** for making this change. What existing problem does the pull +request solve? + +Ex: + +1. If you "Added a/changed the function to do X", explain why: + + * it is necessary to have a way to do X. + * if there already exists a way, why is your implementation better + +2. If you "Fixed bug/error in X", explain: + + * what was the bug/error (if you already made an issue, please link to it here) + * how does your implementation fix the issue + +### Code style and formatting + +Check the [Contributors Style Guidelines section](CONTRIBUTING.md#Style-guidelines) +for how to write your code and the [Contributors Code Formatting section](CONTRIBUTING.md#Code-formatting) +for how to format your code. + +#### Closing Issues + +Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes +(if such). + +--- + +Fixes #XXXX + +## Proposed changes + +* +* +* + +## Motivation behind changes + +### Test plan + +Demonstrate the code is solid. Example: The exact commands you ran and their output, +screenshots / videos if the pull request changes UI. + +*Make sure tests pass on all of the [relevant CI workflows](https://github.com/filipdutescu/modern-cpp-template/actions).* + +### Pull Request Readiness Checklist + +See details at [CONTRIBUTING.md](https://github.com/filipdutescu/modern-cpp-template/blob/master/CONTRIBUTING.md). + +* [ ] I agree to contribute to the project under [INSERT PROJECT NAME] (Unlicense) +[License](LICENSE). + +* [ ] To the best of my knowledge, the proposed patch is not based on a code under +GPL or other license that is incompatible with [INSERT PROJECT NAME] + +* [ ] The PR is proposed to proper branch + +* [ ] There is reference to original bug report and related work + +* [ ] There is accuracy test, performance test and test data in the repository, +if applicable + +* [ ] The feature is well documented and sample code can be built with the project +CMake diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/README.md" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..b92e130712b270d52dae3bc6aecdf0a1f2ff243a --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/README.md" @@ -0,0 +1,57 @@ +# A*寻路算法大作业 + +## Getting Started + +These instructions will get you a copy of the project up and running on your local +machine for development and testing purposes. + +### Prerequisites + +This project is meant to be only a template, thus versions of the software used +can be change to better suit the needs of the developer(s). If you wish to use the +template *as-is*, meaning using the versions recommended here, then you will need: + +* **CMake v3.15+** - found at [https://cmake.org/](https://cmake.org/) + +* **C++ Compiler** - needs to support at least the **C++17** standard, i.e. *MSVC*, +*GCC*, *Clang* + +> ***Note:*** *You also need to be able to provide ***CMake*** a supported +[generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).* + +### Installing + +It is fairly easy to install the project, all you need to do is clone if from +[Gitee](https://gitee.com/fun-sun/iTraining). + +If you wish to clone the repository, rather than generate from it, you simply need +to run: + +```bash +git clone https://gitee.com/fun-sun/iTraining +``` + +测试C++大作业: +```bash +cmake --build build --config Release +build/test/tmp_test_Tests +``` +标准测试提供了三个样例,前两个可以通过,第三个无法到达终点因此无法通过 +随机测试有可能无法通过 + +## Generating the documentation +暂无 + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our how you can +become a contributor and the process for submitting pull requests to us. + +## Authors + +* **黄山** - [@sparklesea](https://github.com/sparklesea) + +## License + +This project is licensed under the [Unlicense](https://unlicense.org/) - see the +[LICENSE](LICENSE) file for details diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/CompilerWarnings.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/CompilerWarnings.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..2b5d58eff36aff6b9e120fc084fa413ce2ff1736 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/CompilerWarnings.cmake" @@ -0,0 +1,99 @@ +# from here: +# +# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Avai +# lable.md +# Courtesy of Jason Turner + +function(set_project_warnings project_name) + set(MSVC_WARNINGS + /W4 # Baseline reasonable warnings + /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss + # of data + /w14254 # 'operator': conversion from 'type1:field_bits' to + # 'type2:field_bits', possible loss of data + /w14263 # 'function': member function does not override any base class + # virtual member function + /w14265 # 'classname': class has virtual functions, but destructor is not + # virtual instances of this class may not be destructed correctly + /w14287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable + # declared in the for-loop is used outside the for-loop scope + /w14296 # 'operator': expression is always 'boolean_value' + /w14311 # 'variable': pointer truncation from 'type1' to 'type2' + /w14545 # expression before comma evaluates to a function which is missing + # an argument list + /w14546 # function call before comma missing argument list + /w14547 # 'operator': operator before comma has no effect; expected + # operator with side-effect + /w14549 # 'operator': operator before comma has no effect; did you intend + # 'operator'? + /w14555 # expression has no effect; expected expression with side- effect + /w14619 # pragma warning: there is no warning number 'number' + /w14640 # Enable warning on thread un-safe static member initialization + /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may + # cause unexpected runtime behavior. + /w14905 # wide string literal cast to 'LPSTR' + /w14906 # string literal cast to 'LPWSTR' + /w14928 # illegal copy-initialization; more than one user-defined + # conversion has been implicitly applied + /permissive- # standards conformance mode for MSVC compiler. + ) + + set(CLANG_WARNINGS + -Wall + -Wextra # reasonable and standard + -Wshadow # warn the user if a variable declaration shadows one from a + # parent context + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a + # non-virtual destructor. This helps catch hard to + # track down memory errors + -Wold-style-cast # warn for c-style casts + -Wcast-align # warn for potential performance problem casts + -Wunused # warn on anything being unused + -Woverloaded-virtual # warn if you overload (not override) a virtual + # function + -Wpedantic # warn if non-standard C++ is used + -Wconversion # warn on type conversions that may lose data + -Wsign-conversion # warn on sign conversions + -Wnull-dereference # warn if a null dereference is detected + -Wdouble-promotion # warn if float is implicit promoted to double + -Wformat=2 # warn on security issues around functions that format output + # (ie printf) + ) + + if (${PROJECT_NAME}_WARNINGS_AS_ERRORS) + set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) + set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) + endif() + + set(GCC_WARNINGS + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks + # do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were + # probably wanted + -Wuseless-cast # warn if you perform a cast to the same type + ) + + if(MSVC) + set(PROJECT_WARNINGS ${MSVC_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(PROJECT_WARNINGS ${CLANG_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(PROJECT_WARNINGS ${GCC_WARNINGS}) + else() + message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") + endif() + + if(${PROJECT_NAME}_BUILD_HEADERS_ONLY) + target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) + else() + target_compile_options(${project_name} PUBLIC ${PROJECT_WARNINGS}) + endif() + + if(NOT TARGET ${project_name}) + message(AUTHOR_WARNING "${project_name} is not a target, thus no compiler warning were added.") + endif() +endfunction() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Conan.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Conan.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..b844e2a5758b013389a709f3cfb9be1dbf05426f --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Conan.cmake" @@ -0,0 +1,46 @@ +if(${PROJECT_NAME}_ENABLE_CONAN) + # + # Setup Conan requires and options here: + # + + set(${PROJECT_NAME}_CONAN_REQUIRES "") + set(${PROJECT_NAME}_CONAN_OPTIONS "") + + # + # If `conan.cmake` (from https://github.com/conan-io/cmake-conan) does not exist, download it. + # + if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") + message( + STATUS + "Downloading conan.cmake from https://github.com/conan-io/cmake-conan..." + ) + file( + DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake" + ) + message(STATUS "Cmake-Conan downloaded succesfully.") + endif() + + include(${CMAKE_BINARY_DIR}/conan.cmake) + + conan_add_remote( + NAME bincrafters + URL + https://api.bintray.com/conan/bincrafters/public-conan + ) + + conan_cmake_run( + REQUIRES + ${${PROJECT_NAME}_CONAN_REQUIRES} + OPTIONS + ${${PROJECT_NAME}_CONAN_OPTIONS} + BASIC_SETUP + CMAKE_TARGETS # Individual targets to link to + BUILD + missing + ) + + conan_basic_setup() + + verbose_message("Conan is setup and all requires have been installed.") +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Doxygen.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Doxygen.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..bd6fe45ba73aec15141dda4a6c6a906adc3e1d40 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Doxygen.cmake" @@ -0,0 +1,11 @@ +if(${PROJECT_NAME}_ENABLE_DOXYGEN) + set(DOXYGEN_CALLER_GRAPH YES) + set(DOXYGEN_CALL_GRAPH YES) + set(DOXYGEN_EXTRACT_ALL YES) + set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs) + + find_package(Doxygen REQUIRED dot) + doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR}) + + verbose_message("Doxygen has been setup and documentation is now available.") +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/SourcesAndHeaders.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/SourcesAndHeaders.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..d7305829a1e2b59d1f566114e17abd3bedfe51fc --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/SourcesAndHeaders.cmake" @@ -0,0 +1,19 @@ +set(sources + # src/tmp.cpp + src/obstacle_map.cpp + src/test_functions.cpp +) + +set(exe_sources + src/main.cpp + ${sources} +) + +set(headers + # include/project/tmp.hpp + include/project/obstacle_map.hpp +) + +set(test_sources + src/tmp_test.cpp +) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StandardSettings.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StandardSettings.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..fd77929987949942b3470fd44b401660baba4e4d --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StandardSettings.cmake" @@ -0,0 +1,95 @@ +# +# Project settings +# + +option(${PROJECT_NAME}_BUILD_EXECUTABLE "Build the project as an executable, rather than a library." OFF) +option(${PROJECT_NAME}_BUILD_HEADERS_ONLY "Build the project as a header-only library." OFF) +option(${PROJECT_NAME}_USE_ALT_NAMES "Use alternative names for the project, such as naming the include directory all lowercase." ON) + +# +# Compiler options +# + +option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF) + +# +# Package managers +# +# Currently supporting: Conan, Vcpkg. + +option(${PROJECT_NAME}_ENABLE_CONAN "Enable the Conan package manager for this project." OFF) +option(${PROJECT_NAME}_ENABLE_VCPKG "Enable the Vcpkg package manager for this project." OFF) + +# +# Unit testing +# +# Currently supporting: GoogleTest, Catch2. + +option(${PROJECT_NAME}_ENABLE_UNIT_TESTING "Enable unit tests for the projects (from the `test` subfolder)." ON) + +option(${PROJECT_NAME}_USE_GTEST "Use the GoogleTest project for creating unit tests." ON) +option(${PROJECT_NAME}_USE_GOOGLE_MOCK "Use the GoogleMock project for extending the unit tests." OFF) + +option(${PROJECT_NAME}_USE_CATCH2 "Use the Catch2 project for creating unit tests." OFF) + +# +# Static analyzers +# +# Currently supporting: Clang-Tidy, Cppcheck. + +option(${PROJECT_NAME}_ENABLE_CLANG_TIDY "Enable static analysis with Clang-Tidy." OFF) +option(${PROJECT_NAME}_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF) + +# +# Code coverage +# + +option(${PROJECT_NAME}_ENABLE_CODE_COVERAGE "Enable code coverage through GCC." OFF) + +# +# Doxygen +# + +option(${PROJECT_NAME}_ENABLE_DOXYGEN "Enable Doxygen documentation builds of source." OFF) + +# +# Miscelanious options +# + +# Generate compile_commands.json for clang based tools +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +option(${PROJECT_NAME}_VERBOSE_OUTPUT "Enable verbose output, allowing for a better understanding of each step taken." ON) +option(${PROJECT_NAME}_GENERATE_EXPORT_HEADER "Create a `project_export.h` file containing all exported symbols." OFF) + +# Export all symbols when building a shared library +if(BUILD_SHARED_LIBS) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) +endif() + +option(${PROJECT_NAME}_ENABLE_LTO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)." OFF) +if(${PROJECT_NAME}_ENABLE_LTO) + include(CheckIPOSupported) + check_ipo_supported(RESULT result OUTPUT output) + if(result) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + message(SEND_ERROR "IPO is not supported: ${output}.") + endif() +endif() + + +option(${PROJECT_NAME}_ENABLE_CCACHE "Enable the usage of Ccache, in order to speed up rebuild times." ON) +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif() + +option(${PROJECT_NAME}_ENABLE_ASAN "Enable Address Sanitize to detect memory error." OFF) +if(${PROJECT_NAME}_ENABLE_ASAN) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StaticAnalyzers.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StaticAnalyzers.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..10e4da4947ec036b1309d29681d1cb28811484d7 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/StaticAnalyzers.cmake" @@ -0,0 +1,20 @@ +if(${PROJECT_NAME}_ENABLE_CLANG_TIDY) + find_program(CLANGTIDY clang-tidy) + if(CLANGTIDY) + set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option) + message("Clang-Tidy finished setting up.") + else() + message(SEND_ERROR "Clang-Tidy requested but executable not found.") + endif() +endif() + +if(${PROJECT_NAME}_ENABLE_CPPCHECK) + find_program(CPPCHECK cppcheck) + if(CPPCHECK) + set(CMAKE_CXX_CPPCHECK ${CPPCHECK} --suppress=missingInclude --enable=all + --inline-suppr --inconclusive -i ${CMAKE_SOURCE_DIR}/imgui/lib) + message("Cppcheck finished setting up.") + else() + message(SEND_ERROR "Cppcheck requested but executable not found.") + endif() +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Utils.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Utils.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..754c7cdf63d19ca710d28994ac7ded233fdc6885 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Utils.cmake" @@ -0,0 +1,40 @@ +# +# Print a message only if the `VERBOSE_OUTPUT` option is on +# + +function(verbose_message content) + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + message(STATUS ${content}) + endif() +endfunction() + +# +# Add a target for formating the project using `clang-format` (i.e: cmake --build build --target clang-format) +# + +function(add_clang_format_target) + if(NOT ${PROJECT_NAME}_CLANG_FORMAT_BINARY) + find_program(${PROJECT_NAME}_CLANG_FORMAT_BINARY clang-format) + endif() + + if(${PROJECT_NAME}_CLANG_FORMAT_BINARY) + if(${PROJECT_NAME}_BUILD_EXECUTABLE) + add_custom_target(clang-format + COMMAND ${${PROJECT_NAME}_CLANG_FORMAT_BINARY} + -i ${exe_sources} ${headers} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) + elseif(${PROJECT_NAME}_BUILD_HEADERS_ONLY) + add_custom_target(clang-format + COMMAND ${${PROJECT_NAME}_CLANG_FORMAT_BINARY} + -i ${headers} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) + else() + add_custom_target(clang-format + COMMAND ${${PROJECT_NAME}_CLANG_FORMAT_BINARY} + -i ${sources} ${headers} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) + endif() + + message(STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n") + endif() +endfunction() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Vcpkg.cmake" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Vcpkg.cmake" new file mode 100644 index 0000000000000000000000000000000000000000..1c13e386a405d05f852ff69ace9abfffaaa30384 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/Vcpkg.cmake" @@ -0,0 +1,20 @@ +if(${PROJECT_NAME}_ENABLE_VCPKG) + # + # If `vcpkg.cmake` (from https://github.com/microsoft/vcpkg) does not exist, download it. + # + if(NOT EXISTS "${CMAKE_BINARY_DIR}/vcpkg.cmake") + message( + STATUS + "Downloading `vcpkg.cmake` from https://github.com/microsoft/vcpkg..." + ) + file(DOWNLOAD "https://github.com/microsoft/vcpkg/raw/master/scripts/buildsystems/vcpkg.cmake" + "${CMAKE_BINARY_DIR}/vcpkg.cmake" + ) + message(STATUS "Vcpkg config downloaded succesfully.") + endif() + + if(${PROJECT_NAME}_VERBOSE_OUTPUT) + set(VCPKG_VERBOSE ON) + endif() + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" "${CMAKE_BINARY_DIR}/vcpkg.cmake") +endif() diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/optimalPathConfig.cmake.in" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/optimalPathConfig.cmake.in" new file mode 100644 index 0000000000000000000000000000000000000000..2ac739c90b98ca8689ad4610652a9b10373675f7 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/optimalPathConfig.cmake.in" @@ -0,0 +1,9 @@ +set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@) + +@PACKAGE_INIT@ + +set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@") + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +check_required_components(@PROJECT_NAME@) diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/version.hpp.in" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/version.hpp.in" new file mode 100644 index 0000000000000000000000000000000000000000..985bad67f624c392b8e6f40e594948b12a9b7eb8 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/cmake/version.hpp.in" @@ -0,0 +1,11 @@ +#ifndef @PROJECT_NAME_UPPERCASE@_VERSION_H_ +#define @PROJECT_NAME_UPPERCASE@_VERSION_H_ + +#define @PROJECT_NAME_UPPERCASE@_VERSION "@PROJECT_VERSION@" + +#define @PROJECT_NAME_UPPERCASE@_MAJOR_VERSION @PROJECT_VERSION_MAJOR@ +#define @PROJECT_NAME_UPPERCASE@_MINOR_VERSION @PROJECT_VERSION_MINOR@ +#define @PROJECT_NAME_UPPERCASE@_PATCH_VERSION @PROJECT_VERSION_PATCH@ + +#endif // @PROJECT_NAME_UPPERCASE@_VERSION_H_ + diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/codecov.yaml" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/codecov.yaml" new file mode 100644 index 0000000000000000000000000000000000000000..b2c991fbb617bd03755cd2f09bc18c66efdafca1 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/codecov.yaml" @@ -0,0 +1,5 @@ +ignore: + - "test" + +comment: + require_changes: true diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/obstacle_map.hpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/obstacle_map.hpp" new file mode 100644 index 0000000000000000000000000000000000000000..f1fada4f7efd641878e680e2bbe041efcb4f6fa7 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/obstacle_map.hpp" @@ -0,0 +1,107 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int WIDTH = 25; // map边长 +const int STRINGLENGTH = 50; // 每行string长度(25 + 24 + 1) +const int directions[3][8] = { { -1, -1, 0, 1, 1, 1, 0, -1 }, + { 0, -1, -1, -1, 0, 1, 1, 1 }, + { 10, 14, 10, 14, 10, 14, 10, 14 } }; // 周围八个方向及cost + +class obstacleMap +{ + public: + struct Node + { + int _row; + int _col; + int G_value; + int H_value; + int F_value; + bool isPath; // is in path + bool isOpen; // is in open_list + bool isBlock; // is in block + Node* fatherNode; + + Node() + : _row(0), + _col(0), + G_value(INT32_MAX), + H_value(INT32_MAX), + F_value(INT32_MAX), + isPath(false), + isOpen(false), + isBlock(false), + fatherNode(nullptr) + { + } + Node(int row, int col, int h, bool isb) + : _row(row), + _col(col), + G_value(INT32_MAX), + H_value(h), + F_value(INT32_MAX), + isPath(false), + isOpen(false), + isBlock(isb), + fatherNode(nullptr) + { + } + Node(int row, int col, int g, int h, int f, bool isp, bool iso, bool isb, Node* fnode) + : _row(row), + _col(col), + G_value(g), + H_value(h), + F_value(f), + isPath(isp), + isOpen(iso), + isBlock(isb), + fatherNode(fnode) + { + } + }; + + using nodeMap = std::vector>; + using strMap = std::vector; + + obstacleMap(bool israndom = false); + obstacleMap(const strMap& input); + ~obstacleMap(); + // void mapReconstruct(const strMap& input); + void toStringMap(strMap& string_map); + bool pathFinding(); + void pathAnnotation(); + void neighbourSearch(Node* tmpNodePtr, Node* nodePtr, int cost); + + private: + nodeMap _map; + std::priority_queue, std::function> _open_list; //(row, col) + std::unordered_set _closed_list; + bool _isAccessible; +}; + +bool isSame(obstacleMap::strMap const& s1, obstacleMap::strMap const& s2); + +bool main_path_finding(bool isCase = true); + +void showStrMap(const obstacleMap::strMap& map); + +bool test_case(const obstacleMap::strMap& originMap, const obstacleMap::strMap& referenceMap); + +void readCases( + const std::string& originPath, + const std::string& refPath, + obstacleMap::strMap& originMap, + obstacleMap::strMap& refMap); \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/tmp.hpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/tmp.hpp" new file mode 100644 index 0000000000000000000000000000000000000000..a7af7aeccb0319a5e20785e2bc15bd132a44330d --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/include/project/tmp.hpp" @@ -0,0 +1,9 @@ +#ifndef TMP_TMP_H_ +#define TMP_TMP_H_ + +namespace tmp +{ + int add(int, int); +} + +#endif // TMP_TMP_H_ diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/obstacle_map.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/obstacle_map.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..be6781bff7170f2f9a0e6d0a57810a883e4b6350 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/obstacle_map.cpp" @@ -0,0 +1,217 @@ +#include "project/obstacle_map.hpp" + +obstacleMap::obstacleMap(bool israndom) : _map(), _open_list(), _closed_list(), _isAccessible(false) +{ + this->_map.resize(WIDTH); // 调用Node默认构造函数 + if (israndom) + { // 生成随机地图 + for (size_t i = 0; i < WIDTH; ++i) + { + for (size_t j = 0; j < WIDTH; ++j) + { + int random = std::rand() % 100; + if (random < 30) + { + this->_map[i].emplace_back(i, j, (i + WIDTH - 1 - j) * 10, true); + } + else + { + this->_map[i].emplace_back(i, j, (i + WIDTH - 1 - j) * 10, false); + } + } + } + } + this->_map[0][WIDTH - 1].isBlock = false; // 起点终点不是障碍 + this->_map[WIDTH - 1][0].isBlock = false; + + auto cmp = [this](const Node* a, const Node* b) { return a->F_value > b->F_value; }; + this->_open_list = std::priority_queue, std::function>(cmp); +} + +obstacleMap::obstacleMap(const obstacleMap::strMap& input) : _map(), _open_list(), _closed_list(), _isAccessible(false) +{ + this->_map.resize(WIDTH); // 先确保有WIDTH行 + for (size_t i = 0; i < WIDTH; ++i) + { + for (size_t j = 0; j < WIDTH; ++j) + { + if (input[i][2 * j] == '$') + { + this->_map[i].emplace_back(i, j, (i + WIDTH - 1 - j) * 10, true); + } + else if (input[i][2 * j] == '*') + { + this->_map[i].emplace_back(i, j, (i + WIDTH - 1 - j) * 10, false); + } + else + { + std::cerr << "错误输入,程序终止" << std::endl; + std::exit(EXIT_FAILURE); + } + } + } + + auto cmp = [this](const Node* a, const Node* b) { return a->F_value > b->F_value; }; + this->_open_list = std::priority_queue, std::function>(cmp); +} + +obstacleMap::~obstacleMap() +{ +} + +// void obstacleMap::mapReconstruct(const obstacleMap::strMap& input) +// { +// for (size_t i = 0; i < WIDTH; ++i) +// { +// for (size_t j = 0; j < WIDTH; ++j) +// { // 每次隔一个空格 +// if (input[i][2 * j] == '$') +// { +// this->_map[i][j].isBlock = true; +// } +// else if (input[i][2 * j] == '*') +// { +// this->_map[i][j].isBlock = false; +// } +// else +// { +// std::cerr << "错误输入,程序终止" << std::endl; +// std::exit(EXIT_FAILURE); +// } +// this->_map[i][j].isPath = false; +// this->_map[i][j].isOpen = false; +// this->_map[i][j].fatherNode = nullptr; +// } +// } +// } + +void obstacleMap::toStringMap(obstacleMap::strMap& string_map) +{ + for (size_t i = 0; i < WIDTH; ++i) + { + string_map.push_back(std::string(STRINGLENGTH - 1, ' ')); // 初始化为空字符串 + for (size_t j = 0; j < WIDTH; j++) + { + if (this->_map[i][j].isPath) + { + string_map[i][j * 2] = '#'; + } + else if (this->_map[i][j].isBlock) + { + string_map[i][j * 2] = '$'; + } + else + { + string_map[i][j * 2] = '*'; + } + } + } +} + +bool obstacleMap::pathFinding() +{ + int row = WIDTH - 1, col = 0; // 当前节点坐标 + this->_open_list.push(&(this->_map[row][col])); // 将起点放入openlist + this->_map[row][col].isOpen = true; + + obstacleMap::Node* nodePtr; + obstacleMap::Node* tmpNodePtr; + while (this->_open_list.empty() != true) + { + nodePtr = this->_open_list.top(); + this->_open_list.pop(); + this->_closed_list.insert(nodePtr); + row = nodePtr->_row; + col = nodePtr->_col; + if (row == 0 && col == WIDTH - 1) + { + return true; + } + int t_row, t_col, cost; // temp row/col + for (int i = 0; i < 8; ++i) + { + t_row = row + directions[0][i]; + t_col = col + directions[1][i]; + cost = directions[2][i]; + if (t_row >= 0 && t_row < WIDTH && t_col >= 0 && t_col < WIDTH) + { + tmpNodePtr = &(this->_map[t_row][t_col]); + if (!(tmpNodePtr->isBlock) && (this->_closed_list.find(tmpNodePtr) == this->_closed_list.end())) + { + obstacleMap::neighbourSearch(tmpNodePtr, nodePtr, cost); + } + } + } + } + return false; +} + +void obstacleMap::pathAnnotation() +{ + std::stack path; + obstacleMap::Node* nodePtr = &(this->_map[0][WIDTH - 1]); + while (nodePtr) + { + path.push(nodePtr); + nodePtr->isPath = true; + nodePtr = nodePtr->fatherNode; + } + std::cout << "The result path is as follows: \n"; + while (!path.empty()) + { + nodePtr = path.top(); + path.pop(); + std::cout << "(" << nodePtr->_row << ", " << nodePtr->_col << ")"; + } + std::cout << "\n"; +} + +void obstacleMap::neighbourSearch(obstacleMap::Node* tmpNodePtr, obstacleMap::Node* nodePtr, int cost) +{ + auto cmp = [this](const Node* a, const Node* b) { return a->F_value > b->F_value; }; + if (tmpNodePtr->isOpen) + { // 在openlist里 + if (tmpNodePtr->G_value > nodePtr->G_value + cost) + { // G值比原来低 + tmpNodePtr->G_value = nodePtr->G_value + cost; + tmpNodePtr->fatherNode = nodePtr; + tmpNodePtr->F_value = tmpNodePtr->G_value + tmpNodePtr->H_value; + std::make_heap( + const_cast(&(this->_open_list.top())), + const_cast(&(this->_open_list.top())) + this->_open_list.size(), + cmp); // 对priority_queue重新排序 + } + } + else + { // 不在openlist里 + tmpNodePtr->fatherNode = nodePtr; + tmpNodePtr->isOpen = true; + tmpNodePtr->G_value = nodePtr->G_value + cost; // 根据父节点初始化G,F值 + tmpNodePtr->F_value = tmpNodePtr->G_value + tmpNodePtr->H_value; + this->_open_list.push(tmpNodePtr); + } + // this->_closed_list.insert(tmpNodePtr); // 无论如何都把closelist状态设为true +} + +bool isSame(obstacleMap::strMap const& s1, obstacleMap::strMap const& s2) +{ + for (size_t i = 0; i < s1.size(); ++i) + { + if (s1[i] != s2[i]) + { + std::cout << "Wrong path in " << i << " row: \n"; + std::cout << "ref: " << s1[i] << std::endl; + std::cout << "our: " << s2[i] << std::endl; + return false; + } + } + return true; +} + +void showStrMap(const obstacleMap::strMap& map) +{ + for (auto& string : map) + { + std::cout << string << std::endl; + } +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/test_functions.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/test_functions.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..4634da6cc82a3cfe07162aef982f70cc212b8ce9 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/test_functions.cpp" @@ -0,0 +1,114 @@ +#include "project/obstacle_map.hpp" + +bool main_path_finding(bool isCase) +{ // 是否使用示例 + srand(static_cast(time(0))); + + if (isCase) + { // 使用默认示例 + std::vector> pathList{ + { "./test/test_case/origin1.txt", "./test/test_case/ref1.txt" }, + { "./test/test_case/origin2.txt", "./test/test_case/ref2.txt" }, + { "./test/test_case/origin3.txt", "./test/test_case/ref3.txt" } + }; + for (int i = 0; i < pathList.size(); ++i) + { + const std::string orginpath = pathList[i][0]; + const std::string refpath = pathList[i][1]; + obstacleMap::strMap originMap; + obstacleMap::strMap referenceMap; + readCases(orginpath, refpath, originMap, referenceMap); + std::cout << "Start Standard test " << i + 1 << ":\n"; + if (test_case(originMap, referenceMap) == false) + { + return false; + } + } + return true; + } + else // 使用随机生成的map + { + obstacleMap map(true); + obstacleMap::strMap temp; + map.toStringMap(temp); + + std::cout << "Origin Map:\n"; + showStrMap(temp); + if (map.pathFinding()) + { + map.pathAnnotation(); + } + else + { + std::cout << "there is no accessible path!" << std::endl; + return false; + } + obstacleMap::strMap resultMap; + map.toStringMap(resultMap); + std::cout << "The map and its result path are as follows:\n"; + showStrMap(resultMap); + } + return true; +} + +bool test_case(const obstacleMap::strMap& originMap, const obstacleMap::strMap& referenceMap) +{ + std::cout << "Origin Map:\n"; + showStrMap(originMap); + + obstacleMap map(originMap); + if (map.pathFinding()) + { + map.pathAnnotation(); + } + else + { + std::cout << "there is no accessible path!" << std::endl; + return false; + } + + obstacleMap::strMap resultMap; + map.toStringMap(resultMap); + + std::cout << "The map and its result path are as follows:\n"; + showStrMap(resultMap); + + return isSame(referenceMap, resultMap); +} + +void readCases( + const std::string& originPath, + const std::string& refPath, + obstacleMap::strMap& originMap, + obstacleMap::strMap& refMap) +{ + std::ifstream originFile(originPath); + std::ifstream refFile(refPath); + if (originFile.is_open()) + { + std::string line; + while (std::getline(originFile, line)) + { + originMap.push_back(line); + } + originFile.close(); + } + else + { + std::cerr << "无法打开文件: " << originPath << std::endl; + } + + if (refFile.is_open()) + { + std::string line; + while (std::getline(refFile, line)) + { + refMap.push_back(line); + } + refFile.close(); + } + else + { + std::cerr << "无法打开文件: " << refPath << std::endl; + } +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/tmp.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/tmp.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..7a4f8fe3b20dd0805502f80659be042b8e41e2af --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/src/tmp.cpp" @@ -0,0 +1,3 @@ +#include "project/tmp.hpp" + +int tmp::add(int a, int b) { return a + b; } diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/CMakeLists.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/CMakeLists.txt" new file mode 100644 index 0000000000000000000000000000000000000000..71f07af2a353861b4faab9979b35de8918a70c22 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/CMakeLists.txt" @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.15) + +# +# Project details +# + +project( + ${CMAKE_PROJECT_NAME}Tests + LANGUAGES CXX +) + +verbose_message("Adding tests under ${CMAKE_PROJECT_NAME}Tests...") + +foreach(file ${test_sources}) + string(REGEX REPLACE "(.*/)([a-zA-Z0-9_ ]+)(\.cpp)" "\\2" test_name ${file}) + add_executable(${test_name}_Tests ${file}) + + # + # Set the compiler standard + # + + target_compile_features(${test_name}_Tests PUBLIC cxx_std_17) + + # + # Setup code coverage if enabled + # + + if (${CMAKE_PROJECT_NAME}_ENABLE_CODE_COVERAGE) + target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC -O0 -g -fprofile-arcs -ftest-coverage) + target_link_options(${CMAKE_PROJECT_NAME} PUBLIC -fprofile-arcs -ftest-coverage) + verbose_message("Code coverage is enabled and provided with GCC.") + endif() + + # + # Load the desired unit testing framework + # + # Currently supported: GoogleTest (and GoogleMock), Catch2. + + if(${CMAKE_PROJECT_NAME}_BUILD_EXECUTABLE) + set(${CMAKE_PROJECT_NAME}_TEST_LIB ${CMAKE_PROJECT_NAME}_LIB) + else() + set(${CMAKE_PROJECT_NAME}_TEST_LIB ${CMAKE_PROJECT_NAME}) + endif() + + if(${CMAKE_PROJECT_NAME}_USE_GTEST) + find_package(GTest REQUIRED) + + if(${CMAKE_PROJECT_NAME}_USE_GOOGLE_MOCK) + set(GOOGLE_MOCK_LIBRARIES GTest::gmock GTest::gmock_main) + endif() + + target_link_libraries( + ${test_name}_Tests + PUBLIC + GTest::GTest + GTest::Main + ${GOOGLE_MOCK_LIBRARIES} + ${${CMAKE_PROJECT_NAME}_TEST_LIB} + ) + elseif(${CMAKE_PROJECT_NAME}_USE_CATCH2) + find_package(Catch2 REQUIRED) + target_link_libraries( + ${test_name}_Tests + PUBLIC + Catch2::Catch2 + ${${CMAKE_PROJECT_NAME}_TEST_LIB} + ) + else() + message(FATAL_ERROR "Unknown testing library. Please setup your desired unit testing library by using `target_link_libraries`.") + endif() + + # + # Add the unit tests + # + + add_test( + NAME + ${test_name} + COMMAND + ${test_name}_Tests + ) +endforeach() + +verbose_message("Finished adding unit tests for ${CMAKE_PROJECT_NAME}.") diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/src/tmp_test.cpp" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/src/tmp_test.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..500f88573ec5a13d99b3a72781b9288705513abe --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/src/tmp_test.cpp" @@ -0,0 +1,25 @@ +#include + +#include "project/obstacle_map.hpp" + +// TEST(TmpAddTest, CheckValues) +// { +// ASSERT_EQ(tmp::add(1, 2), 3); +// EXPECT_TRUE(true); +// } + +TEST(PathFindTest, StandardMap) +{ + EXPECT_TRUE(main_path_finding()); +} + +TEST(PathFindTest, RandomMap) +{ + EXPECT_TRUE(main_path_finding(false)); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin1.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin1.txt" new file mode 100644 index 0000000000000000000000000000000000000000..c3b154254c77579519aa0b4d72677968ab3edc14 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin1.txt" @@ -0,0 +1,25 @@ +$ $ $ * * $ * * * * * * $ $ * * * * $ * * * $ * * +$ * * * $ * * * * * * * * $ * * * * * * $ $ * * * +* * * $ $ $ * * * $ * $ * * * * * * * * * $ * * $ +* $ $ * * * $ * $ * * $ * $ * * * $ * * * $ * * * +* $ * $ * * $ * * * * $ * * * * * * * * * * * $ * +* * * * * $ $ * * * * * * * * $ * * * * $ * * $ $ +* $ * $ $ * * * * $ $ * * * * * * $ * $ $ * * $ $ +* $ $ * * $ $ * * $ * * * * $ $ $ * * $ * $ * * * +* $ $ * $ * * * * * * $ $ * * * $ * * $ * * $ * * +* * * $ $ * * * * * $ $ * * * * * $ * $ * * $ $ * +$ * * * $ * $ * * * * * * $ * * * * * * * * * * $ +$ * $ * * * $ * * $ * $ * * * * * $ * * $ * * * $ +$ $ $ $ * * $ * * * * * $ * * * * $ * * $ * * * * +$ * * * * * $ $ $ * $ * $ * * $ * * * $ $ * * $ * +* $ * * * $ * * * * * $ * $ * * * $ * * * * * $ * +* * * $ * $ * * * $ $ * $ * $ * * * $ * $ $ * $ $ +$ * $ $ * $ * * * * * * * $ * * $ * * * * * * * $ +$ $ * * $ * * * $ * * $ * * * $ * $ * * * * $ $ $ +* * $ $ $ * $ * * $ * * * * * * * * * $ * * $ * * +* * * * * * * * $ $ * $ * * $ * $ * * $ * * * $ * +* * $ * * * * $ * $ $ * * * * * * $ * * * * * * * +* * * $ * * * * $ * * * $ * $ * * $ $ * $ * $ $ * +* * * $ $ * * * * * * $ * * $ * * $ * * $ * * $ $ +$ $ * * * $ $ * $ * * $ $ * $ * * $ * * * * $ * * +* * $ * $ * * * * * $ * * $ $ * $ * * * $ * $ * * \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin2.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin2.txt" new file mode 100644 index 0000000000000000000000000000000000000000..2a7bae42872cacc46558ddaab58184432beb08e7 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin2.txt" @@ -0,0 +1,25 @@ +$ * $ * * $ * * * * * * * $ * $ * * * $ $ * * * * +* * * $ * * * $ * * * $ * * * $ $ * * * * * $ * * +* * * * * * $ * * * * $ * * * * $ * * $ * * $ * * +$ * $ * * $ * $ $ * * $ * $ $ * * $ $ $ $ $ * * $ +* $ * * $ $ $ $ $ * * * * * $ * * * * * $ * * * $ +* * * * * $ * * $ * * $ $ * $ * * $ * * * * * $ * +* * $ * * $ * * $ * $ $ * * * * * * $ * * * * * $ +* * $ * * $ * * $ * * * * $ * * * $ * $ * * $ $ $ +* * * * * * * * * * * * $ * $ * * * * $ * $ * * $ +$ * $ $ $ $ * * * * * $ $ $ * * * * * $ $ * * * * +$ * $ * * $ * $ * * * * * * * * * * * * * * * $ $ +* * $ $ * * * * $ * * * $ $ * * * * * * * * $ * * +$ * * $ * * $ * $ * * $ $ * * $ * * $ * * $ * $ $ +* * * $ * $ $ $ * * * * * $ * * $ * * $ $ $ * * $ +* * * * $ * * $ * * $ * $ * * * * * $ $ * * $ * * +* * * * * $ * * * $ * $ * * * * * * * * * * * * * +$ * * * * $ $ * * * $ * $ $ $ * * * * * $ $ * * * +* $ $ * $ * $ $ * * * $ * $ * $ * $ $ $ * * * $ * +* * * * * * * $ $ * * * * * * * $ * * * * $ * * * +$ $ $ * $ * * * * * * * * $ * * * $ * * * * $ * * +$ * * $ $ * $ * $ $ * $ * $ $ $ * * * * * * * * * +* * $ * $ $ * $ * $ * * $ * $ * * * * * * * * * * +$ * $ * $ $ * * * * * * $ * * $ $ * * * * * * * $ +* * $ * $ * * * * $ * $ $ $ * * * $ $ $ * * * $ * +* * $ * * * * $ * * $ * * $ * $ $ $ * $ * * * $ * \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin3.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin3.txt" new file mode 100644 index 0000000000000000000000000000000000000000..fb8c5c87cf0a275169280c09632848252147a1ed --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/origin3.txt" @@ -0,0 +1,25 @@ +* $ * * $ * * * * * $ * * * * * $ $ $ * * * * * * +* $ * $ * $ $ * * $ * * * * $ * * $ * * * * * $ $ +* * * * * $ $ * $ $ $ * * * $ * * $ * * * * * * * +* * * * $ * $ * * * * * * * $ $ * $ * * $ $ * * $ +* * * $ * * $ * * * * * * $ $ * $ $ * * * $ * $ * +* * * * * $ * * * $ * * * * * $ $ * * * $ * * * $ +$ * * * $ * * * * * * $ * * * $ * * * * $ $ $ $ * +* * $ * * $ $ * * * * * * $ * $ $ * $ * * * * * * +* * * * * $ * * * $ $ * * * * * $ $ * * * $ * * * +* * * * $ $ * * * * $ $ * * * $ * $ $ $ $ $ $ $ $ +* * * $ $ * $ * * * * * * $ $ $ * $ * * * $ * * * +* * $ $ * * * * * * * $ * * $ $ * * * * $ $ * * $ +* * * $ * $ * $ * $ $ * * * $ * * * $ * * * $ $ $ +$ * * * * $ * * * * $ $ * * * * * * * * $ * * * * +* * * $ * * $ $ * * $ $ * * * * * $ * * $ $ * * $ +* * * * * * * $ $ $ * * $ $ * $ * * * $ * $ $ * * +* * * * * * * * * * * * * * * * * * * * $ * $ * * +* * * * * * * * * $ * * $ $ * * * * * * * * $ $ * +* * * $ $ $ * $ * * * * * * * * * $ $ * * * $ * $ +* $ * * $ $ * $ * * * * $ * * $ * * * * * * * $ $ +$ * $ * $ * * $ $ * * $ * $ * * * * $ * $ * $ * * +$ * * $ $ $ * * $ * * * * * * $ * * $ * * $ * * * +* $ * * $ $ * $ * $ * * * $ * * * * * * $ $ * * $ +$ $ * $ * * * $ * * $ * * * * * * * $ $ * * $ $ * +* * * * * * $ * * * $ * * * * * $ $ * * $ * * $ * \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref1.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref1.txt" new file mode 100644 index 0000000000000000000000000000000000000000..d9878da0423242c39241a6a85557a8c3589d1a08 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref1.txt" @@ -0,0 +1,25 @@ +$ $ $ * * $ * * * * * * $ $ * * * * $ # # # $ # # +$ * * * $ * * * * * * * * $ * * * * # * $ $ # * * +* * * $ $ $ * * * $ * $ * * * * * # * * * $ * * $ +* $ $ * * * $ * $ * * $ * $ * * # $ * * * $ * * * +* $ * $ * * $ * * * * $ * * * # * * * * * * * $ * +* * * * * $ $ * * * * * * * # $ * * * * $ * * $ $ +* $ * $ $ * * * * $ $ * * * # * * $ * $ $ * * $ $ +* $ $ * * $ $ * * $ * * * # $ $ $ * * $ * $ * * * +* $ $ * $ * * * * * * $ $ # * * $ * * $ * * $ * * +* * * $ $ * * * * * $ $ # * * * * $ * $ * * $ $ * +$ * * * $ * $ * * * * # * $ * * * * * * * * * * $ +$ * $ * * * $ * * $ # $ * * * * * $ * * $ * * * $ +$ $ $ $ * * $ * * * # * $ * * * * $ * * $ * * * * +$ * * * * * $ $ $ # $ * $ * * $ * * * $ $ * * $ * +* $ * * * $ * * * # * $ * $ * * * $ * * * * * $ * +* * * $ * $ * * # $ $ * $ * $ * * * $ * $ $ * $ $ +$ * $ $ * $ * # * * * * * $ * * $ * * * * * * * $ +$ $ * * $ * # * $ * * $ * * * $ * $ * * * * $ $ $ +* * $ $ $ # $ * * $ * * * * * * * * * $ * * $ * * +* * * * # * * * $ $ * $ * * $ * $ * * $ * * * $ * +* * $ # * * * $ * $ $ * * * * * * $ * * * * * * * +* * # $ * * * * $ * * * $ * $ * * $ $ * $ * $ $ * +* * # $ $ * * * * * * $ * * $ * * $ * * $ * * $ $ +$ $ # * * $ $ * $ * * $ $ * $ * * $ * * * * $ * * +# # $ * $ * * * * * $ * * $ $ * $ * * * $ * $ * * \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref2.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref2.txt" new file mode 100644 index 0000000000000000000000000000000000000000..34fc32d2b4fc4580e0e5c3d66c530f0caa69d5a2 --- /dev/null +++ "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref2.txt" @@ -0,0 +1,25 @@ +$ * $ * * $ * * * * * * * $ * $ * * * $ $ # # # # +* * * $ * * * $ * * * $ * * * $ $ * # # # * $ * * +* * * * * * $ * * * * $ * # # # $ # * $ * * $ * * +$ * $ * * $ * $ $ * * $ # $ $ * # $ $ $ $ $ * * $ +* $ * * $ $ $ $ $ * * # * * $ * * * * * $ * * * $ +* * * * * $ * * $ * # $ $ * $ * * $ * * * * * $ * +* * $ * * $ * * $ # $ $ * * * * * * $ * * * * * $ +* * $ * * $ * * $ # * * * $ * * * $ * $ * * $ $ $ +* * * * * * * * # * * * $ * $ * * * * $ * $ * * $ +$ * $ $ $ $ * # * * * $ $ $ * * * * * $ $ * * * * +$ * $ * * $ # $ * * * * * * * * * * * * * * * $ $ +* * $ $ * * # * $ * * * $ $ * * * * * * * * $ * * +$ * * $ * # $ * $ * * $ $ * * $ * * $ * * $ * $ $ +* * * $ # $ $ $ * * * * * $ * * $ * * $ $ $ * * $ +* * * # $ * * $ * * $ * $ * * * * * $ $ * * $ * * +* * * # * $ * * * $ * $ * * * * * * * * * * * * * +$ * * # * $ $ * * * $ * $ $ $ * * * * * $ $ * * * +* $ $ # $ * $ $ * * * $ * $ * $ * $ $ $ * * * $ * +* * * # * * * $ $ * * * * * * * $ * * * * $ * * * +$ $ $ # $ * * * * * * * * $ * * * $ * * * * $ * * +$ * # $ $ * $ * $ $ * $ * $ $ $ * * * * * * * * * +* # $ * $ $ * $ * $ * * $ * $ * * * * * * * * * * +$ # $ * $ $ * * * * * * $ * * $ $ * * * * * * * $ +* # $ * $ * * * * $ * $ $ $ * * * $ $ $ * * * $ * +# * $ * * * * $ * * $ * * $ * $ $ $ * $ * * * $ * \ No newline at end of file diff --git "a/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref3.txt" "b/C++/codes/2024-07/\351\273\204\345\261\261/optimal_path/test/test_case/ref3.txt" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391