Added LC_ARRAY_SIZE_CHECK for static array checks.

This commit is contained in:
Leonardo Zide 2020-12-06 11:26:55 -08:00
parent c6c0718d18
commit e52ea0ab63
8 changed files with 24 additions and 15 deletions

View file

@ -1657,9 +1657,9 @@ lcCommand gCommands[LC_NUM_COMMANDS] =
}
};
static_assert(sizeof(gCommands)/sizeof(gCommands[0]) == LC_NUM_COMMANDS, "Array size mismatch.");
LC_ARRAY_SIZE_CHECK(gCommands, LC_NUM_COMMANDS);
const char* gToolNames[static_cast<int>(lcTool::Count)] =
const char* gToolNames[] =
{
QT_TRANSLATE_NOOP("Mouse", "NewPiece"), // lcTool::Insert
QT_TRANSLATE_NOOP("Mouse", "NewPointLight"), // lcTool::Light
@ -1678,4 +1678,4 @@ const char* gToolNames[static_cast<int>(lcTool::Count)] =
QT_TRANSLATE_NOOP("Mouse", "ZoomRegion") // lcTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(gToolNames) == static_cast<int>(lcTool::Count), "Array size mismatch.");
LC_ARRAY_SIZE_CHECK(gToolNames, lcTool::Count);

View file

@ -287,5 +287,5 @@ enum class lcTool
Count
};
extern const char* gToolNames[static_cast<int>(lcTool::Count)];
extern const char* gToolNames[];

View file

@ -102,7 +102,7 @@ void lcContext::CreateShaderPrograms()
" LC_SHADER_PRECISION float Diffuse = min(abs(dot(Normal, LightDirection)) * 0.6 + 0.65, 1.0);\n"
};
const char* const VertexShaders[static_cast<int>(lcMaterialType::Count)] =
const char* const VertexShaders[] =
{
":/resources/shaders/unlit_color_vs.glsl", // UnlitColor
":/resources/shaders/unlit_texture_modulate_vs.glsl", // UnlitTextureModulate
@ -113,7 +113,9 @@ void lcContext::CreateShaderPrograms()
":/resources/shaders/fakelit_texture_decal_vs.glsl" // FakeLitTextureDecal
};
const char* const FragmentShaders[static_cast<int>(lcMaterialType::Count)] =
LC_ARRAY_SIZE_CHECK(VertexShaders, lcMaterialType::Count);
const char* const FragmentShaders[] =
{
":/resources/shaders/unlit_color_ps.glsl", // UnlitColor
":/resources/shaders/unlit_texture_modulate_ps.glsl", // UnlitTextureModulate
@ -124,6 +126,8 @@ void lcContext::CreateShaderPrograms()
":/resources/shaders/fakelit_texture_decal_ps.glsl" // FakeLitTextureDecal
};
LC_ARRAY_SIZE_CHECK(FragmentShaders, lcMaterialType::Count);
const auto LoadShader = [ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
{
QResource Resource(FileName);

View file

@ -26,6 +26,7 @@
#endif
#define LC_ARRAY_COUNT(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define LC_ARRAY_SIZE_CHECK(a,s) static_assert(LC_ARRAY_COUNT(a) == static_cast<int>(s), QT_STRINGIFY(a) " size mismatch.")
#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES)
#undef GL_LINES_ADJACENCY_EXT

View file

@ -70,7 +70,7 @@ lcCursor lcGLWidget::GetCursor() const
return lcCursor::SelectRemove;
}
const lcCursor CursorFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
constexpr lcCursor CursorFromTrackTool[] =
{
lcCursor::Select, // lcTrackTool::None
lcCursor::Brick, // lcTrackTool::Insert
@ -104,7 +104,7 @@ lcCursor lcGLWidget::GetCursor() const
lcCursor::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(CursorFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
LC_ARRAY_SIZE_CHECK(CursorFromTrackTool, lcTrackTool::Count);
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return CursorFromTrackTool[static_cast<int>(mTrackTool)];
@ -123,7 +123,7 @@ void lcGLWidget::SetCursor(lcCursor CursorType)
const char* Name;
};
const lcCursorInfo Cursors[static_cast<int>(lcCursor::Count)] =
constexpr lcCursorInfo Cursors[] =
{
{ 0, 0, "" }, // lcCursor::Hidden
{ 0, 0, "" }, // lcCursor::Default
@ -148,7 +148,7 @@ void lcGLWidget::SetCursor(lcCursor CursorType)
{ 15, 15, ":/resources/cursor_rotate_view" }, // lcCursor::RotateView
};
static_assert(LC_ARRAY_COUNT(Cursors) == static_cast<int>(lcCursor::Count), "Array size mismatch");
LC_ARRAY_SIZE_CHECK(Cursors, lcCursor::Count);
if (CursorType == lcCursor::Hidden)
{
@ -175,7 +175,7 @@ void lcGLWidget::UpdateCursor()
lcTool lcGLWidget::GetCurrentTool() const
{
const lcTool ToolFromTrackTool[static_cast<int>(lcTrackTool::Count)] =
constexpr lcTool ToolFromTrackTool[] =
{
lcTool::Select, // lcTrackTool::None
lcTool::Insert, // lcTrackTool::Insert
@ -209,7 +209,7 @@ lcTool lcGLWidget::GetCurrentTool() const
lcTool::ZoomRegion // lcTrackTool::ZoomRegion
};
static_assert(LC_ARRAY_COUNT(ToolFromTrackTool) == static_cast<int>(lcTrackTool::Count), "Array size mismatch.");
LC_ARRAY_SIZE_CHECK(ToolFromTrackTool, lcTrackTool::Count);
if (mTrackTool >= lcTrackTool::None && mTrackTool < lcTrackTool::Count)
return ToolFromTrackTool[static_cast<int>(mTrackTool)];

View file

@ -1771,7 +1771,7 @@ void lcMainWindow::SetTransformType(lcTransformType TransformType)
mTransformType = TransformType;
const char* IconNames[static_cast<int>(lcTransformType::Count)] =
constexpr const char* IconNames[] =
{
":/resources/edit_transform_absolute_translation.png",
":/resources/edit_transform_relative_translation.png",
@ -1779,6 +1779,8 @@ void lcMainWindow::SetTransformType(lcTransformType TransformType)
":/resources/edit_transform_relative_rotation.png"
};
LC_ARRAY_SIZE_CHECK(IconNames, lcTransformType::Count);
int TransformIndex = static_cast<int>(TransformType);
mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformIndex]->setChecked(true);
mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformIndex]));

