From c095bbee9566a64ba0e271d8de678ccfd26d6651 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 29 Jul 2012 19:09:15 +0200 Subject: [PATCH] Some refactoring of the macros. Use the "do {...} while(0)" template where it makes sense. --- src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 68 +++++++++++++++++++++++++++++++-------- src/Dialog_Processing.cpp | 24 ++++++++++---- src/Global.h | 19 +++++------ src/Main.cpp | 4 +-- 5 files changed, 86 insertions(+), 31 deletions(-) diff --git a/src/Config.h b/src/Config.h index ef0d7fbc..e1656bad 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 5 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 11 -#define VER_LAMEXP_BUILD 1060 +#define VER_LAMEXP_BUILD 1061 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 5b43b6d1..28f63002 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -70,16 +70,58 @@ #include #include +//////////////////////////////////////////////////////////// //Helper macros -#define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; } -#define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); } -#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } +//////////////////////////////////////////////////////////// + +#define ABORT_IF_BUSY do \ +{ \ + if(m_banner->isVisible() || m_delayedFileTimer->isActive()) \ + { \ + MessageBeep(MB_ICONEXCLAMATION); \ + return; \ + } \ +} \ +while(0) + +#define SET_TEXT_COLOR(WIDGET, COLOR) do \ +{ \ + QPalette _palette = WIDGET->palette(); \ + _palette.setColor(QPalette::WindowText, (COLOR)); \ + _palette.setColor(QPalette::Text, (COLOR)); \ + WIDGET->setPalette(_palette); \ +} \ +while(0) + +#define SET_FONT_BOLD(WIDGET,BOLD) do \ +{ \ + QFont _font = WIDGET->font(); \ + _font.setBold(BOLD); \ + WIDGET->setFont(_font); \ +} \ +while(0) + +#define TEMP_HIDE_DROPBOX(CMD) do \ +{ \ + bool _dropBoxVisible = m_dropBox->isVisible(); \ + if(_dropBoxVisible) m_dropBox->hide(); \ + do { CMD } while(0); \ + if(_dropBoxVisible) m_dropBox->show(); \ +} \ +while(0) + +#define SET_MODEL(VIEW, MODEL) do \ +{ \ + QItemSelectionModel *_tmp = (VIEW)->selectionModel(); \ + (VIEW)->setModel(MODEL); \ + LAMEXP_DELETE(_tmp); \ +} \ +while(0) + #define LINK(URL) QString("%2").arg(URL).arg(QString(URL).replace("-", "−")) #define FSLINK(PATH) QString("%2").arg(PATH).arg(QString(PATH).replace("-", "−")) -#define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); {CMD}; if(__dropBoxVisible) m_dropBox->show(); } #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP)) #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel())) -#define SET_MODEL(VIEW, MODEL) { QItemSelectionModel *_tmp = (VIEW)->selectionModel(); (VIEW)->setModel(MODEL); LAMEXP_DELETE(_tmp); } //////////////////////////////////////////////////////////// // Constructor @@ -1511,7 +1553,7 @@ void MainWindow::aboutButtonClicked(void) AboutDialog *aboutBox = new AboutDialog(m_settings, this); aboutBox->exec(); LAMEXP_DELETE(aboutBox); - ) + ); } /* @@ -1870,7 +1912,7 @@ void MainWindow::importCueSheetActionTriggered(bool checked) if(result != (-1)) break; } - ) + ); } /* @@ -2047,7 +2089,7 @@ void MainWindow::checkUpdatesActionActivated(void) TEMP_HIDE_DROPBOX ( bFlag = checkForUpdates(); - ) + ); if(bFlag) { @@ -2095,7 +2137,7 @@ void MainWindow::addFilesButtonClicked(void) } } } - ) + ); } /* @@ -2130,7 +2172,7 @@ void MainWindow::openFolderActionActivated(void) m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath()); addFolder(selectedFolder, action->data().toBool()); } - ) + ); } } @@ -2209,7 +2251,7 @@ void MainWindow::showDetailsButtonClicked(void) TEMP_HIDE_DROPBOX ( iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1); - ) + ); if(iResult == INT_MAX) { @@ -2410,7 +2452,7 @@ void MainWindow::exportCsvContextActionTriggered(void) qWarning("exportToCsv: Unknown return code!"); } } - ) + ); } @@ -2466,7 +2508,7 @@ void MainWindow::importCsvContextActionTriggered(void) qWarning("exportToCsv: Unknown return code!"); } } - ) + ); } /* diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 39850e56..f7f982ca 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -79,21 +79,33 @@ static int cores2instances(int cores); //////////////////////////////////////////////////////////// -#define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) \ +#define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) do \ { \ QPalette palette = WIDGET->palette(); \ palette.setColor(QPalette::Background, COLOR); \ WIDGET->setPalette(palette); \ -} +} \ +while(0) -#define SET_PROGRESS_TEXT(TXT) \ +#define SET_PROGRESS_TEXT(TXT) do \ { \ label_progress->setText(TXT); \ m_systemTray->setToolTip(QString().sprintf("LameXP v%d.%02d\n%ls", lamexp_version_major(), lamexp_version_minor(), QString(TXT).utf16())); \ -} +} \ +while(0) -#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } -#define UPDATE_MIN_WIDTH(WIDGET) { if(WIDGET->width() > WIDGET->minimumWidth()) WIDGET->setMinimumWidth(WIDGET->width()); } +#define SET_FONT_BOLD(WIDGET,BOLD) do \ +{ \ + QFont _font = WIDGET->font(); \ + _font.setBold(BOLD); WIDGET->setFont(_font); \ +} \ +while(0) + +#define UPDATE_MIN_WIDTH(WIDGET) do \ +{ \ + if(WIDGET->width() > WIDGET->minimumWidth()) WIDGET->setMinimumWidth(WIDGET->width()); \ +} \ +while(0) //////////////////////////////////////////////////////////// // Constructor diff --git a/src/Global.h b/src/Global.h index 3ccbd668..a742cfbe 100644 --- a/src/Global.h +++ b/src/Global.h @@ -152,26 +152,27 @@ const QString lamexp_clean_filepath(const QString &str); SIZE_T lamexp_dbg_private_bytes(void); //Helper macros -#define LAMEXP_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; } -#define LAMEXP_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; } -#define LAMEXP_SAFE_FREE(PTR) if(PTR) { free((void*) PTR); PTR = NULL; } -#define LAMEXP_CLOSE(HANDLE) if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } +#define LAMEXP_DELETE(PTR) do { if(PTR) { delete PTR; PTR = NULL; } } while(0) +#define LAMEXP_DELETE_ARRAY(PTR) do { if(PTR) { delete [] PTR; PTR = NULL; } } while(0) +#define LAMEXP_SAFE_FREE(PTR) do { if(PTR) { free((void*) PTR); PTR = NULL; } } while(0) +#define LAMEXP_CLOSE(HANDLE) do { if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } } while(0) #define LAMEXP_MIN_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) > (VER_MAJ)) || ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) >= (VER_MIN)))) #define LAMEXP_MAX_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) < (VER_MAJ)) || ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) <= (VER_MIN)))) #define LAMEXP_EQL_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) == (VER_MIN))) #define QWCHAR(STR) reinterpret_cast(STR.utf16()) #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast(STR)) -#define LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast(SRC); } catch(std::bad_cast) { OUT = NULL; } -#define LAMEXP_BOOL(X) (X ? "1" : "0") +#define LAMEXP_BOOL2STR(X) (X ? "1" : "0") #define LAMEXP_MAKE_STRING_EX(X) #X #define LAMEXP_MAKE_STRING(X) LAMEXP_MAKE_STRING_EX(X) #define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT)) #define NOBR(STR) (QString("%1").arg((STR)).replace("-", "−")) //Output Qt debug message (Unicode-safe versions) -//#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); -//#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); -//#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +/* +#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +*/ //Check for debug build #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG) diff --git a/src/Main.cpp b/src/Main.cpp index 066ac4cf..b3accc63 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -84,10 +84,10 @@ static int lamexp_main(int argc, char* argv[]) //Detect CPU capabilities lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(arguments); - qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL(cpuFeatures.intel)); + qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL2STR(cpuFeatures.intel)); qDebug("CPU brand string : %s", cpuFeatures.brand); qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping); - qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", LAMEXP_BOOL(cpuFeatures.mmx), LAMEXP_BOOL(cpuFeatures.sse), LAMEXP_BOOL(cpuFeatures.sse2), LAMEXP_BOOL(cpuFeatures.sse3), LAMEXP_BOOL(cpuFeatures.ssse3), LAMEXP_BOOL(cpuFeatures.x64)); + qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", LAMEXP_BOOL2STR(cpuFeatures.mmx), LAMEXP_BOOL2STR(cpuFeatures.sse), LAMEXP_BOOL2STR(cpuFeatures.sse2), LAMEXP_BOOL2STR(cpuFeatures.sse3), LAMEXP_BOOL2STR(cpuFeatures.ssse3), LAMEXP_BOOL2STR(cpuFeatures.x64)); qDebug(" Number of CPU's : %d\n", cpuFeatures.count); //Initialize Qt