Skip to content

Commit 5e068be

Browse files
committed
Fix remaining Sonar Scanner code quality issues
1 parent 722592d commit 5e068be

43 files changed

Lines changed: 687 additions & 654 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Apps/05-Typography/TypographyAppController.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,40 @@ void TypographyAppController::OnKeyboardStateAction(TypographyAppAction action)
5050

5151
switch(action)
5252
{
53-
case TypographyAppAction::SwitchTextWrapMode:
53+
using enum TypographyAppAction;
54+
55+
case SwitchTextWrapMode:
5456
text_layout.wrap = magic_enum::enum_value<gui::Text::Wrap>(
5557
(magic_enum::enum_integer(text_layout.wrap) + 1) % magic_enum::enum_count<gui::Text::Wrap>());
5658
m_typography_app.SetTextLayout(text_layout);
5759
break;
5860

59-
case TypographyAppAction::SwitchTextHorizontalAlignment:
61+
case SwitchTextHorizontalAlignment:
6062
text_layout.horizontal_alignment = magic_enum::enum_value<gui::Text::HorizontalAlignment>(
6163
(magic_enum::enum_integer(text_layout.horizontal_alignment) + 1) % magic_enum::enum_count<gui::Text::HorizontalAlignment>());
6264
m_typography_app.SetTextLayout(text_layout);
6365
break;
6466

65-
case TypographyAppAction::SwitchTextVerticalAlignment:
67+
case SwitchTextVerticalAlignment:
6668
text_layout.vertical_alignment = magic_enum::enum_value<gui::Text::VerticalAlignment>(
6769
(magic_enum::enum_integer(text_layout.vertical_alignment) + 1) % magic_enum::enum_count<gui::Text::VerticalAlignment>());
6870
m_typography_app.SetTextLayout(text_layout);
6971
break;
7072

71-
case TypographyAppAction::SwitchIncrementalTextUpdate:
73+
case SwitchIncrementalTextUpdate:
7274
m_typography_app.SetIncrementalTextUpdate(!m_typography_app.GetSettings().is_incremental_text_update);
7375
break;
7476

75-
case TypographyAppAction::SwitchTypingDirection:
77+
case SwitchTypingDirection:
7678
m_typography_app.SetForwardTypingDirection(!m_typography_app.GetSettings().is_forward_typing_direction);
7779
break;
7880

79-
case TypographyAppAction::SpeedupTyping:
81+
case SpeedupTyping:
8082
m_typography_app.SetTextUpdateInterval(
8183
std::max(s_text_update_interval_delta, m_typography_app.GetSettings().typing_update_interval_sec - s_text_update_interval_delta));
8284
break;
8385

84-
case TypographyAppAction::SlowdownTyping:
86+
case SlowdownTyping:
8587
m_typography_app.SetTextUpdateInterval( m_typography_app.GetSettings().typing_update_interval_sec + s_text_update_interval_delta);
8688
break;
8789

@@ -95,13 +97,14 @@ std::string TypographyAppController::GetKeyboardActionName(TypographyAppAction a
9597
META_FUNCTION_TASK();
9698
switch(action)
9799
{
98-
case TypographyAppAction::SwitchTextWrapMode: return "switch text wrap mode";
99-
case TypographyAppAction::SwitchTextHorizontalAlignment: return "switch horizontal text alignment";
100-
case TypographyAppAction::SwitchTextVerticalAlignment: return "switch vertical text alignment";
101-
case TypographyAppAction::SwitchIncrementalTextUpdate: return "switch incremental text update";
102-
case TypographyAppAction::SwitchTypingDirection: return "switch typing direction";
103-
case TypographyAppAction::SpeedupTyping: return "speedup typing";
104-
case TypographyAppAction::SlowdownTyping: return "slowdown typing";
100+
using enum TypographyAppAction;
101+
case SwitchTextWrapMode: return "switch text wrap mode";
102+
case SwitchTextHorizontalAlignment: return "switch horizontal text alignment";
103+
case SwitchTextVerticalAlignment: return "switch vertical text alignment";
104+
case SwitchIncrementalTextUpdate: return "switch incremental text update";
105+
case SwitchTypingDirection: return "switch typing direction";
106+
case SpeedupTyping: return "speedup typing";
107+
case SlowdownTyping: return "slowdown typing";
105108
default: META_UNEXPECTED_RETURN(action, "");
106109
}
107110
}

Apps/07-ParallelRendering/ParallelRenderingApp.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ class ParallelRenderingApp final // NOSONAR - destructor required
7171
uint32_t render_thread_count = std::thread::hardware_concurrency();
7272
bool parallel_rendering_enabled = true;
7373

74-
friend bool operator==(const Settings& left, const Settings& right) noexcept
75-
{
76-
return std::tie(left.cubes_grid_size, left.render_thread_count, left.parallel_rendering_enabled) ==
77-
std::tie(right.cubes_grid_size, right.render_thread_count, right.parallel_rendering_enabled);
78-
}
74+
friend bool operator==(const Settings& left, const Settings& right) noexcept = default;
7975

8076
uint32_t GetTotalCubesCount() const noexcept;
8177
uint32_t GetActiveRenderThreadCount() const noexcept;

Apps/07-ParallelRendering/ParallelRenderingAppController.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,25 @@ void ParallelRenderingAppController::OnKeyboardStateAction(ParallelRenderingAppA
4848

4949
switch(action)
5050
{
51-
case ParallelRenderingAppAction::SwitchParallelRendering:
51+
using enum ParallelRenderingAppAction;
52+
53+
case SwitchParallelRendering:
5254
app_settings.parallel_rendering_enabled = !app_settings.parallel_rendering_enabled;
5355
break;
5456

55-
case ParallelRenderingAppAction::IncreaseCubesGridSize:
57+
case IncreaseCubesGridSize:
5658
app_settings.cubes_grid_size++;
5759
break;
5860

59-
case ParallelRenderingAppAction::DecreaseCubesGridSize:
61+
case DecreaseCubesGridSize:
6062
app_settings.cubes_grid_size = std::max(2U, app_settings.cubes_grid_size - 1U);
6163
break;
6264

63-
case ParallelRenderingAppAction::IncreaseRenderThreadsCount:
65+
case IncreaseRenderThreadsCount:
6466
app_settings.render_thread_count++;
6567
break;
6668

67-
case ParallelRenderingAppAction::DecreaseRenderThreadsCount:
69+
case DecreaseRenderThreadsCount:
6870
app_settings.render_thread_count = std::min(std::max(2U, app_settings.render_thread_count - 1U), app_settings.GetTotalCubesCount());
6971
break;
7072

@@ -79,11 +81,12 @@ std::string ParallelRenderingAppController::GetKeyboardActionName(ParallelRender
7981
{
8082
switch(action)
8183
{
82-
case ParallelRenderingAppAction::SwitchParallelRendering: return "switch parallel rendering";
83-
case ParallelRenderingAppAction::IncreaseCubesGridSize: return "increase cubes grid size";
84-
case ParallelRenderingAppAction::DecreaseCubesGridSize: return "decrease cubes grid size";
85-
case ParallelRenderingAppAction::IncreaseRenderThreadsCount: return "increase render threads count";
86-
case ParallelRenderingAppAction::DecreaseRenderThreadsCount: return "decrease render threads count";
84+
using enum ParallelRenderingAppAction;
85+
case SwitchParallelRendering: return "switch parallel rendering";
86+
case IncreaseCubesGridSize: return "increase cubes grid size";
87+
case DecreaseCubesGridSize: return "decrease cubes grid size";
88+
case IncreaseRenderThreadsCount: return "increase render threads count";
89+
case DecreaseRenderThreadsCount: return "decrease render threads count";
8790
default: META_UNEXPECTED_RETURN(action, "");
8891
}
8992
}

Modules/Common/Primitives/Include/Methane/Checks.hpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,20 @@ Methane short check macroses throwing exceptions on negative check result
3939

4040
#include "Exceptions.hpp"
4141

42-
#ifndef __FUNCTION_NAME__
43-
#ifdef WIN32
44-
#define __FUNCTION_NAME__ __FUNCTION__
45-
#else
46-
#define __FUNCTION_NAME__ __func__
47-
#endif
48-
#endif
49-
5042
#ifdef METHANE_CHECKS_ENABLED
5143

5244
#define META_INVALID_ARG_DESCR(argument, description, ...) \
53-
throw Methane::InvalidArgumentException<std::decay_t<decltype(argument)>>(__FUNCTION_NAME__, #argument, argument, fmt::format(description, ## __VA_ARGS__))
45+
throw Methane::InvalidArgumentException<std::decay_t<decltype(argument)>>(std::source_location::current(), #argument, argument, fmt::format(description, ## __VA_ARGS__))
5446

5547
#define META_CHECK_DESCR(argument, condition, description, ...) \
5648
if (!(condition)) \
57-
throw Methane::InvalidArgumentException<std::decay_t<decltype(argument)>>(__FUNCTION_NAME__, #argument, argument, fmt::format(description, ## __VA_ARGS__))
49+
throw Methane::InvalidArgumentException<std::decay_t<decltype(argument)>>(std::source_location::current(), #argument, argument, fmt::format(description, ## __VA_ARGS__))
5850

5951
#define META_CHECK(argument, condition) META_CHECK_DESCR(argument, condition, #condition)
6052

6153
#define META_CHECK_NAME_DESCR(argument_name, condition, description, ...) \
6254
if (!(condition)) \
63-
throw Methane::InvalidArgumentException<bool>(__FUNCTION_NAME__, argument_name, fmt::format(description, ## __VA_ARGS__))
55+
throw Methane::InvalidArgumentException<bool>(std::source_location::current(), argument_name, fmt::format(description, ## __VA_ARGS__))
6456

6557
#define META_CHECK_NAME(argument_name, condition) META_CHECK_NAME_DESCR(argument_name, condition, #condition)
6658

@@ -76,73 +68,73 @@ Methane short check macroses throwing exceptions on negative check result
7668

7769
#define META_CHECK_RANGE_DESCR(argument, range_begin, range_end, description, ...) \
7870
if (argument < static_cast<std::decay_t<decltype(argument)>>(range_begin) || argument >= static_cast<std::decay_t<decltype(argument)>>(range_end)) \
79-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(range_begin)>>(__FUNCTION_NAME__, #argument, argument, \
71+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(range_begin)>>(std::source_location::current(), #argument, argument, \
8072
{ range_begin, static_cast<std::decay_t<decltype(range_begin)>>(range_end) }, false, fmt::format(description, ## __VA_ARGS__))
8173

8274
#define META_CHECK_RANGE(argument, range_begin, range_end) META_CHECK_RANGE_DESCR(argument, range_begin, range_end, "")
8375

8476
#define META_CHECK_RANGE_INC_DESCR(argument, range_begin, range_end, description, ...) \
8577
if (argument < static_cast<std::decay_t<decltype(argument)>>(range_begin) || argument > static_cast<std::decay_t<decltype(argument)>>(range_end)) \
86-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(range_begin)>>(__FUNCTION_NAME__, #argument, argument, \
78+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(range_begin)>>(std::source_location::current(), #argument, argument, \
8779
{ range_begin, static_cast<std::decay_t<decltype(range_begin)>>(range_end) }, true, fmt::format(description, ## __VA_ARGS__))
8880

8981
#define META_CHECK_INC_RANGE(argument, range_begin, range_end) META_CHECK_RANGE_INC_DESCR(argument, range_begin, range_end, "")
9082

9183
#define META_CHECK_LESS_DESCR(argument, upper_limit, description, ...) \
9284
if (argument >= static_cast<std::decay_t<decltype(argument)>>(upper_limit)) \
93-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(upper_limit)>>(__FUNCTION_NAME__, #argument, argument, \
85+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(upper_limit)>>(std::source_location::current(), #argument, argument, \
9486
{ std::numeric_limits<std::decay_t<decltype(upper_limit)>>::min(), upper_limit }, false, fmt::format(description, ## __VA_ARGS__))
9587

9688
#define META_CHECK_LESS(argument, upper_limit) META_CHECK_LESS_DESCR(argument, upper_limit, "")
9789

9890
#define META_CHECK_LESS_OR_EQUAL_DESCR(argument, upper_limit, description, ...) \
9991
if (argument > static_cast<std::decay_t<decltype(argument)>>(upper_limit)) \
100-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(upper_limit)>>(__FUNCTION_NAME__, #argument, argument, \
92+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(upper_limit)>>(std::source_location::current(), #argument, argument, \
10193
{ std::numeric_limits<std::decay_t<decltype(upper_limit)>>::min(), upper_limit }, true, fmt::format(description, ## __VA_ARGS__))
10294

10395
#define META_CHECK_LESS_OR_EQUAL(argument, upper_limit) META_CHECK_LESS_OR_EQUAL_DESCR(argument, upper_limit, "")
10496

10597
#define META_CHECK_GREATER_DESCR(argument, min_value, description, ...) \
10698
if (argument <= static_cast<std::decay_t<decltype(argument)>>(min_value)) \
107-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(min_value)>>(__FUNCTION_NAME__, #argument, argument, \
99+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(min_value)>>(std::source_location::current(), #argument, argument, \
108100
{ min_value, std::numeric_limits<std::decay_t<decltype(min_value)>>::max() }, false, fmt::format(description, ## __VA_ARGS__))
109101

110102
#define META_CHECK_GREATER(argument, upper_limit) META_CHECK_GREATER_DESCR(argument, upper_limit, "")
111103

112104
#define META_CHECK_GREATER_OR_EQUAL_DESCR(argument, min_value, description, ...) \
113105
if (argument < static_cast<std::decay_t<decltype(argument)>>(min_value)) \
114-
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(min_value)>>(__FUNCTION_NAME__, #argument, argument, \
106+
throw Methane::OutOfRangeArgumentException<std::decay_t<decltype(argument)>, std::decay_t<decltype(min_value)>>(std::source_location::current(), #argument, argument, \
115107
{ min_value, std::numeric_limits<std::decay_t<decltype(min_value)>>::max() }, true, fmt::format(description, ## __VA_ARGS__))
116108

117109
#define META_CHECK_GREATER_OR_EQUAL(argument, min_value) META_CHECK_GREATER_OR_EQUAL_DESCR(argument, min_value, "")
118110

119111
#define META_CHECK_NOT_EMPTY_DESCR(argument, description, ...) \
120112
if (argument.empty()) \
121-
throw Methane::EmptyArgumentException<std::decay_t<decltype(argument)>>(__FUNCTION_NAME__, #argument, fmt::format(description, ## __VA_ARGS__))
113+
throw Methane::EmptyArgumentException<std::decay_t<decltype(argument)>>(std::source_location::current(), #argument, fmt::format(description, ## __VA_ARGS__))
122114

123115
#define META_CHECK_NOT_EMPTY(argument) META_CHECK_NOT_EMPTY_DESCR(argument, "")
124116

125117
#define META_CHECK_NOT_NULL_DESCR(argument, description, ...) \
126118
if (!argument) \
127-
throw Methane::NullPointerArgumentException<std::decay_t<decltype(argument)>>(__FUNCTION_NAME__, #argument, fmt::format(description, ## __VA_ARGS__))
119+
throw Methane::NullPointerArgumentException<std::decay_t<decltype(argument)>>(std::source_location::current(), #argument, fmt::format(description, ## __VA_ARGS__))
128120

129121
#define META_CHECK_NOT_NULL(argument) META_CHECK_NOT_NULL_DESCR(argument, "")
130122

131123
#define META_CHECK_NOT_ZERO_DESCR(argument, description, ...) \
132124
if (!argument) \
133-
throw Methane::ZeroArgumentException<std::decay_t<decltype(argument)>>(__FUNCTION_NAME__, #argument, fmt::format(description, ## __VA_ARGS__))
125+
throw Methane::ZeroArgumentException<std::decay_t<decltype(argument)>>(std::source_location::current(), #argument, fmt::format(description, ## __VA_ARGS__))
134126

135127
#define META_CHECK_NOT_ZERO(argument) META_CHECK_NOT_ZERO_DESCR(argument, "")
136128

137129
#define META_UNEXPECTED_DESCR(argument, description, ...) \
138-
throw Methane::UnexpectedArgumentException<decltype(argument)>(__FUNCTION_NAME__, #argument, argument, fmt::format(description, ## __VA_ARGS__))
130+
throw Methane::UnexpectedArgumentException<decltype(argument)>(std::source_location::current(), #argument, argument, fmt::format(description, ## __VA_ARGS__))
139131

140132
#define META_UNEXPECTED(argument) META_UNEXPECTED_DESCR(argument, "")
141133
#define META_UNEXPECTED_RETURN(argument, return_value) META_UNEXPECTED_DESCR(argument, "")
142134
#define META_UNEXPECTED_RETURN_DESCR(argument, return_value, description, ...) META_UNEXPECTED_DESCR(argument, description, ## __VA_ARGS__)
143135

144136
#define META_FUNCTION_NOT_IMPLEMENTED_DESCR(description, ...) \
145-
throw Methane::NotImplementedException(__FUNCTION_NAME__, fmt::format(description, ## __VA_ARGS__))
137+
throw Methane::NotImplementedException(std::source_location::current(), fmt::format(description, ## __VA_ARGS__))
146138

147139
#define META_FUNCTION_NOT_IMPLEMENTED_RETURN_DESCR(return_value, description, ...) META_FUNCTION_NOT_IMPLEMENTED_DESCR(description, ## __VA_ARGS__)
148140

0 commit comments

Comments
 (0)