View file

@ -96,7 +96,7 @@ void MinifigWizard::OnInitialUpdate()
MakeCurrent();
mContext->SetDefaultState();
static_assert(LC_ARRAY_COUNT(MinifigWizard::mSectionNames) == LC_MFW_NUMITEMS, "Array size mismatch.");
LC_ARRAY_SIZE_CHECK(MinifigWizard::mSectionNames, LC_MFW_NUMITEMS);
const int ColorCodes[LC_MFW_NUMITEMS] = { 4, 7, 14, 7, 1, 0, 7, 4, 4, 14, 14, 7, 7, 0, 0, 7, 7 };
const char* const Pieces[LC_MFW_NUMITEMS] = { "3624.dat", "", "3626bp01.dat", "", "973.dat", "3815.dat", "", "3819.dat", "3818.dat", "3820.dat", "3820.dat", "", "", "3817.dat", "3816.dat", "", "" };

View file

@ -1714,7 +1714,7 @@ lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const
if (OverrideTool == lcTool::Count)
return lcTrackTool::None;
lcTrackTool TrackToolFromTool[static_cast<int>(lcTool::Count)] =
constexpr lcTrackTool TrackToolFromTool[] =
{
lcTrackTool::Insert, // lcTool::Insert
lcTrackTool::PointLight, // lcTool::Light
@ -1733,6 +1733,8 @@ lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const
lcTrackTool::ZoomRegion // lcTool::ZoomRegion
};
LC_ARRAY_SIZE_CHECK(TrackToolFromTool, lcTool::Count);
return TrackToolFromTool[static_cast<int>(OverrideTool)];
}