Skip to content

Commit

Permalink
Switch to C++20 standard and using enum/designated initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Destroy666x committed Dec 4, 2023
1 parent 99a0118 commit 22cdfc7
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 431 deletions.
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -53,7 +53,7 @@ Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
FixNamespaceComments: false
ForEachMacros:
ForEachMacros:
- 'json_object_foreach'
- 'json_object_foreach_safe'
- 'json_array_foreach'
Expand Down
11 changes: 0 additions & 11 deletions .github/scripts/check-changes.sh

This file was deleted.

12 changes: 6 additions & 6 deletions .github/scripts/check-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ 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
run: ./.github/scripts/check-format.sh

- name: Install cmake-format
run: sudo pip install cmakelang
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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_20)
target_compile_features(${LIB_NAME} PUBLIC cxx_std_20)

add_definitions(-DASIO_STANDALONE)
target_include_directories(
Expand Down
9 changes: 5 additions & 4 deletions src/macro-core/macro-action-clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params, 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, &params, true);
SetTempVarValues(params);
break;
Expand Down
17 changes: 9 additions & 8 deletions src/macro-core/macro-action-media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,34 @@ 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);
} else {
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:
Expand Down
Loading

0 comments on commit 22cdfc7

Please sign in to comment.