From ea1c3737f2785ce1100d26d01266568538366a33 Mon Sep 17 00:00:00 2001 From: Przemek Pawlas <3606072+Destroy666x@users.noreply.github.com> Date: Sun, 3 Dec 2023 21:35:40 +0100 Subject: [PATCH] Switch to C++23 standard and using enum/designated initializers --- .clang-format | 6 +++--- .github/scripts/check-format.sh | 12 ++++++------ .github/workflows/main.yml | 2 +- CMakeLists.txt | 6 +++--- src/macro-core/macro-action-clipboard.cpp | 9 +++++---- src/macro-core/macro-action-media.cpp | 17 +++++++++-------- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.clang-format b/.clang-format index c9dfc48e9..6dabf4de0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,6 @@ -# please use clang-format version 8 or later +# please use clang-format version 15 or later -Standard: Cpp11 +Standard: c++20 AccessModifierOffset: -8 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false @@ -53,7 +53,7 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false FixNamespaceComments: false -ForEachMacros: +ForEachMacros: - 'json_object_foreach' - 'json_object_foreach_safe' - 'json_array_foreach' diff --git a/.github/scripts/check-format.sh b/.github/scripts/check-format.sh index 2ea193414..2b976d19b 100755 --- a/.github/scripts/check-format.sh +++ b/.github/scripts/check-format.sh @@ -26,18 +26,18 @@ elif [[ ${OS} = "Darwin" ]] ; then fi # Discover clang-format -if type clang-format-13 2> /dev/null ; then - CLANG_FORMAT=clang-format-13 +if type clang-format-15 2> /dev/null ; then + CLANG_FORMAT=clang-format-15 elif type clang-format 2> /dev/null ; then # Clang format found, but need to check version CLANG_FORMAT=clang-format V=$(clang-format --version) - if [[ $V != *"version 13.0"* ]]; then - echo "clang-format is not 13.0 (returned ${V})" + if [[ $V != *"version 15.0"* ]]; then + echo "clang-format is not 15.0 (returned ${V})" exit 1 fi else - echo "No appropriate clang-format found (expected clang-format-13.0.0, or clang-format)" + echo "No appropriate clang-format found (expected clang-format-15.0.0, or clang-format)" exit 1 fi @@ -57,4 +57,4 @@ find . -type d \( \ -name '*.mm' -or \ -name '*.c' -or \ -name '*.cpp' \ - | xargs -L100 -P ${NPROC} "${CLANG_FORMAT}" ${VERBOSITY} -i -style=file -fallback-style=none + | xargs -L100 -P ${NPROC} "${CLANG_FORMAT}" ${VERBOSITY} -style=file -fallback-style=none --dry-run --Werror diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01cfb7384..e170cf63e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: submodules: recursive - name: Install clang-format - run: sudo apt-get install -y clang-format-13 + run: sudo apt-get install -y clang-format-15 - name: Run clang-format run: ./.github/scripts/check-format.sh && ./.github/scripts/check-changes.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ea86f78a..f01809372 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16.3) +cmake_minimum_required(VERSION 3.22) project(advanced-scene-switcher VERSION 1.0.0) set(LIB_NAME "${PROJECT_NAME}-lib") @@ -375,8 +375,8 @@ set_target_properties( AUTORCC ON AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/forms") -target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) -target_compile_features(${LIB_NAME} PUBLIC cxx_std_17) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) +target_compile_features(${LIB_NAME} PUBLIC cxx_std_23) add_definitions(-DASIO_STANDALONE) target_include_directories( diff --git a/src/macro-core/macro-action-clipboard.cpp b/src/macro-core/macro-action-clipboard.cpp index b58d8ef7e..43c6d562e 100644 --- a/src/macro-core/macro-action-clipboard.cpp +++ b/src/macro-core/macro-action-clipboard.cpp @@ -96,14 +96,15 @@ static void copyImageFromUrl(void *param) bool MacroActionClipboard::PerformAction() { switch (_action) { - case Action::COPY_TEXT: { - ClipboardTextQueueParams params{"", "", _text}; + using enum Action; + case COPY_TEXT: { + ClipboardTextQueueParams params{.text = _text}; obs_queue_task(OBS_TASK_UI, copyText, ¶ms, true); SetTempVarValues(params); break; } - case Action::COPY_IMAGE: { - ClipboardImageQueueParams params{"", "", _url}; + case COPY_IMAGE: { + ClipboardImageQueueParams params{.url = _url}; obs_queue_task(OBS_TASK_UI, copyImageFromUrl, ¶ms, true); SetTempVarValues(params); break; diff --git a/src/macro-core/macro-action-media.cpp b/src/macro-core/macro-action-media.cpp index 2a5158983..c13d613fd 100644 --- a/src/macro-core/macro-action-media.cpp +++ b/src/macro-core/macro-action-media.cpp @@ -48,7 +48,8 @@ bool MacroActionMedia::PerformAction() obs_media_state state = obs_source_media_get_state(source); switch (_action) { - case Action::PLAY: + using enum Action; + case PLAY: if (state == OBS_MEDIA_STATE_STOPPED || state == OBS_MEDIA_STATE_ENDED) { obs_source_media_restart(source); @@ -56,25 +57,25 @@ bool MacroActionMedia::PerformAction() obs_source_media_play_pause(source, false); } break; - case Action::PAUSE: + case PAUSE: obs_source_media_play_pause(source, true); break; - case Action::STOP: + case STOP: obs_source_media_stop(source); break; - case Action::RESTART: + case RESTART: obs_source_media_restart(source); break; - case Action::NEXT: + case NEXT: obs_source_media_next(source); break; - case Action::PREVIOUS: + case PREVIOUS: obs_source_media_previous(source); break; - case Action::SEEK_DURATION: + case SEEK_DURATION: obs_source_media_set_time(source, _seekDuration.Milliseconds()); break; - case Action::SEEK_PERCENTAGE: + case SEEK_PERCENTAGE: SeekToPercentage(source); break; default: