mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Added array count macro.
This commit is contained in:
parent
9ad9675062
commit
24890ecebd
9 changed files with 19 additions and 16 deletions
|
@ -204,7 +204,7 @@ int lcGetBrickLinkColor(int ColorIndex)
|
|||
|
||||
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)
|
||||
return BrickLinkColors[Color].BrickLink;
|
||||
|
||||
|
|
|
@ -1565,4 +1565,4 @@ const char* gToolNames[LC_NUM_TOOLS] =
|
|||
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.");
|
||||
|
|
|
@ -20,9 +20,12 @@
|
|||
#endif
|
||||
|
||||
#ifndef QT_STRINGIFY
|
||||
#define QT_STRINGIFY(s) ""
|
||||
#define QT_STRINGIFY2(x) #x
|
||||
#define QT_STRINGIFY(x) QT_STRINGIFY2(x)
|
||||
#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)
|
||||
#undef GL_LINES_ADJACENCY_EXT
|
||||
#undef GL_LINE_STRIP_ADJACENCY_EXT
|
||||
|
|
|
@ -498,7 +498,7 @@ void lcPiecesLibrary::ReadArchiveDescriptions(const QString& OfficialFileName, c
|
|||
bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
|
||||
{
|
||||
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];
|
||||
|
||||
|
@ -515,13 +515,13 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
|
|||
mHasUnofficial = !FileLists[LC_FOLDER_UNOFFICIAL].isEmpty();
|
||||
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/" };
|
||||
bool SubFileDirectories[] = { false, false, true };
|
||||
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]));
|
||||
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 Dir(BaseDir.absoluteFilePath(QLatin1String("parts/textures/")), QLatin1String("*.png"), QDir::SortFlags(QDir::Name | QDir::IgnoreCase), QDir::Files | QDir::Hidden | QDir::Readable);
|
||||
|
|
|
@ -93,7 +93,7 @@ void lcSynthInit()
|
|||
{ "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);
|
||||
|
||||
|
@ -628,8 +628,8 @@ void lcSynthInfo::AddFlexHoseParts(lcMemFile& File, lcLibraryMeshData& MeshData,
|
|||
}
|
||||
};
|
||||
|
||||
AddSectionVertices(OutsideSectionVertices, sizeof(OutsideSectionVertices) / sizeof(OutsideSectionVertices[0]));
|
||||
AddSectionVertices(InsideSectionVertices, sizeof(InsideSectionVertices) / sizeof(InsideSectionVertices[0]));
|
||||
AddSectionVertices(OutsideSectionVertices, LC_ARRAY_COUNT(OutsideSectionVertices));
|
||||
AddSectionVertices(InsideSectionVertices, LC_ARRAY_COUNT(InsideSectionVertices));
|
||||
}
|
||||
|
||||
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 }
|
||||
};
|
||||
|
||||
const int NumSectionVertices = sizeof(SectionVertices) / sizeof(SectionVertices[0]);
|
||||
const int NumSectionVertices = LC_ARRAY_COUNT(SectionVertices);
|
||||
|
||||
int BaseVertex;
|
||||
lcLibraryMeshVertex* VertexBuffer;
|
||||
|
|
|
@ -95,7 +95,7 @@ void MinifigWizard::OnInitialUpdate()
|
|||
MakeCurrent();
|
||||
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 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", "", "" };
|
||||
|
|
|
@ -66,7 +66,7 @@ void lcGLWidget::SetCursor(LC_CURSOR_TYPE CursorType)
|
|||
{ 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;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
|
|||
ui->lgeoPath->setText(mOptions->LGEOPath);
|
||||
ui->authorName->setText(mOptions->DefaultAuthor);
|
||||
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])
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ void lcQPreferencesDialog::accept()
|
|||
mOptions->Preferences.mMouseSensitivity = ui->mouseSensitivity->value();
|
||||
|
||||
int Language = ui->Language->currentIndex();
|
||||
if (Language < 0 || Language > sizeof(gLanguageLocales) / sizeof(gLanguageLocales[0]))
|
||||
if (Language < 0 || Language > LC_ARRAY_COUNT(gLanguageLocales))
|
||||
Language = 0;
|
||||
mOptions->Language = gLanguageLocales[Language];
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ static LONG WINAPI lcSehHandler(PEXCEPTION_POINTERS exceptionPointers)
|
|||
|
||||
static void lcSehInit()
|
||||
{
|
||||
if (GetTempPath(sizeof(gMinidumpPath) / sizeof(gMinidumpPath[0]), gMinidumpPath))
|
||||
if (GetTempPath(LC_ARRAY_SIZE(gMinidumpPath), gMinidumpPath))
|
||||
lstrcat(gMinidumpPath, TEXT("leocad.dmp"));
|
||||
|
||||
SetUnhandledExceptionFilter(lcSehHandler);
|
||||
|
|
Loading…
Reference in a new issue