Added array count macro.

This commit is contained in:
Leonardo Zide 2019-12-09 11:43:54 -08:00
parent 9ad9675062
commit 24890ecebd
9 changed files with 19 additions and 16 deletions

View file

@ -204,7 +204,7 @@ int lcGetBrickLinkColor(int ColorIndex)
int ColorCode = gColorList[ColorIndex].Code; int ColorCode = gColorList[ColorIndex].Code;
for (unsigned int Color = 0; Color < sizeof(BrickLinkColors) / sizeof(BrickLinkColors[0]); Color++) for (unsigned int Color = 0; Color < LC_ARRAY_COUNT(BrickLinkColors); Color++)
if (BrickLinkColors[Color].LDraw == ColorCode) if (BrickLinkColors[Color].LDraw == ColorCode)
return BrickLinkColors[Color].BrickLink; return BrickLinkColors[Color].BrickLink;

View file

@ -1565,4 +1565,4 @@ const char* gToolNames[LC_NUM_TOOLS] =
QT_TRANSLATE_NOOP("Mouse", "ZoomRegion") // LC_TOOL_ZOOM_REGION QT_TRANSLATE_NOOP("Mouse", "ZoomRegion") // LC_TOOL_ZOOM_REGION
}; };
static_assert(sizeof(gToolNames) / sizeof(gToolNames[0]) == LC_NUM_TOOLS, "Array size mismatch."); static_assert(LC_ARRAY_COUNT(gToolNames) == LC_NUM_TOOLS, "Array size mismatch.");

View file

@ -20,9 +20,12 @@
#endif #endif
#ifndef QT_STRINGIFY #ifndef QT_STRINGIFY
#define QT_STRINGIFY(s) "" #define QT_STRINGIFY2(x) #x
#define QT_STRINGIFY(x) QT_STRINGIFY2(x)
#endif #endif
#define LC_ARRAY_COUNT(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES) #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 #undef GL_LINES_ADJACENCY_EXT
#undef GL_LINE_STRIP_ADJACENCY_EXT #undef GL_LINE_STRIP_ADJACENCY_EXT

View file

@ -498,7 +498,7 @@ void lcPiecesLibrary::ReadArchiveDescriptions(const QString& OfficialFileName, c
bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress) bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
{ {
const QLatin1String BaseFolders[LC_NUM_FOLDERTYPES] = { QLatin1String("unofficial/"), QLatin1String("") }; const QLatin1String BaseFolders[LC_NUM_FOLDERTYPES] = { QLatin1String("unofficial/"), QLatin1String("") };
const int NumBaseFolders = sizeof(BaseFolders) / sizeof(BaseFolders[0]); const int NumBaseFolders = LC_ARRAY_COUNT(BaseFolders);
QFileInfoList FileLists[NumBaseFolders]; QFileInfoList FileLists[NumBaseFolders];
@ -515,13 +515,13 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
mHasUnofficial = !FileLists[LC_FOLDER_UNOFFICIAL].isEmpty(); mHasUnofficial = !FileLists[LC_FOLDER_UNOFFICIAL].isEmpty();
ReadDirectoryDescriptions(FileLists, ShowProgress); ReadDirectoryDescriptions(FileLists, ShowProgress);
for (unsigned int BaseFolderIdx = 0; BaseFolderIdx < sizeof(BaseFolders) / sizeof(BaseFolders[0]); BaseFolderIdx++) for (unsigned int BaseFolderIdx = 0; BaseFolderIdx < LC_ARRAY_COUNT(BaseFolders); BaseFolderIdx++)
{ {
const char* PrimitiveDirectories[] = { "p/", "parts/s/" }; const char* PrimitiveDirectories[] = { "p/", "parts/s/" };
bool SubFileDirectories[] = { false, false, true }; bool SubFileDirectories[] = { false, false, true };
QDir BaseDir(LibraryDir.absoluteFilePath(QLatin1String(BaseFolders[BaseFolderIdx]))); QDir BaseDir(LibraryDir.absoluteFilePath(QLatin1String(BaseFolders[BaseFolderIdx])));
for (int DirectoryIdx = 0; DirectoryIdx < (int)(sizeof(PrimitiveDirectories) / sizeof(PrimitiveDirectories[0])); DirectoryIdx++) for (int DirectoryIdx = 0; DirectoryIdx < (int)(LC_ARRAY_COUNT(PrimitiveDirectories)); DirectoryIdx++)
{ {
QString ChildPath = BaseDir.absoluteFilePath(QLatin1String(PrimitiveDirectories[DirectoryIdx])); QString ChildPath = BaseDir.absoluteFilePath(QLatin1String(PrimitiveDirectories[DirectoryIdx]));
QDirIterator DirIterator(ChildPath, QStringList() << QLatin1String("*.dat"), QDir::Files | QDir::Hidden | QDir::Readable, QDirIterator::Subdirectories); QDirIterator DirIterator(ChildPath, QStringList() << QLatin1String("*.dat"), QDir::Files | QDir::Hidden | QDir::Readable, QDirIterator::Subdirectories);
@ -567,7 +567,7 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
} }
} }
for (unsigned int BaseFolderIdx = 0; BaseFolderIdx < sizeof(BaseFolders) / sizeof(BaseFolders[0]); BaseFolderIdx++) for (unsigned int BaseFolderIdx = 0; BaseFolderIdx < LC_ARRAY_COUNT(BaseFolders); BaseFolderIdx++)
{ {
QDir BaseDir(LibraryDir.absoluteFilePath(QLatin1String(BaseFolders[BaseFolderIdx]))); QDir BaseDir(LibraryDir.absoluteFilePath(QLatin1String(BaseFolders[BaseFolderIdx])));
QDir Dir(BaseDir.absoluteFilePath(QLatin1String("parts/textures/")), QLatin1String("*.png"), QDir::SortFlags(QDir::Name | QDir::IgnoreCase), QDir::Files | QDir::Hidden | QDir::Readable); QDir Dir(BaseDir.absoluteFilePath(QLatin1String("parts/textures/")), QLatin1String("*.png"), QDir::SortFlags(QDir::Name | QDir::IgnoreCase), QDir::Files | QDir::Hidden | QDir::Readable);

View file

@ -93,7 +93,7 @@ void lcSynthInit()
{ "61927.dat", lcSynthType::ACTUATOR, 170.00f, 1 } // Technic Power Functions Linear Actuator (Contracted) { "61927.dat", lcSynthType::ACTUATOR, 170.00f, 1 } // Technic Power Functions Linear Actuator (Contracted)
}; };
for (unsigned int InfoIdx = 0; InfoIdx < sizeof(HoseInfo) / sizeof(HoseInfo[0]); InfoIdx++) for (unsigned int InfoIdx = 0; InfoIdx < LC_ARRAY_COUNT(HoseInfo); InfoIdx++)
{ {
PieceInfo* Info = Library->FindPiece(HoseInfo[InfoIdx].PartID, nullptr, false, false); PieceInfo* Info = Library->FindPiece(HoseInfo[InfoIdx].PartID, nullptr, false, false);
@ -628,8 +628,8 @@ void lcSynthInfo::AddFlexHoseParts(lcMemFile& File, lcLibraryMeshData& MeshData,
} }
}; };
AddSectionVertices(OutsideSectionVertices, sizeof(OutsideSectionVertices) / sizeof(OutsideSectionVertices[0])); AddSectionVertices(OutsideSectionVertices, LC_ARRAY_COUNT(OutsideSectionVertices));
AddSectionVertices(InsideSectionVertices, sizeof(InsideSectionVertices) / sizeof(InsideSectionVertices[0])); AddSectionVertices(InsideSectionVertices, LC_ARRAY_COUNT(InsideSectionVertices));
} }
void lcSynthInfo::AddRibbedHoseParts(lcMemFile& File, const lcArray<lcMatrix44>& Sections) const void lcSynthInfo::AddRibbedHoseParts(lcMemFile& File, const lcArray<lcMatrix44>& Sections) const
@ -745,7 +745,7 @@ void lcSynthInfo::AddFlexibleAxleParts(lcMemFile& File, lcLibraryMeshData& MeshD
{ lcVector3(-5.602f, 0.0f, -2.000f), lcVector3(-0.942f, 0.0f, -0.336f), 4.0f, lcVector2(0.0f, 0.0f), 0 } { lcVector3(-5.602f, 0.0f, -2.000f), lcVector3(-0.942f, 0.0f, -0.336f), 4.0f, lcVector2(0.0f, 0.0f), 0 }
}; };
const int NumSectionVertices = sizeof(SectionVertices) / sizeof(SectionVertices[0]); const int NumSectionVertices = LC_ARRAY_COUNT(SectionVertices);
int BaseVertex; int BaseVertex;
lcLibraryMeshVertex* VertexBuffer; lcLibraryMeshVertex* VertexBuffer;

