diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/alsoft-config/mainwindow.cpp | 16 | ||||
-rw-r--r-- | utils/makemhr/makemhr.cpp | 31 | ||||
-rw-r--r-- | utils/uhjdecoder.cpp | 3 |
3 files changed, 26 insertions, 24 deletions
diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index b2412c73..9a65f79c 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -20,6 +20,7 @@ #include <shlobj.h> #endif +#include "almalloc.h" #include "alspan.h" namespace { @@ -1283,11 +1284,10 @@ void MainWindow::addHrtfFile() void MainWindow::removeHrtfFile() { - QList<QListWidgetItem*> selected{ui->hrtfFileList->selectedItems()}; + QList<gsl::owner<QListWidgetItem*>> selected{ui->hrtfFileList->selectedItems()}; if(!selected.isEmpty()) { - foreach(QListWidgetItem *item, selected) - delete item; + std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{}); enableApplyButton(); } } @@ -1321,9 +1321,8 @@ void MainWindow::showEnabledBackendMenu(QPoint pt) QAction *gotAction{ctxmenu.exec(pt)}; if(gotAction == removeAction) { - QList<QListWidgetItem*> selected{ui->enabledBackendList->selectedItems()}; - foreach(QListWidgetItem *item, selected) - delete item; + QList<gsl::owner<QListWidgetItem*>> selected{ui->enabledBackendList->selectedItems()}; + std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{}); enableApplyButton(); } else if(gotAction != nullptr) @@ -1359,9 +1358,8 @@ void MainWindow::showDisabledBackendMenu(QPoint pt) QAction *gotAction{ctxmenu.exec(pt)}; if(gotAction == removeAction) { - QList<QListWidgetItem*> selected{ui->disabledBackendList->selectedItems()}; - foreach(QListWidgetItem *item, selected) - delete item; + QList<gsl::owner<QListWidgetItem*>> selected{ui->disabledBackendList->selectedItems()}; + std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{}); enableApplyButton(); } else if(gotAction != nullptr) diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index f14110c0..0a9b71e7 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -104,6 +104,11 @@ HrirDataT::~HrirDataT() = default; namespace { +struct FileDeleter { + void operator()(gsl::owner<FILE*> f) { fclose(f); } +}; +using FilePtr = std::unique_ptr<FILE,FileDeleter>; + using namespace std::placeholders; // The epsilon used to maintain signal stability. @@ -312,7 +317,6 @@ static int WriteAscii(const char *out, FILE *fp, const char *filename) len = strlen(out); if(fwrite(out, 1, len, fp) != len) { - fclose(fp); fprintf(stderr, "\nError: Bad write to file '%s'.\n", filename); return 0; } @@ -343,33 +347,33 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) uint dither_seed{22222}; uint fi, ei, ai, i; - FILE *fp{fopen(filename, "wb")}; + FilePtr fp{fopen(filename, "wb")}; if(!fp) { fprintf(stderr, "\nError: Could not open MHR file '%s'.\n", filename); return 0; } - if(!WriteAscii(MHRFormat, fp, filename)) + if(!WriteAscii(MHRFormat, fp.get(), filename)) return 0; - if(!WriteBin4(4, hData->mIrRate, fp, filename)) + if(!WriteBin4(4, hData->mIrRate, fp.get(), filename)) return 0; - if(!WriteBin4(1, static_cast<uint32_t>(hData->mChannelType), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(hData->mChannelType), fp.get(), filename)) return 0; - if(!WriteBin4(1, hData->mIrPoints, fp, filename)) + if(!WriteBin4(1, hData->mIrPoints, fp.get(), filename)) return 0; - if(!WriteBin4(1, static_cast<uint>(hData->mFds.size()), fp, filename)) + if(!WriteBin4(1, static_cast<uint>(hData->mFds.size()), fp.get(), filename)) return 0; for(fi = static_cast<uint>(hData->mFds.size()-1);fi < hData->mFds.size();fi--) { auto fdist = static_cast<uint32_t>(std::round(1000.0 * hData->mFds[fi].mDistance)); - if(!WriteBin4(2, fdist, fp, filename)) + if(!WriteBin4(2, fdist, fp.get(), filename)) return 0; - if(!WriteBin4(1, static_cast<uint32_t>(hData->mFds[fi].mEvs.size()), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(hData->mFds[fi].mEvs.size()), fp.get(), filename)) return 0; for(ei = 0;ei < hData->mFds[fi].mEvs.size();ei++) { const auto &elev = hData->mFds[fi].mEvs[ei]; - if(!WriteBin4(1, static_cast<uint32_t>(elev.mAzs.size()), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(elev.mAzs.size()), fp.get(), filename)) return 0; } } @@ -392,7 +396,7 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) for(i = 0;i < (channels * n);i++) { const auto v = static_cast<int>(Clamp(out[i], -scale-1.0, scale)); - if(!WriteBin4(bps, static_cast<uint32_t>(v), fp, filename)) + if(!WriteBin4(bps, static_cast<uint32_t>(v), fp.get(), filename)) return 0; } } @@ -407,16 +411,15 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) for(const auto &azd : hData->mFds[fi].mEvs[ei].mAzs) { auto v = static_cast<uint>(std::round(azd.mDelays[0]*DelayPrecScale)); - if(!WriteBin4(1, v, fp, filename)) return 0; + if(!WriteBin4(1, v, fp.get(), filename)) return 0; if(hData->mChannelType == CT_STEREO) { v = static_cast<uint>(std::round(azd.mDelays[1]*DelayPrecScale)); - if(!WriteBin4(1, v, fp, filename)) return 0; + if(!WriteBin4(1, v, fp.get(), filename)) return 0; } } } } - fclose(fp); return 1; } diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index 8f0d2006..970d9f82 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -35,6 +35,7 @@ #include "albit.h" #include "alcomplex.h" +#include "almalloc.h" #include "alnumbers.h" #include "alspan.h" #include "vector.h" @@ -47,7 +48,7 @@ struct FileDeleter { - void operator()(FILE *file) { fclose(file); } + void operator()(gsl::owner<FILE*> file) { fclose(file); } }; using FilePtr = std::unique_ptr<FILE,FileDeleter>; |