View file

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

@ -66,7 +66,7 @@ void lcGLWidget::SetCursor(LC_CURSOR_TYPE CursorType)
{ 15, 15, ":/resources/cursor_rotate_view" }, // LC_CURSOR_ROTATE_VIEW { 15, 15, ":/resources/cursor_rotate_view" }, // LC_CURSOR_ROTATE_VIEW
}; };
static_assert(sizeof(Cursors) / sizeof(Cursors[0]) == LC_CURSOR_COUNT, "Array size mismatch"); static_assert(LC_ARRAY_COUNT(Cursors) == LC_CURSOR_COUNT, "Array size mismatch");
QGLWidget* widget = (QGLWidget*)mWidget; QGLWidget* widget = (QGLWidget*)mWidget;

View file

@ -46,7 +46,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
ui->lgeoPath->setText(mOptions->LGEOPath); ui->lgeoPath->setText(mOptions->LGEOPath);
ui->authorName->setText(mOptions->DefaultAuthor); ui->authorName->setText(mOptions->DefaultAuthor);
ui->mouseSensitivity->setValue(mOptions->Preferences.mMouseSensitivity); ui->mouseSensitivity->setValue(mOptions->Preferences.mMouseSensitivity);
for (unsigned int LanguageIdx = 0; LanguageIdx < sizeof(gLanguageLocales) / sizeof(gLanguageLocales[0]); LanguageIdx++) for (unsigned int LanguageIdx = 0; LanguageIdx < LC_ARRAY_COUNT(gLanguageLocales); LanguageIdx++)
{ {
if (mOptions->Language == gLanguageLocales[LanguageIdx]) if (mOptions->Language == gLanguageLocales[LanguageIdx])
{ {
@ -168,7 +168,7 @@ void lcQPreferencesDialog::accept()
mOptions->Preferences.mMouseSensitivity = ui->mouseSensitivity->value(); mOptions->Preferences.mMouseSensitivity = ui->mouseSensitivity->value();
int Language = ui->Language->currentIndex(); int Language = ui->Language->currentIndex();
if (Language < 0 || Language > sizeof(gLanguageLocales) / sizeof(gLanguageLocales[0])) if (Language < 0 || Language > LC_ARRAY_COUNT(gLanguageLocales))
Language = 0; Language = 0;
mOptions->Language = gLanguageLocales[Language]; mOptions->Language = gLanguageLocales[Language];

View file

@ -71,7 +71,7 @@ static LONG WINAPI lcSehHandler(PEXCEPTION_POINTERS exceptionPointers)
static void lcSehInit() static void lcSehInit()
{ {
if (GetTempPath(sizeof(gMinidumpPath) / sizeof(gMinidumpPath[0]), gMinidumpPath)) if (GetTempPath(LC_ARRAY_SIZE(gMinidumpPath), gMinidumpPath))
lstrcat(gMinidumpPath, TEXT("leocad.dmp")); lstrcat(gMinidumpPath, TEXT("leocad.dmp"));
SetUnhandledExceptionFilter(lcSehHandler); SetUnhandledExceptionFilter(lcSehHandler);