reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 0577045c5d3e3d2d2520247c36e29108e0918e35
parent 8144e2e475093ab28cd1d0023275722ba785b38a
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon,  1 Apr 2019 16:56:40 -0400

don't import the std namespace into the global scope

Diffstat:
Msrc/about.cpp | 36+++++++++++++++++-------------------
Msrc/api_misc.cpp | 4+---
Msrc/api_package.cpp | 11+++++------
Msrc/api_repo.cpp | 2--
Msrc/archive.cpp | 42++++++++++++++++++++----------------------
Msrc/archive_tasks.cpp | 23+++++++++++++----------
Msrc/browser.cpp | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/browser_entry.cpp | 30++++++++++++++----------------
Msrc/browser_entry.hpp | 2+-
Msrc/config.cpp | 22+++++++++++-----------
Msrc/control.cpp | 4+---
Msrc/database.cpp | 12+++++-------
Msrc/dialog.cpp | 25+++++++++++++------------
Msrc/download.cpp | 22++++++++++------------
Msrc/filedialog.cpp | 16+++++++---------
Msrc/filesystem.cpp | 16+++++++---------
Msrc/import.cpp | 8+++-----
Msrc/index.cpp | 22++++++++++------------
Msrc/index_v1.cpp | 16+++++++---------
Msrc/install.cpp | 6++----
Msrc/listview.cpp | 43+++++++++++++++++++------------------------
Msrc/listview.hpp | 8+++-----
Msrc/manager.cpp | 42++++++++++++++++++++----------------------
Msrc/obsquery.cpp | 8+++-----
Msrc/package.cpp | 12+++++-------
Msrc/package.hpp | 2+-
Msrc/path.cpp | 46++++++++++++++++++++++------------------------
Msrc/progress.cpp | 9++++-----
Msrc/reapack.cpp | 22++++++++++------------
Msrc/receipt.cpp | 6++----
Msrc/registry.cpp | 24+++++++++++-------------
Msrc/remote.cpp | 61++++++++++++++++++++++++++++++-------------------------------
Msrc/report.cpp | 2--
Msrc/richedit-gtk.cpp | 6++----
Msrc/richedit-win32.cpp | 17+++++++----------
Msrc/richedit.mm | 6++----
Msrc/serializer.cpp | 20+++++++++-----------
Msrc/source.cpp | 8+++-----
Msrc/string.cpp | 18++++++++----------
Msrc/task.cpp | 6++----
Msrc/thread.cpp | 10++++------
Msrc/time.cpp | 14++++++--------
Msrc/transaction.cpp | 36+++++++++++++++++-------------------
Msrc/version.cpp | 42++++++++++++++++++++----------------------
Msrc/win32.cpp | 20+++++++++-----------
Mtest/api.cpp | 2--
Mtest/database.cpp | 18++++++++----------
Mtest/event.cpp | 2+-
Mtest/filter.cpp | 2--
Mtest/helper.cpp | 4+---
Mtest/index.cpp | 22++++++++++------------
Mtest/index_v1.cpp | 10++++------
Mtest/metadata.cpp | 2--
Mtest/package.cpp | 16+++++++---------
Mtest/path.cpp | 10++++------
Mtest/platform.cpp | 4+---
Mtest/receipt.cpp | 30++++++++++++++----------------
Mtest/registry.cpp | 12+++++-------
Mtest/remote.cpp | 27+++++++++++++--------------
Mtest/source.cpp | 15++++++---------
Mtest/string.cpp | 8+++-----
Mtest/time.cpp | 6++----
Mtest/version.cpp | 16+++++++---------
Mtest/win32.cpp | 2--
Mwin32.tup | 4++--
65 files changed, 493 insertions(+), 604 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -38,8 +38,6 @@ #include <iomanip> #include <sstream> -using namespace std; - enum { ACTION_ABOUT_PKG = 300, ACTION_FIND_IN_BROWSER, ACTION_COPY_URL, ACTION_LOCATE @@ -58,7 +56,7 @@ void About::onInit() m_desc = createControl<RichEdit>(IDC_ABOUT); m_menu = createControl<ListView>(IDC_MENU); - m_menu->onSelect >> bind(&About::updateList, this); + m_menu->onSelect >> std::bind(&About::updateList, this); m_list = createControl<ListView>(IDC_LIST); m_list->onFillContextMenu >> [=] (Menu &m, int i) { return m_delegate->fillContextMenu(m, i); }; @@ -168,14 +166,14 @@ void About::setDelegate(const DelegatePtr &delegate, const bool focus) } } -void About::setTitle(const string &what) +void About::setTitle(const std::string &what) { Win32::setWindowText(handle(), what.c_str()); } void About::setMetadata(const Metadata *metadata, const bool substitution) { - string aboutText(metadata->about()); + std::string aboutText(metadata->about()); if(substitution) { boost::replace_all(aboutText, "[[REAPACK_VERSION]]", ReaPack::VERSION); @@ -229,7 +227,7 @@ void About::setMetadata(const Metadata *metadata, const bool substitution) onResize(); // update the position of link buttons } -void About::setAction(const string &label) +void About::setAction(const std::string &label) { HWND btn = getControl(IDC_ACTION); Win32::setWindowText(btn, label.c_str()); @@ -251,7 +249,7 @@ void About::selectLink(const int ctrl) Menu menu; for(int i = 0; i < count; i++) { - const string &name = boost::replace_all_copy(links[i]->name, "&", "&&"); + const std::string &name = boost::replace_all_copy(links[i]->name, "&", "&&"); menu.addAction(name.c_str(), i | (ctrl << 8)); } @@ -313,12 +311,12 @@ void AboutIndexDelegate::initInstalledFiles() { const HWND report = m_dialog->getControl(IDC_REPORT); - set<Registry::File> allFiles; + std::set<Registry::File> allFiles; try { Registry reg(Path::REGISTRY.prependRoot()); for(const Registry::Entry &entry : reg.getEntries(m_index->name())) { - const vector<Registry::File> &files = reg.getFiles(entry); + const std::vector<Registry::File> &files = reg.getFiles(entry); allFiles.insert(files.begin(), files.end()); } } @@ -339,7 +337,7 @@ void AboutIndexDelegate::initInstalledFiles() "any package compatible with your system."); } else { - stringstream stream; + std::stringstream stream; for(const Registry::File &file : allFiles) { stream << file.path.join(); @@ -357,7 +355,7 @@ void AboutIndexDelegate::updateList(const int index) // -1: all packages, >0 selected category const int catIndex = index - 1; - const vector<const Package *> *packages; + const std::vector<const Package *> *packages; if(catIndex < 0) packages = &m_index->packages(); @@ -421,7 +419,7 @@ void AboutIndexDelegate::findInBrowser() const Package *pkg = currentPackage(); - ostringstream stream; + std::ostringstream stream; stream << '^' << quoted(pkg->displayName()) << "$ ^" << quoted(m_index->name()) << '$'; browser->setFilter(stream.str()); } @@ -438,7 +436,7 @@ void AboutIndexDelegate::aboutPackage() } catch(const reapack_error &) {} - m_dialog->setDelegate(make_shared<AboutPackageDelegate>(pkg, current)); + m_dialog->setDelegate(std::make_shared<AboutPackageDelegate>(pkg, current)); } void AboutIndexDelegate::itemCopy() @@ -546,7 +544,7 @@ void AboutPackageDelegate::init(About *dialog) void AboutPackageDelegate::updateList(const int index) { - const pair<Source::Section, const char *> sectionMap[] = { + const std::pair<Source::Section, const char *> sectionMap[] = { {Source::MainSection, "Main"}, {Source::MIDIEditorSection, "MIDI Editor"}, {Source::MIDIInlineEditorSection, "MIDI Inline Editor"}, @@ -558,7 +556,7 @@ void AboutPackageDelegate::updateList(const int index) return; const Version *ver = m_package->version(index); - ostringstream stream; + std::ostringstream stream; stream << *ver; Win32::setWindowText(m_dialog->getControl(IDC_CHANGELOG), stream.str().c_str()); @@ -566,10 +564,10 @@ void AboutPackageDelegate::updateList(const int index) for(const Source *src : ver->sources()) { int sections = src->sections(); - string actionList; + std::string actionList; if(sections) { - vector<string> sectionNames; + std::vector<std::string> sectionNames; for(const auto &[section, name] : sectionMap) { if(sections & section) { @@ -614,7 +612,7 @@ void AboutPackageDelegate::onCommand(const int id) { switch(id) { case IDC_ACTION: - m_dialog->setDelegate(make_shared<AboutIndexDelegate>(m_index)); + m_dialog->setDelegate(std::make_shared<AboutIndexDelegate>(m_index)); break; case ACTION_COPY_URL: copySourceUrl(); @@ -649,7 +647,7 @@ void AboutPackageDelegate::locate() if(!FS::exists(path)) return; - const string &arg = String::format(R"(/select,"%s")", + const std::string &arg = String::format(R"(/select,"%s")", path.prependRoot().join().c_str()); Win32::shellExecute("explorer.exe", arg.c_str()); diff --git a/src/api_misc.cpp b/src/api_misc.cpp @@ -21,8 +21,6 @@ #include "browser.hpp" #include "reapack.hpp" -using namespace std; - DEFINE_API(void, BrowsePackages, ((const char*, filter)), R"(Opens the package browser with the given filter string.)", { @@ -35,7 +33,7 @@ DEFINE_API(int, CompareVersions, ((const char*, ver1))((const char*, ver2)) R"(Returns 0 if both versions are equal, a positive value if ver1 is higher than ver2 and a negative value otherwise.)", { VersionName a, b; - string error; + std::string error; b.tryParse(ver2, &error); a.tryParse(ver1, &error); diff --git a/src/api_package.cpp b/src/api_package.cpp @@ -26,14 +26,12 @@ #include "remote.hpp" #include "transaction.hpp" -using namespace std; - struct PackageEntry { Registry::Entry regEntry; - vector<Registry::File> files; + std::vector<Registry::File> files; }; -static set<PackageEntry *> s_entries; +static std::set<PackageEntry *> s_entries; DEFINE_API(bool, AboutInstalledPackage, ((PackageEntry*, entry)), R"(Show the about dialog of the given package entry. @@ -53,7 +51,7 @@ The repository index is downloaded asynchronously if the cached copy doesn't exi if(!tx) return false; - const vector<Remote> repos = {repo}; + const std::vector<Remote> repos{repo}; tx->fetchIndexes(repos); tx->onFinish >> [=] { @@ -63,7 +61,8 @@ The repository index is downloaded asynchronously if the cached copy doesn't exi const Package *pkg = indexes.front()->find(entryCopy.category, entryCopy.package); if(pkg) - g_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>(pkg, entryCopy.version)); + g_reapack->about()->setDelegate(std::make_shared<AboutPackageDelegate>( + pkg, entryCopy.version)); }; tx->runTasks(); diff --git a/src/api_repo.cpp b/src/api_repo.cpp @@ -25,8 +25,6 @@ #include <boost/lexical_cast.hpp> #include <boost/logic/tribool_io.hpp> // required to get correct tribool casts -using namespace std; - DEFINE_API(bool, AboutRepository, ((const char*, repoName)), R"(Show the about dialog of the given repository. Returns true if the repository exists in the user configuration. The repository index is downloaded asynchronously if the cached copy doesn't exist or is older than one week.)", diff --git a/src/archive.cpp b/src/archive.cpp @@ -34,8 +34,6 @@ #include <zlib/unzip.h> #include <zlib/ioapi.h> -using namespace std; - static const Path ARCHIVE_TOC("toc"); static const size_t BUFFER_SIZE = 4096; @@ -63,8 +61,8 @@ static void *wide_fopen(voidpf, const void *filename, int mode) #endif struct ImportArchive { - void importRemote(const string &); - void importPackage(const string &); + void importRemote(const std::string &); + void importPackage(const std::string &); ArchiveReaderPtr m_reader; RemoteList *m_remotes; @@ -72,12 +70,12 @@ struct ImportArchive { IndexPtr m_lastIndex; }; -void Archive::import(const string &path) +void Archive::import(const std::string &path) { - ImportArchive state{make_shared<ArchiveReader>(path), + ImportArchive state{std::make_shared<ArchiveReader>(path), &g_reapack->config()->remotes}; - stringstream toc; + std::stringstream toc; if(const int err = state.m_reader->extractFile(ARCHIVE_TOC, toc)) throw reapack_error(String::format( "Cannot locate the table of contents (%d)", err)); @@ -86,12 +84,12 @@ void Archive::import(const string &path) if(!(state.m_tx = g_reapack->setupTransaction())) return; - string line; - while(getline(toc, line)) { + std::string line; + while(std::getline(toc, line)) { if(line.size() <= 5) // 5 is the length of the line type prefix continue; - const string &data = line.substr(5); + const std::string &data = line.substr(5); try { switch(line[0]) { @@ -115,7 +113,7 @@ void Archive::import(const string &path) state.m_tx->runTasks(); } -void ImportArchive::importRemote(const string &data) +void ImportArchive::importRemote(const std::string &data) { m_lastIndex = nullptr; // clear the previous repository Remote remote = Remote::fromString(data); @@ -135,17 +133,17 @@ void ImportArchive::importRemote(const string &data) m_lastIndex = Index::load(remote.name()); } -void ImportArchive::importPackage(const string &data) +void ImportArchive::importPackage(const std::string &data) { // don't report an error if the index isn't loaded assuming we already // did when failing to import the repository above if(!m_lastIndex) return; - string categoryName, packageName, versionName; + std::string categoryName, packageName, versionName; bool pinned; - istringstream stream(data); + std::istringstream stream(data); stream >> quoted(categoryName) >> quoted(packageName) >> quoted(versionName) >> pinned; @@ -184,7 +182,7 @@ ArchiveReader::~ArchiveReader() int ArchiveReader::extractFile(const Path &path) { - ofstream stream; + std::ofstream stream; if(FS::open(stream, path)) return extractFile(path, stream); @@ -194,7 +192,7 @@ int ArchiveReader::extractFile(const Path &path) } } -int ArchiveReader::extractFile(const Path &path, ostream &stream) noexcept +int ArchiveReader::extractFile(const Path &path, std::ostream &stream) noexcept { int status = unzLocateFile(m_zip, path.join(false).c_str(), false); if(status != UNZ_OK) @@ -204,7 +202,7 @@ int ArchiveReader::extractFile(const Path &path, ostream &stream) noexcept if(status != UNZ_OK) return status; - string buffer(BUFFER_SIZE, 0); + std::string buffer(BUFFER_SIZE, 0); const auto readChunk = [&] { return unzReadCurrentFile(m_zip, &buffer[0], (int)buffer.size()); @@ -228,7 +226,7 @@ FileExtractor::FileExtractor(const Path &target, const ArchiveReaderPtr &reader) bool FileExtractor::run() { - ofstream stream; + std::ofstream stream; if(!FS::open(stream, m_path.temp())) { setError({FS::lastError(), m_path.temp().join()}); return false; @@ -267,7 +265,7 @@ ArchiveWriter::~ArchiveWriter() int ArchiveWriter::addFile(const Path &path) { - ifstream stream; + std::ifstream stream; if(FS::open(stream, path)) return addFile(path, stream); @@ -277,7 +275,7 @@ int ArchiveWriter::addFile(const Path &path) } } -int ArchiveWriter::addFile(const Path &path, istream &stream) noexcept +int ArchiveWriter::addFile(const Path &path, std::istream &stream) noexcept { const int status = zipOpenNewFileInZip(m_zip, path.join(false).c_str(), nullptr, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, Z_DEFAULT_COMPRESSION); @@ -285,7 +283,7 @@ int ArchiveWriter::addFile(const Path &path, istream &stream) noexcept if(status != ZIP_OK) return status; - string buffer(BUFFER_SIZE, 0); + std::string buffer(BUFFER_SIZE, 0); const auto readChunk = [&] { stream.read(&buffer[0], buffer.size()); @@ -310,7 +308,7 @@ FileCompressor::FileCompressor(const Path &target, const ArchiveWriterPtr &write bool FileCompressor::run() { - ifstream stream; + std::ifstream stream; if(!FS::open(stream, m_path)) { setError({ String::format("Could not open file for export (%s)", FS::lastError()), diff --git a/src/archive_tasks.cpp b/src/archive_tasks.cpp @@ -23,35 +23,36 @@ #include "index.hpp" #include "reapack.hpp" #include "remote.hpp" +#include "string.hpp" #include "transaction.hpp" #include <iomanip> #include <sstream> -using namespace std; - static const Path ARCHIVE_TOC("toc"); -ExportTask::ExportTask(const string &path, Transaction *tx) +ExportTask::ExportTask(const std::string &path, Transaction *tx) : Task(tx), m_path(path) { } bool ExportTask::start() { - stringstream toc; + std::stringstream toc; ArchiveWriterPtr writer; try { - writer = make_shared<ArchiveWriter>(m_path.temp()); + writer = std::make_shared<ArchiveWriter>(m_path.temp()); } catch(const reapack_error &e) { - tx()->receipt()->addError({string("Could not open archive for writing: ") + - e.what(), m_path.temp().join()}); + tx()->receipt()->addError({ + String::format("Could not open archive for writing: %s", e.what()), + m_path.temp().join() + }); return false; } - vector<FileCompressor *> jobs; + std::vector<FileCompressor *> jobs; for(const Remote &remote : g_reapack->config()->remotes.getEnabled()) { bool addedRemote = false; @@ -95,8 +96,10 @@ bool ExportTask::start() void ExportTask::commit() { if(!FS::rename(m_path)) { - tx()->receipt()->addError({string("Could not move to permanent location: ") + - FS::lastError(), m_path.target().prependRoot().join()}); + tx()->receipt()->addError({ + String::format("Could not move to permanent location: %s", FS::lastError()), + m_path.target().prependRoot().join() + }); } } diff --git a/src/browser.cpp b/src/browser.cpp @@ -29,8 +29,6 @@ #include "transaction.hpp" #include "win32.hpp" -using namespace std; - enum Timers { TIMER_FILTER = 1, TIMER_ABOUT }; Browser::Browser() @@ -70,9 +68,9 @@ void Browser::onInit() }); m_list->onActivate >> [=] { aboutPackage(m_list->itemUnderMouse()); }; - m_list->onSelect >> bind(&Browser::onSelection, this); - m_list->onFillContextMenu >> bind(&Browser::fillContextMenu, this, - placeholders::_1, placeholders::_2); + m_list->onSelect >> std::bind(&Browser::onSelection, this); + m_list->onFillContextMenu >> std::bind(&Browser::fillContextMenu, this, + std::placeholders::_1, std::placeholders::_2); m_list->sortByColumn(1); Dialog::onInit(); @@ -108,6 +106,8 @@ void Browser::onClose() void Browser::onCommand(const int id, const int event) { + using namespace std::placeholders; + switch(id) { case IDC_TABS: if(event == CBN_SELCHANGE) @@ -135,25 +135,25 @@ void Browser::onCommand(const int id, const int event) actionsButton(); break; case ACTION_LATEST: - currentDo(bind(&Browser::installLatest, this, placeholders::_1, true)); + currentDo(std::bind(&Browser::installLatest, this, _1, true)); break; case ACTION_LATEST_ALL: installLatestAll(); break; case ACTION_REINSTALL: - currentDo(bind(&Browser::reinstall, this, placeholders::_1, true)); + currentDo(std::bind(&Browser::reinstall, this, _1, true)); break; case ACTION_REINSTALL_ALL: - selectionDo(bind(&Browser::reinstall, this, placeholders::_1, false)); + selectionDo(std::bind(&Browser::reinstall, this, _1, false)); break; case ACTION_UNINSTALL: - currentDo(bind(&Browser::uninstall, this, placeholders::_1, true)); + currentDo(std::bind(&Browser::uninstall, this, _1, true)); break; case ACTION_UNINSTALL_ALL: - selectionDo(bind(&Browser::uninstall, this, placeholders::_1, false)); + selectionDo(std::bind(&Browser::uninstall, this, _1, false)); break; case ACTION_PIN: - currentDo(bind(&Browser::togglePin, this, placeholders::_1)); + currentDo(std::bind(&Browser::togglePin, this, _1)); break; case ACTION_ABOUT_PKG: aboutPackage(m_currentIndex); @@ -162,7 +162,7 @@ void Browser::onCommand(const int id, const int event) aboutRemote(m_currentIndex); break; case ACTION_RESET_ALL: - selectionDo(bind(&Browser::resetActions, this, placeholders::_1)); + selectionDo(std::bind(&Browser::resetActions, this, _1)); break; case ACTION_COPY: copy(); @@ -180,7 +180,7 @@ void Browser::onCommand(const int id, const int event) g_reapack->manageRemotes(); break; case ACTION_FILTERTYPE: - m_typeFilter = nullopt; + m_typeFilter = std::nullopt; fillList(); break; case IDOK: @@ -200,7 +200,7 @@ void Browser::onCommand(const int id, const int event) break; default: if(id >> 8 == ACTION_VERSION) - currentDo(bind(&Browser::installVersion, this, placeholders::_1, id & 0xff)); + currentDo(std::bind(&Browser::installVersion, this, _1, id & 0xff)); else if(id >> 8 == ACTION_FILTERTYPE) { m_typeFilter = static_cast<Package::Type>(id & 0xff); fillList(); @@ -313,7 +313,7 @@ void Browser::updateDisplayLabel() void Browser::displayButton() { - static map<const char *, Package::Type> types = { + static std::pair<const char *, Package::Type> types[]{ {"&Automation Items", Package::AutomationItemType}, {"&Effects", Package::EffectType}, {"E&xtensions", Package::ExtensionType}, @@ -425,7 +425,7 @@ void Browser::refresh(const bool stale) break; } - const vector<Remote> &remotes = g_reapack->config()->remotes.getEnabled(); + const std::vector<Remote> &remotes = g_reapack->config()->remotes.getEnabled(); if(remotes.empty()) { if(!isVisible() || stale) { @@ -466,11 +466,11 @@ void Browser::refresh(const bool stale) } } -void Browser::populate(const vector<IndexPtr> &indexes, const Registry *reg) +void Browser::populate(const std::vector<IndexPtr> &indexes, const Registry *reg) { // keep previous entries in memory a bit longer for #transferActions - vector<Entry> oldEntries; - swap(m_entries, oldEntries); + std::vector<Entry> oldEntries; + std::swap(m_entries, oldEntries); m_currentIndex = -1; @@ -492,7 +492,7 @@ void Browser::populate(const vector<IndexPtr> &indexes, const Registry *reg) show(); } -void Browser::setFilter(const string &newFilter) +void Browser::setFilter(const std::string &newFilter) { Win32::setWindowText(m_filter, newFilter.c_str()); updateFilter(); // don't wait for the timer, update now! @@ -501,8 +501,8 @@ void Browser::setFilter(const string &newFilter) void Browser::transferActions() { - list<Entry *> oldActions; - swap(m_actions, oldActions); + std::list<Entry *> oldActions; + std::swap(m_actions, oldActions); for(Entry *oldEntry : oldActions) { const auto &entryIt = find(m_entries.begin(), m_entries.end(), *oldEntry); @@ -537,8 +537,8 @@ void Browser::fillList() const int scroll = m_list->scroll(); - vector<int> selectIndexes = m_list->selection(); - vector<const Entry *> oldSelection(selectIndexes.size()); + std::vector<int> selectIndexes = m_list->selection(); + std::vector<const Entry *> oldSelection(selectIndexes.size()); for(size_t i = 0; i < selectIndexes.size(); i++) oldSelection[i] = static_cast<Entry *>(m_list->row(selectIndexes[i])->userData); selectIndexes.clear(); // will put new indexes below @@ -617,7 +617,7 @@ void Browser::aboutPackage(const int index, const bool focus) const Entry *entry = getEntry(index); if(entry && entry->package) { - g_reapack->about()->setDelegate(make_shared<AboutPackageDelegate>( + g_reapack->about()->setDelegate(std::make_shared<AboutPackageDelegate>( entry->package, entry->regEntry.version), focus); } } @@ -626,7 +626,7 @@ void Browser::aboutRemote(const int index, const bool focus) { if(const Entry *entry = getEntry(index)) { g_reapack->about()->setDelegate( - make_shared<AboutIndexDelegate>(entry->index), focus); + std::make_shared<AboutIndexDelegate>(entry->index), focus); } } @@ -651,7 +651,7 @@ void Browser::installLatestAll() } } - selectionDo(bind(&Browser::installLatest, this, placeholders::_1, false)); + selectionDo(std::bind(&Browser::installLatest, this, std::placeholders::_1, false)); } void Browser::installLatest(const int index, const bool toggle) @@ -706,7 +706,7 @@ void Browser::togglePin(const int index) const bool newVal = !entry->pin.value_or(entry->regEntry.pinned); if(newVal == entry->regEntry.pinned) - entry->pin = nullopt; + entry->pin = std::nullopt; else entry->pin = newVal; @@ -723,7 +723,7 @@ void Browser::toggleTarget(const int index, const Version *target) Entry *entry = getEntry(index); if(entry->target && *entry->target == target) - entry->target = nullopt; + entry->target = std::nullopt; else entry->target = target; @@ -735,7 +735,7 @@ void Browser::resetTarget(const int index) Entry *entry = getEntry(index); if(entry->target) { - entry->target = nullopt; + entry->target = std::nullopt; updateAction(index); } } @@ -745,9 +745,9 @@ void Browser::resetActions(const int index) Entry *entry = getEntry(index); if(entry->target) - entry->target = nullopt; + entry->target = std::nullopt; if(entry->pin) - entry->pin = nullopt; + entry->pin = std::nullopt; updateAction(index); } @@ -772,7 +772,7 @@ void Browser::updateAction(const int index) m_list->row(index)->setCell(0, entry->displayState()); } -void Browser::listDo(const function<void (int)> &func, const vector<int> &indexes) +void Browser::listDo(const std::function<void (int)> &func, const std::vector<int> &indexes) { ListView::BeginEdit edit(m_list); @@ -799,24 +799,24 @@ void Browser::listDo(const function<void (int)> &func, const vector<int> &indexe enable(m_applyBtn); } -void Browser::currentDo(const function<void (int)> &func) +void Browser::currentDo(const std::function<void (int)> &func) { listDo(func, {m_currentIndex}); } -void Browser::selectionDo(const function<void (int)> &func) +void Browser::selectionDo(const std::function<void (int)> &func) { listDo(func, m_list->selection()); } auto Browser::currentView() const -> View { - return (View)SendMessage(m_view, CB_GETCURSEL, 0, 0); + return static_cast<View>(SendMessage(m_view, CB_GETCURSEL, 0, 0)); } void Browser::copy() { - vector<string> values; + std::vector<std::string> values; for(const int index : m_list->selection(false)) values.push_back(getEntry(index)->displayName()); @@ -859,11 +859,11 @@ bool Browser::apply() else tx->uninstall(entry->regEntry); - entry->target = nullopt; + entry->target = std::nullopt; } else if(entry->pin) { tx->setPinned(entry->regEntry, *entry->pin); - entry->pin = nullopt; + entry->pin = std::nullopt; } } diff --git a/src/browser_entry.cpp b/src/browser_entry.cpp @@ -25,8 +25,6 @@ #include <boost/range/adaptor/reversed.hpp> -using namespace std; - Browser::Entry::Entry(const Package *pkg, const Registry::Entry &re, const IndexPtr &i) : m_flags(0), regEntry(re), package(pkg), index(i), current(nullptr) { @@ -58,9 +56,9 @@ Browser::Entry::Entry(const Registry::Entry &re, const IndexPtr &i) index(i), current(nullptr), latest(nullptr) {} -string Browser::Entry::displayState() const +std::string Browser::Entry::displayState() const { - string state; + std::string state; if(test(ObsoleteFlag)) state += 'o'; @@ -82,22 +80,22 @@ string Browser::Entry::displayState() const return state; } -const string &Browser::Entry::indexName() const +const std::string &Browser::Entry::indexName() const { return package ? package->category()->index()->name() : regEntry.remote; } -const string &Browser::Entry::categoryName() const +const std::string &Browser::Entry::categoryName() const { return package ? package->category()->name() : regEntry.category; } -const string &Browser::Entry::packageName() const +const std::string &Browser::Entry::packageName() const { return package ? package->name() : regEntry.package; } -string Browser::Entry::displayName() const +std::string Browser::Entry::displayName() const { if(package) return package->displayName(); @@ -110,14 +108,14 @@ Package::Type Browser::Entry::type() const return latest ? package->type() : regEntry.type; } -string Browser::Entry::displayType() const +std::string Browser::Entry::displayType() const { return package ? package->displayType() : Package::displayType(regEntry.type); } -string Browser::Entry::displayVersion() const +std::string Browser::Entry::displayVersion() const { - string display; + std::string display; if(test(InstalledFlag)) display = regEntry.version.toString(); @@ -140,7 +138,7 @@ const VersionName *Browser::Entry::sortVersion() const return &latest->name(); } -string Browser::Entry::displayAuthor() const +std::string Browser::Entry::displayAuthor() const { return latest ? latest->displayAuthor() : Version::displayAuthor(regEntry.author); } @@ -150,19 +148,19 @@ const Time *Browser::Entry::lastUpdate() const return latest ? &latest->time() : nullptr; } -void Browser::Entry::updateRow(const ListView::RowPtr &row) const +void Browser::Entry::updateRow(ListView::Row *row) const { int c = 0; - const Time *time = lastUpdate(); + Time *time = const_cast<Time *>(lastUpdate()); row->setCell(c++, displayState()); row->setCell(c++, displayName()); row->setCell(c++, categoryName()); - row->setCell(c++, displayVersion(), (void *)sortVersion()); + row->setCell(c++, displayVersion(), const_cast<VersionName *>(sortVersion())); row->setCell(c++, displayAuthor()); row->setCell(c++, displayType()); row->setCell(c++, indexName()); - row->setCell(c++, time ? time->toString() : string(), (void *)time); + row->setCell(c++, time ? time->toString() : std::string{}, time); } void Browser::Entry::fillMenu(Menu &menu) const diff --git a/src/browser_entry.hpp b/src/browser_entry.hpp @@ -68,7 +68,7 @@ public: std::string displayAuthor() const; const Time *lastUpdate() const; - void updateRow(const ListView::RowPtr &) const; + void updateRow(ListView::Row *) const; void fillMenu(Menu &) const; int possibleActions(bool allowToggle) const; diff --git a/src/config.cpp b/src/config.cpp @@ -20,14 +20,14 @@ #include "path.hpp" #include "win32.hpp" +#include <algorithm> + #ifdef _WIN32 # include <windows.h> #else # include <swell/swell.h> #endif -using namespace std; - static const char *GENERAL_GRP = "general"; static const char *VERSION_KEY = "version"; @@ -52,9 +52,9 @@ static const char *SIZE_KEY = "size"; static const char *REMOTES_GRP = "remotes"; static const char *REMOTE_KEY = "remote"; -inline static string nKey(const char *key, const unsigned int i) +static std::string nKey(const char *key, const unsigned int i) { - return key + to_string(i); + return key + std::to_string(i); } Config::Config(const Path &path) @@ -78,8 +78,8 @@ void Config::resetOptions() void Config::restoreSelfRemote() { - const string name = "ReaPack"; - const string url = "https://reapack.com/index.xml"; + const std::string name = "ReaPack"; + const std::string url = "https://reapack.com/index.xml"; Remote remote = remotes.get(name); remote.setName(name); @@ -185,7 +185,7 @@ void Config::readRemotes() m_remotesIniSize = getUInt(REMOTES_GRP, SIZE_KEY); for(unsigned int i = 0; i < m_remotesIniSize; i++) { - const string data = getString(REMOTES_GRP, nKey(REMOTE_KEY, i).c_str()); + const std::string data = getString(REMOTES_GRP, nKey(REMOTE_KEY, i).c_str()); remotes.add(Remote::fromString(data)); } @@ -193,7 +193,7 @@ void Config::readRemotes() void Config::writeRemotes() { - m_remotesIniSize = max((unsigned int)remotes.size(), m_remotesIniSize); + m_remotesIniSize = std::max(static_cast<unsigned int>(remotes.size()), m_remotesIniSize); unsigned int i = 0; for(auto it = remotes.begin(); it != remotes.end(); it++, i++) @@ -204,12 +204,12 @@ void Config::writeRemotes() setUInt(REMOTES_GRP, SIZE_KEY, m_remotesIniSize = i); } -string Config::getString(const char *group, const char *key, const string &fallback) const +std::string Config::getString(const char *group, const char *key, const std::string &fallback) const { return Win32::getPrivateProfileString(group, key, fallback.c_str(), m_path.c_str()); } -void Config::setString(const char *group, const char *key, const string &val) const +void Config::setString(const char *group, const char *key, const std::string &val) const { Win32::writePrivateProfileString(group, key, val.c_str(), m_path.c_str()); } @@ -227,7 +227,7 @@ bool Config::getBool(const char *group, const char *key, const bool fallback) co void Config::setUInt(const char *group, const char *key, const unsigned int val) const { - setString(group, key, to_string(val)); + setString(group, key, std::to_string(val)); } void Config::deleteKey(const char *group, const char *key) const diff --git a/src/control.cpp b/src/control.cpp @@ -17,9 +17,7 @@ #include "control.hpp" -using namespace std; - -map<HWND, InhibitControl *> InhibitControl::s_lock; +std::map<HWND, InhibitControl *> InhibitControl::s_lock; void InhibitControl::inhibitRedraw(const bool inhibit) { diff --git a/src/database.cpp b/src/database.cpp @@ -22,9 +22,7 @@ #include <cinttypes> #include <sqlite3.h> -using namespace std; - -Database::Database(const string &fn) +Database::Database(const std::string &fn) : m_savePoint(0) { if(sqlite3_open(fn.empty() ? ":memory:" : fn.c_str(), &m_db)) { @@ -145,7 +143,7 @@ Statement::~Statement() sqlite3_finalize(m_stmt); } -void Statement::bind(const int index, const string &text) +void Statement::bind(const int index, const std::string &text) { if(sqlite3_bind_text(m_stmt, index, text.c_str(), -1, SQLITE_TRANSIENT)) throw m_db->lastError(); @@ -187,12 +185,12 @@ int64_t Statement::intColumn(const int index) const return sqlite3_column_int64(m_stmt, index); } -string Statement::stringColumn(const int index) const +std::string Statement::stringColumn(const int index) const { - char *col = (char *)sqlite3_column_text(m_stmt, index); + const unsigned char *col = sqlite3_column_text(m_stmt, index); if(col) - return col; + return reinterpret_cast<const char *>(col); else return {}; } diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -29,8 +29,6 @@ # include <windowsx.h> #endif -using namespace std; - std::map<HWND, Dialog *> Dialog::s_instances; WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) @@ -131,7 +129,7 @@ Dialog::~Dialog() { plugin_register("-accelerator", &m_accel); - const set<int> timers = m_timers; // make an immutable copy + const std::set<int> timers = m_timers; // make an immutable copy for(const int id : timers) stopTimer(id); @@ -194,6 +192,8 @@ void Dialog::close(const INT_PTR result) void Dialog::center() { + using std::min, std::max; + RECT dialogRect, parentRect; GetWindowRect(m_handle, &dialogRect); @@ -238,6 +238,8 @@ void Dialog::center() void Dialog::boundedMove(int x, int y) { + using std::min, std::max, std::abs; + RECT rect; GetWindowRect(m_handle, &rect); @@ -317,7 +319,7 @@ void Dialog::stopTimer(int id) m_timers.erase(id); } -void Dialog::setClipboard(const string &text) +void Dialog::setClipboard(const std::string &text) { const HANDLE mem = Win32::globalCopy(text); @@ -331,7 +333,7 @@ void Dialog::setClipboard(const string &text) CloseClipboard(); } -void Dialog::setClipboard(const vector<string> &values) +void Dialog::setClipboard(const std::vector<std::string> &values) { #ifdef _WIN32 constexpr const char *nl = "\r\n"; @@ -350,12 +352,11 @@ HWND Dialog::getControl(const int idc) void Dialog::setAnchor(HWND handle, const int flags) { - const float left = (float)min(1, flags & AnchorLeft); - const float top = (float)min(1, flags & AnchorTop); - const float right = (float)min(1, flags & AnchorRight); - const float bottom = (float)min(1, flags & AnchorBottom); - - m_resizer.init_itemhwnd(handle, left, top, right, bottom); + m_resizer.init_itemhwnd(handle, + static_cast<float>(flags & AnchorLeft), + static_cast<float>(flags & AnchorTop), + static_cast<float>(flags & AnchorRight), + static_cast<float>(flags & AnchorBottom)); } void Dialog::setAnchorPos(HWND handle, @@ -455,7 +456,7 @@ void Dialog::onContextMenu(HWND target, const int x, const int y) #ifndef _WIN32 // special treatment for SWELL - swap(rect.top, rect.bottom); + std::swap(rect.top, rect.bottom); #endif const POINT point{x, y}; diff --git a/src/download.cpp b/src/download.cpp @@ -25,14 +25,12 @@ #include <reaper_plugin_functions.h> -using namespace std; - static const int DOWNLOAD_TIMEOUT = 15; // to set the amount of concurrent downloads, change the size of // the m_pool member in ThreadPool (thread.hpp) static CURLSH *g_curlShare = nullptr; -static mutex g_curlMutex; +static std::mutex g_curlMutex; static void LockCurlMutex(CURL *, curl_lock_data, curl_lock_access, void *) { @@ -104,12 +102,12 @@ int Download::UpdateProgress(void *ptr, const double, const double, return static_cast<Download *>(ptr)->aborted(); } -Download::Download(const string &url, const NetworkOpts &opts, const int flags) +Download::Download(const std::string &url, const NetworkOpts &opts, const int flags) : m_url(url), m_opts(opts), m_flags(flags) { } -void Download::setName(const string &name) +void Download::setName(const std::string &name) { setSummary("Downloading %s: " + name); } @@ -121,9 +119,9 @@ bool Download::run() Hash::Algorithm algo; if(!m_expectedChecksum.empty()) { if(Hash::getAlgorithm(m_expectedChecksum, &algo)) - write.hash = make_unique<Hash>(algo); + write.hash = std::make_unique<Hash>(algo); else { - const string &error = String::format( + const std::string &error = String::format( "Unsupported checksum: %s", m_expectedChecksum.c_str()); setError({error, m_url}); return false; @@ -161,13 +159,13 @@ bool Download::run() closeStream(); if(res != CURLE_OK) { - const string &err = String::format( + const std::string &err = String::format( "%s (%d): %s", curl_easy_strerror(res), res, errbuf); setError({err, m_url}); return false; } else if(write.hash && write.hash->digest() != m_expectedChecksum) { - const string &err = String::format( + const std::string &err = String::format( "Checksum mismatch.\nExpected: %s\nActual: %s", m_expectedChecksum.c_str(), write.hash->digest().c_str() ); @@ -186,13 +184,13 @@ void Download::WriteContext::write(const char *data, const size_t len) hash->addData(data, len); } -MemoryDownload::MemoryDownload(const string &url, const NetworkOpts &opts, int flags) +MemoryDownload::MemoryDownload(const std::string &url, const NetworkOpts &opts, int flags) : Download(url, opts, flags) { setName(url); } -FileDownload::FileDownload(const Path &target, const string &url, +FileDownload::FileDownload(const Path &target, const std::string &url, const NetworkOpts &opts, int flags) : Download(url, opts, flags), m_path(target) { @@ -207,7 +205,7 @@ bool FileDownload::save() return FS::remove(m_path.temp()); } -ostream *FileDownload::openStream() +std::ostream *FileDownload::openStream() { if(FS::open(m_stream, m_path.temp())) return &m_stream; diff --git a/src/filedialog.cpp b/src/filedialog.cpp @@ -24,10 +24,8 @@ # include <swell.h> #endif -using namespace std; - #ifdef _WIN32 -static string getFileName(BOOL(__stdcall *func)(LPOPENFILENAME), +static std::string getFileName(BOOL(__stdcall *func)(LPOPENFILENAME), HWND parent, HINSTANCE instance, const char *title, const Path &initialDir, const Win32::char_type *filters, const Win32::char_type *defaultExt) { @@ -39,17 +37,17 @@ static string getFileName(BOOL(__stdcall *func)(LPOPENFILENAME), OPENFILENAME of{sizeof(OPENFILENAME), parent, instance}; of.lpstrFilter = filters; of.lpstrFile = pathBuffer; - of.nMaxFile = static_cast<DWORD>(size(pathBuffer)); + of.nMaxFile = static_cast<DWORD>(std::size(pathBuffer)); of.lpstrInitialDir = wideInitialDir.c_str(); of.lpstrTitle = wideTitle.c_str(); of.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT; of.lpstrDefExt = defaultExt; - return func(&of) ? Win32::narrow(pathBuffer) : string(); + return func(&of) ? Win32::narrow(pathBuffer) : std::string{}; } #endif -string FileDialog::getOpenFileName(HWND parent, HINSTANCE instance, +std::string FileDialog::getOpenFileName(HWND parent, HINSTANCE instance, const char *title, const Path &initialDir, const Win32::char_type *filters, const Win32::char_type *defaultExt) { @@ -59,11 +57,11 @@ string FileDialog::getOpenFileName(HWND parent, HINSTANCE instance, #else const char *path = BrowseForFiles(title, initialDir.join().c_str(), nullptr, false, filters); - return path ? path : string(); + return path ? path : std::string{}; #endif } -string FileDialog::getSaveFileName(HWND parent, HINSTANCE instance, +std::string FileDialog::getSaveFileName(HWND parent, HINSTANCE instance, const char *title, const Path &initialDir, const Win32::char_type *filters, const Win32::char_type *defaultExt) { @@ -71,7 +69,7 @@ string FileDialog::getSaveFileName(HWND parent, HINSTANCE instance, return getFileName(&GetSaveFileName, parent, instance, title, initialDir, filters, defaultExt); #else - char path[4096] = {}; + char path[4096]{}; if(BrowseForSaveFile(title, initialDir.join().c_str(), nullptr, filters, path, sizeof(path))) diff --git a/src/filesystem.cpp b/src/filesystem.cpp @@ -30,8 +30,6 @@ # define stat _stat #endif -using namespace std; - static auto nativePath(const Path &path) { return Win32::widen(path.prependRoot().join()); @@ -61,24 +59,24 @@ FILE *FS::open(const Path &path) #endif } -bool FS::open(ifstream &stream, const Path &path) +bool FS::open(std::ifstream &stream, const Path &path) { - stream.open(nativePath(path), ios_base::binary); + stream.open(nativePath(path), std::ios_base::binary); return stream.good(); } -bool FS::open(ofstream &stream, const Path &path) +bool FS::open(std::ofstream &stream, const Path &path) { if(!mkdir(path.dirname())) return false; - stream.open(nativePath(path), ios_base::binary); + stream.open(nativePath(path), std::ios_base::binary); return stream.good(); } -bool FS::write(const Path &path, const string &contents) +bool FS::write(const Path &path, const std::string &contents) { - ofstream file; + std::ofstream file; if(!open(file, path)) return false; @@ -182,7 +180,7 @@ bool FS::mkdir(const Path &path) Path fullPath = Path::root(); - for(const string &dir : path) { + for(const std::string &dir : path) { fullPath.append(dir); const auto &joined = Win32::widen(fullPath.join()); diff --git a/src/import.cpp b/src/import.cpp @@ -30,8 +30,6 @@ #include <boost/algorithm/string/trim.hpp> -using namespace std; - static const char *TITLE = "Import repositories"; static const char *DISCOVER_URL = "https://reapack.com/repos"; @@ -89,7 +87,7 @@ ThreadPool *Import::setupPool() { if(!m_pool) { m_state = OK; - m_pool = make_unique<ThreadPool>(); + m_pool = std::make_unique<ThreadPool>(); m_pool->onAbort >> [=] { if(!m_state) m_state = Aborted; }; m_pool->onDone >> [=] { @@ -120,8 +118,8 @@ void Import::fetch() const auto &opts = g_reapack->config()->network; size_t index = 0; - stringstream stream(Win32::getWindowText(m_url)); - string url; + std::stringstream stream(Win32::getWindowText(m_url)); + std::string url; while(getline(stream, url)) { boost::algorithm::trim(url); diff --git a/src/index.cpp b/src/index.cpp @@ -24,14 +24,12 @@ #include <WDL/tinyxml/tinyxml.h> -using namespace std; - -Path Index::pathFor(const string &name) +Path Index::pathFor(const std::string &name) { return Path::CACHE + (name + ".xml"); } -IndexPtr Index::load(const string &name, const char *data) +IndexPtr Index::load(const std::string &name, const char *data) { TiXmlDocument doc; @@ -66,7 +64,7 @@ IndexPtr Index::load(const string &name, const char *data) // ensure the memory is released if an exception is // thrown during the loading process - unique_ptr<Index> ptr(ri); + std::unique_ptr<Index> ptr(ri); switch(version) { case 1: @@ -80,7 +78,7 @@ IndexPtr Index::load(const string &name, const char *data) return IndexPtr(ri); } -Index::Index(const string &name) +Index::Index(const std::string &name) : m_name(name) { } @@ -91,7 +89,7 @@ Index::~Index() delete cat; } -void Index::setName(const string &newName) +void Index::setName(const std::string &newName) { if(!m_name.empty()) throw reapack_error("index name is already set"); @@ -117,7 +115,7 @@ bool Index::addCategory(const Category *cat) return true; } -const Category *Index::category(const string &name) const +const Category *Index::category(const std::string &name) const { const auto &it = m_catMap.find(name); @@ -127,7 +125,7 @@ const Category *Index::category(const string &name) const return category(it->second); } -const Package *Index::find(const string &catName, const string &pkgName) const +const Package *Index::find(const std::string &catName, const std::string &pkgName) const { if(const Category *cat = category(catName)) return cat->package(pkgName); @@ -135,7 +133,7 @@ const Package *Index::find(const string &catName, const string &pkgName) const return nullptr; } -Category::Category(const string &name, const Index *ri) +Category::Category(const std::string &name, const Index *ri) : m_index(ri), m_name(name) { if(m_name.empty()) @@ -148,7 +146,7 @@ Category::~Category() delete pack; } -string Category::fullName() const +std::string Category::fullName() const { return m_index ? m_index->name() + "/" + m_name : m_name; } @@ -166,7 +164,7 @@ bool Category::addPackage(const Package *pkg) return true; } -const Package *Category::package(const string &name) const +const Package *Category::package(const std::string &name) const { const auto &it = m_pkgMap.find(name); diff --git a/src/index_v1.cpp b/src/index_v1.cpp @@ -22,8 +22,6 @@ #include <sstream> #include <WDL/tinyxml/tinyxml.h> -using namespace std; - static void LoadMetadataV1(TiXmlElement *, Metadata *); static void LoadCategoryV1(TiXmlElement *, Index *); static void LoadPackageV1(TiXmlElement *, Category *); @@ -86,7 +84,7 @@ void LoadCategoryV1(TiXmlElement *catNode, Index *ri) if(!name) name = ""; Category *cat = new Category(name, ri); - unique_ptr<Category> ptr(cat); + std::unique_ptr<Category> ptr(cat); TiXmlElement *packNode = catNode->FirstChildElement("reapack"); @@ -112,7 +110,7 @@ void LoadPackageV1(TiXmlElement *packNode, Category *cat) if(!desc) desc = ""; Package *pack = new Package(Package::getType(type), name, cat); - unique_ptr<Package> ptr(pack); + std::unique_ptr<Package> ptr(pack); pack->setDescription(desc); @@ -139,7 +137,7 @@ void LoadVersionV1(TiXmlElement *verNode, Package *pkg) if(!name) name = ""; Version *ver = new Version(name, pkg); - unique_ptr<Version> ptr(ver); + std::unique_ptr<Version> ptr(ver); const char *author = verNode->Attribute("author"); if(author) ver->setAuthor(author); @@ -186,16 +184,16 @@ void LoadSourceV1(TiXmlElement *node, Version *ver) if(!url) url = ""; Source *src = new Source(file, url, ver); - unique_ptr<Source> ptr(src); + std::unique_ptr<Source> ptr(src); src->setChecksum(checksum); src->setPlatform(platform); src->setTypeOverride(Package::getType(type)); int sections = 0; - string section; - istringstream mainStream(main); - while(getline(mainStream, section, '\x20')) + std::string section; + std::istringstream mainStream(main); + while(std::getline(mainStream, section, '\x20')) sections |= Source::getSection(section.c_str()); src->setSections(sections); diff --git a/src/install.cpp b/src/install.cpp @@ -25,11 +25,9 @@ #include "reapack.hpp" #include "transaction.hpp" -using namespace std; - InstallTask::InstallTask(const Version *ver, const bool pin, const Registry::Entry &re, const ArchiveReaderPtr &reader, Transaction *tx) - : Task(tx), m_version(ver), m_pin(pin), m_oldEntry(move(re)), m_reader(reader), + : Task(tx), m_version(ver), m_pin(pin), m_oldEntry(std::move(re)), m_reader(reader), m_fail(false), m_index(ver->package()->category()->index()->shared_from_this()) { } @@ -41,7 +39,7 @@ bool InstallTask::start() // prevent file conflicts (don't worry, the registry push is reverted) try { - vector<Path> conflicts; + std::vector<Path> conflicts; tx()->registry()->push(m_version, &conflicts); if(!conflicts.empty()) { diff --git a/src/listview.cpp b/src/listview.cpp @@ -26,8 +26,6 @@ #include <boost/algorithm/string/case_conv.hpp> #include <cassert> -using namespace std; - bool ListView_GetScroll(HWND, POINT *); // undocumented macOS SWELL function static int adjustWidth(const int points) @@ -92,15 +90,12 @@ int ListView::addColumn(const Column &col) return index; } -auto ListView::createRow(void *data) -> RowPtr +ListView::Row *ListView::createRow(void *data) { const int index = rowCount(); insertItem(index, index); - RowPtr row = make_shared<Row>(data, this); - m_rows.push_back(row); - - return row; + return m_rows.emplace_back(std::make_unique<Row>(data, this)).get(); } void ListView::insertItem(const int viewIndex, const int rowIndex) @@ -254,10 +249,10 @@ void ListView::setSortArrow(const bool set) void ListView::filter() { - vector<int> hide; + std::vector<int> hide; for(int ri = 0; ri < rowCount(); ++ri) { - RowPtr &row = m_rows[ri]; + const auto &row = m_rows[ri]; if(m_filter.match(row->filterValues())) { if(row->viewIndex == -1) { @@ -285,7 +280,7 @@ void ListView::filter() m_dirty &= ~NeedFilterFlag; } -void ListView::setFilter(const string &newFilter) +void ListView::setFilter(const std::string &newFilter) { if(m_filter != newFilter) { ListView::BeginEdit edit(this); @@ -338,8 +333,8 @@ void ListView::reset() m_cols.clear(); m_customizable = false; - m_sort = nullopt; - m_defaultSort = nullopt; + m_sort = std::nullopt; + m_defaultSort = std::nullopt; } void ListView::setSelected(const int index, const bool select) @@ -363,10 +358,10 @@ int ListView::currentIndex() const return translateBack(internalIndex); } -vector<int> ListView::selection(const bool sort) const +std::vector<int> ListView::selection(const bool sort) const { int index = -1; - vector<int> selectedIndexes; + std::vector<int> selectedIndexes; while((index = ListView_GetNextItem(handle(), index, LVNI_SELECTED)) != -1) selectedIndexes.push_back(translateBack(index)); @@ -479,14 +474,14 @@ bool ListView::onContextMenu(HWND dialog, int x, int y) // find the location of the current item or of the first item POINT itemPos{}; - ListView_GetItemPosition(handle(), translate(max(0, index)), &itemPos); + ListView_GetItemPosition(handle(), translate(std::max(0, index)), &itemPos); ClientToScreen(handle(), &itemPos); RECT controlRect; GetWindowRect(handle(), &controlRect); - x = max(controlRect.left, min(itemPos.x, controlRect.right)); - y = max(controlRect.top, min(itemPos.y, controlRect.bottom)); + x = std::max(controlRect.left, std::min(itemPos.x, controlRect.right)); + y = std::max(controlRect.top, std::min(itemPos.y, controlRect.bottom)); } #endif @@ -594,7 +589,7 @@ void ListView::headerMenu(const int x, const int y) void ListView::resetColumns() { - vector<int> order(columnCount()); + std::vector<int> order(columnCount()); for(int i = 0; i < columnCount(); i++) { order[i] = i; @@ -624,7 +619,7 @@ void ListView::restoreState(Serializer::Data &data) return; int col = -1; - vector<int> order(columnCount()); + std::vector<int> order(columnCount()); while(!data.empty()) { const auto &rec = data.front(); @@ -660,7 +655,7 @@ void ListView::restoreState(Serializer::Data &data) void ListView::saveState(Serializer::Data &data) const { const Sort &sort = m_sort.value_or(Sort{}); - vector<int> order(columnCount()); + std::vector<int> order(columnCount()); ListView_GetColumnOrderArray(handle(), columnCount(), &order[0]); data.push_back({sort.column, sort.order}); @@ -680,7 +675,7 @@ int ListView::Column::compare(const ListView::Cell &cl, const ListView::Cell &cr switch(dataType) { case UserType: { // arbitrary data or no data: sort by visible text - string l = cl.value, r = cr.value; + std::string l = cl.value, r = cr.value; boost::algorithm::to_lower(l); boost::algorithm::to_lower(r); @@ -704,7 +699,7 @@ ListView::Row::Row(void *data, ListView *list) { } -void ListView::Row::setCell(const int i, const string &val, void *data) +void ListView::Row::setCell(const int i, const std::string &val, void *data) { Cell &cell = m_cells[i]; cell.value = val; @@ -718,9 +713,9 @@ void ListView::Row::setChecked(bool checked) m_list->setRowIcon(userIndex, checked); } -vector<string> ListView::Row::filterValues() const +std::vector<std::string> ListView::Row::filterValues() const { - vector<string> values; + std::vector<std::string> values; for(int ci = 0; ci < m_list->columnCount(); ++ci) { if(m_list->column(ci).test(FilterFlag)) diff --git a/src/listview.hpp b/src/listview.hpp @@ -80,8 +80,6 @@ public: Cell *m_cells; }; - typedef std::shared_ptr<Row> RowPtr; - struct Column { std::string label; int width; @@ -109,8 +107,8 @@ public: ListView(HWND handle, const Columns & = {}); void reserveRows(size_t count) { m_rows.reserve(count); } - RowPtr createRow(void *data = nullptr); - const RowPtr &row(size_t index) const { return m_rows[index]; } + Row *createRow(void *data = nullptr); + Row *row(size_t index) const { return m_rows[index].get(); } void removeRow(int index); int rowCount() const { return (int)m_rows.size(); } int visibleRowCount() const; @@ -197,7 +195,7 @@ private: bool m_customizable; std::vector<Column> m_cols; - std::vector<RowPtr> m_rows; + std::vector<std::unique_ptr<Row>> m_rows; std::optional<Sort> m_sort; std::optional<Sort> m_defaultSort; }; diff --git a/src/manager.cpp b/src/manager.cpp @@ -36,8 +36,6 @@ static const Win32::char_type *ARCHIVE_FILTER = L("ReaPack Offline Archive (*.ReaPackArchive)\0*.ReaPackArchive\0"); static const Win32::char_type *ARCHIVE_EXT = L("ReaPackArchive"); -using namespace std; - enum { ACTION_UNINSTALL = 80, ACTION_ABOUT, ACTION_REFRESH, ACTION_COPYURL, ACTION_SELECT, ACTION_UNSELECT, ACTION_AUTOINSTALL_GLOBAL, @@ -72,11 +70,11 @@ void Manager::onInit() }); m_list->enableIcons(); - m_list->onSelect >> bind(&Dialog::startTimer, this, 100, TIMER_ABOUT, true); - m_list->onIconClick >> bind(&Manager::toggleEnabled, this); - m_list->onActivate >> bind(&Manager::aboutRepo, this, true); - m_list->onFillContextMenu >> bind(&Manager::fillContextMenu, this, - placeholders::_1, placeholders::_2); + m_list->onSelect >> std::bind(&Dialog::startTimer, this, 100, TIMER_ABOUT, true); + m_list->onIconClick >> std::bind(&Manager::toggleEnabled, this); + m_list->onActivate >> std::bind(&Manager::aboutRepo, this, true); + m_list->onFillContextMenu >> std::bind(&Manager::fillContextMenu, this, + std::placeholders::_1, std::placeholders::_2); setAnchor(m_list->handle(), AnchorRight | AnchorBottom); setAnchor(getControl(IDC_IMPORT), AnchorTop | AnchorBottom); @@ -292,8 +290,8 @@ void Manager::refresh() { ListView::BeginEdit edit(m_list); - const vector<int> selection = m_list->selection(); - vector<string> selected(selection.size()); + const std::vector<int> selection = m_list->selection(); + std::vector<std::string> selected(selection.size()); for(size_t i = 0; i < selection.size(); i++) selected[i] = m_list->row(selection[i])->cell(0).value; // TODO: use data ptr to Remote @@ -354,7 +352,7 @@ void Manager::toggleEnabled() const bool enable = !mods->enable.value_or(remote.isEnabled()); if(remote.isEnabled() == enable) - mods->enable = nullopt; + mods->enable = std::nullopt; else mods->enable = enable; @@ -377,7 +375,7 @@ void Manager::setRemoteAutoInstall(const tribool &enabled) setMods([=](const Remote &remote, int, RemoteMods *mods) { if(remote.autoInstall() == enabled || (indeterminate(remote.autoInstall()) && indeterminate(enabled))) - mods->autoInstall = nullopt; + mods->autoInstall = std::nullopt; else mods->autoInstall = enabled; }); @@ -398,8 +396,8 @@ void Manager::refreshIndex() if(!m_list->hasSelection()) return; - const vector<int> selection = m_list->selection(); - vector<Remote> remotes(selection.size()); + const std::vector<int> selection = m_list->selection(); + std::vector<Remote> remotes(selection.size()); for(size_t i = 0; i < selection.size(); i++) remotes[i] = getRemote(selection[i]); @@ -429,7 +427,7 @@ void Manager::uninstall() } } -void Manager::toggle(optional<bool> &setting, const bool current) +void Manager::toggle(std::optional<bool> &setting, const bool current) { setting = !setting.value_or(current); setChange(*setting == current ? -1 : 1); @@ -450,7 +448,7 @@ void Manager::setChange(const int increment) void Manager::copyUrl() { - vector<string> values; + std::vector<std::string> values; for(const int index : m_list->selection(false)) values.push_back(getRemote(index).url()); @@ -491,7 +489,7 @@ void Manager::importArchive() { const char *title = "Import offline archive"; - const string &path = FileDialog::getOpenFileName(handle(), instance(), + const std::string &path = FileDialog::getOpenFileName(handle(), instance(), title, Path::DATA.prependRoot(), ARCHIVE_FILTER, ARCHIVE_EXT); if(path.empty()) @@ -509,7 +507,7 @@ void Manager::importArchive() void Manager::exportArchive() { - const string &path = FileDialog::getSaveFileName(handle(), instance(), + const std::string &path = FileDialog::getSaveFileName(handle(), instance(), "Export offline archive", Path::DATA.prependRoot(), ARCHIVE_FILTER, ARCHIVE_EXT); if(!path.empty()) { @@ -592,7 +590,7 @@ bool Manager::apply() // syncList is the list of repos to synchronize for autoinstall // (global or local setting) - set<Remote> syncList; + std::set<Remote> syncList; if(m_autoInstall) { g_reapack->config()->install.autoInstall = *m_autoInstall; @@ -652,9 +650,9 @@ void Manager::reset() { m_mods.clear(); m_uninstall.clear(); - m_autoInstall = nullopt; - m_bleedingEdge = nullopt; - m_promptObsolete = nullopt; + m_autoInstall = std::nullopt; + m_bleedingEdge = std::nullopt; + m_promptObsolete = std::nullopt; m_changes = 0; disable(m_apply); @@ -665,7 +663,7 @@ Remote Manager::getRemote(const int index) const if(index < 0 || index > m_list->rowCount() - 1) return {}; - const string &remoteName = m_list->row(index)->cell(0).value; + const std::string &remoteName = m_list->row(index)->cell(0).value; return g_reapack->config()->remotes.get(remoteName); } diff --git a/src/obsquery.cpp b/src/obsquery.cpp @@ -24,11 +24,9 @@ #include <sstream> -using namespace std; - enum { ACTION_SELECT_ALL = 300, ACTION_UNSELECT_ALL }; -ObsoleteQuery::ObsoleteQuery(vector<Registry::Entry> *entries, bool *enable) +ObsoleteQuery::ObsoleteQuery(std::vector<Registry::Entry> *entries, bool *enable) : Dialog(IDD_OBSQUERY_DIALOG), m_entries(entries), m_enable(enable) { } @@ -54,7 +52,7 @@ void ObsoleteQuery::onInit() m_list->reserveRows(m_entries->size()); for(const Registry::Entry &entry : *m_entries) { - ostringstream stream; + std::ostringstream stream; stream << entry.remote << '/' << entry.category << '/' << Package::displayName(entry.package, entry.description); m_list->createRow()->setCell(0, stream.str()); @@ -89,7 +87,7 @@ void ObsoleteQuery::onCommand(const int id, int event) void ObsoleteQuery::prepare() { - vector<Registry::Entry> selected; + std::vector<Registry::Entry> selected; for(int index : m_list->selection()) selected.emplace_back(m_entries->at(index)); diff --git a/src/package.cpp b/src/package.cpp @@ -23,8 +23,6 @@ #include <algorithm> #include <boost/range/adaptor/reversed.hpp> -using namespace std; - Package::Type Package::getType(const char *type) { const std::pair<const char *, Type> map[]{ @@ -49,7 +47,7 @@ Package::Type Package::getType(const char *type) return UnknownType; } -string Package::displayType(const Type type) +const char *Package::displayType(const Type type) { switch(type) { case UnknownType: @@ -81,17 +79,17 @@ string Package::displayType(const Type type) return "Unknown"; } -const string &Package::displayName(const string &name, const string &desc) +const std::string &Package::displayName(const std::string &name, const std::string &desc) { return desc.empty() ? name : desc; } -Package::Package(const Type type, const string &name, const Category *cat) +Package::Package(const Type type, const std::string &name, const Category *cat) : m_category(cat), m_type(type), m_name(name) { if(m_name.empty()) throw reapack_error("empty package name"); - else if(m_name.find_first_of("/\\") != string::npos) { + else if(m_name.find_first_of("/\\") != std::string::npos) { throw reapack_error( String::format("invalid package name '%s'", m_name.c_str())); } @@ -103,7 +101,7 @@ Package::~Package() delete ver; } -string Package::fullName() const +std::string Package::fullName() const { return m_category ? m_category->fullName() + "/" + displayName() : displayName(); } diff --git a/src/package.hpp b/src/package.hpp @@ -41,7 +41,7 @@ public: }; static Type getType(const char *); - static std::string displayType(Type); + static const char *displayType(Type); static const std::string &displayName(const std::string &name, const std::string &desc); Package(const Type, const std::string &name, const Category *); diff --git a/src/path.cpp b/src/path.cpp @@ -33,8 +33,6 @@ static constexpr char NATIVE_SEPARATOR = '\\'; static constexpr const char *DOT = "."; static constexpr const char *DOTDOT = ".."; -using namespace std; - const Path Path::DATA("ReaPack"); const Path Path::CACHE = Path::DATA + "cache"; const Path Path::CONFIG("reapack.ini"); @@ -42,11 +40,11 @@ const Path Path::REGISTRY = Path::DATA + "registry.db"; Path Path::s_root; -static vector<string> Split(const string &input, bool *absolute) +static std::vector<std::string> Split(const std::string &input, bool *absolute) { - vector<string> list; + std::vector<std::string> list; - const auto append = [&list, absolute] (const string &part) { + const auto append = [&list, absolute] (const std::string &part) { if(part.empty() || part == DOT) return; @@ -65,7 +63,7 @@ static vector<string> Split(const string &input, bool *absolute) while(last < size) { const size_t pos = input.find_first_of("\\/", last); - if(pos == string::npos) { + if(pos == std::string::npos) { append(input.substr(last)); break; } @@ -85,12 +83,12 @@ static vector<string> Split(const string &input, bool *absolute) return list; } -Path::Path(const string &path) : m_absolute(false) +Path::Path(const std::string &path) : m_absolute(false) { append(path); } -void Path::append(const string &input, const bool traversal) +void Path::append(const std::string &input, const bool traversal) { if(input.empty()) return; @@ -101,7 +99,7 @@ void Path::append(const string &input, const bool traversal) if(m_parts.empty() && absolute) m_absolute = true; - for(const string &part : parts) { + for(const std::string &part : parts) { if(part == DOTDOT) { if(traversal) removeLast(); @@ -132,10 +130,10 @@ void Path::remove(const size_t pos, size_t count) count = size() - pos; auto begin = m_parts.begin(); - advance(begin, pos); + std::advance(begin, pos); auto end = begin; - advance(end, count); + std::advance(end, count); m_parts.erase(begin, end); @@ -149,7 +147,7 @@ void Path::removeLast() m_parts.pop_back(); } -string Path::front() const +std::string Path::front() const { if(empty()) return {}; @@ -157,7 +155,7 @@ string Path::front() const return m_parts.front(); } -string Path::basename() const +std::string Path::basename() const { if(empty()) return {}; @@ -175,7 +173,7 @@ Path Path::dirname() const return dir; } -string Path::join(const bool nativeSeparator) const +std::string Path::join(const bool nativeSeparator) const { const char sep = nativeSeparator ? NATIVE_SEPARATOR : UNIX_SEPARATOR; @@ -185,9 +183,9 @@ string Path::join(const bool nativeSeparator) const const bool absoluteSlash = m_absolute; #endif - string path; + std::string path; - for(const string &part : m_parts) { + for(const std::string &part : m_parts) { if(!path.empty() || absoluteSlash) path += sep; @@ -248,7 +246,7 @@ bool Path::operator<(const Path &o) const return m_parts < o.m_parts; } -Path Path::operator+(const string &part) const +Path Path::operator+(const std::string &part) const { Path path(*this); path.append(part); @@ -264,7 +262,7 @@ Path Path::operator+(const Path &o) const return path; } -const Path &Path::operator+=(const string &parts) +const Path &Path::operator+=(const std::string &parts) { append(parts); return *this; @@ -276,7 +274,7 @@ const Path &Path::operator+=(const Path &o) return *this; } -const string &Path::at(const size_t index) const +const std::string &Path::at(const size_t index) const { auto it = m_parts.begin(); advance(it, index); @@ -284,25 +282,25 @@ const string &Path::at(const size_t index) const return *it; } -string &Path::operator[](const size_t index) +std::string &Path::operator[](const size_t index) { - return const_cast<string &>(at(index)); + return const_cast<std::string &>(at(index)); } -const string &Path::operator[](const size_t index) const +const std::string &Path::operator[](const size_t index) const { return at(index); } UseRootPath::UseRootPath(const Path &path) - : m_backup(move(Path::s_root)) + : m_backup(std::move(Path::s_root)) { Path::s_root = path; } UseRootPath::~UseRootPath() { - Path::s_root = move(m_backup); + Path::s_root = std::move(m_backup); } TempPath::TempPath(const Path &target) diff --git a/src/progress.cpp b/src/progress.cpp @@ -23,14 +23,12 @@ #include <sstream> -using namespace std; - Progress::Progress(ThreadPool *pool) : Dialog(IDD_PROGRESS_DIALOG), m_pool(pool), m_label(nullptr), m_progress(nullptr), m_done(0), m_total(0) { - m_pool->onPush >> bind(&Progress::addTask, this, placeholders::_1); + m_pool->onPush >> std::bind(&Progress::addTask, this, std::placeholders::_1); } void Progress::onInit() @@ -90,12 +88,13 @@ void Progress::updateProgress() { Win32::setWindowText(m_label, String::format(m_current.c_str(), String::format("%s of %s", - String::number(min(m_done + 1, m_total)).c_str(), + String::number(std::min(m_done + 1, m_total)).c_str(), String::number(m_total).c_str() ).c_str() ).c_str()); - const double pos = static_cast<double>(min(m_done+1, m_total)) / max(2, m_total); + const double pos = static_cast<double>( + std::min(m_done + 1, m_total)) / std::max(2, m_total); const int percent = static_cast<int>(pos * 100); SendMessage(m_progress, PBM_SETPOS, percent, 0); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -36,8 +36,6 @@ #include <reaper_plugin_functions.h> -using namespace std; - const char *ReaPack::VERSION = "1.2.2"; const char *ReaPack::BUILDTIME = __DATE__ " " __TIME__; @@ -50,7 +48,7 @@ ReaPack *ReaPack::s_instance = nullptr; static void CleanupTempFiles() { const Path &path = (Path::DATA + "*.tmp").prependRoot(); - const wstring &pattern = Win32::widen(path.join()); + const std::wstring &pattern = Win32::widen(path.join()); WIN32_FIND_DATA fd = {}; HANDLE handle = FindFirstFile(pattern.c_str(), &fd); @@ -59,7 +57,7 @@ static void CleanupTempFiles() return; do { - wstring file = pattern; + std::wstring file = pattern; file.replace(file.size() - 5, 5, fd.cFileName); // 5 == strlen("*.tmp") DeleteFile(file.c_str()); } while(FindNextFile(handle, &fd)); @@ -147,7 +145,7 @@ void ReaPack::setupAPI() void ReaPack::synchronizeAll() { - const vector<Remote> &remotes = m_config.remotes.getEnabled(); + const std::vector<Remote> &remotes = m_config.remotes.getEnabled(); if(remotes.empty()) { ShowMessageBox("No repository enabled, nothing to do!", "ReaPack", MB_OK); @@ -220,7 +218,7 @@ void ReaPack::manageRemotes() m_manager->setCloseHandler([=](INT_PTR) { m_manager.reset(); }); } -Remote ReaPack::remote(const string &name) const +Remote ReaPack::remote(const std::string &name) const { return m_config.remotes.get(name); } @@ -231,13 +229,13 @@ void ReaPack::about(const Remote &repo, const bool focus) if(!tx) return; - const vector<Remote> repos = {repo}; + const std::vector<Remote> repos{repo}; tx->fetchIndexes(repos); tx->onFinish >> [=] { const auto &indexes = tx->getIndexes(repos); if(!indexes.empty()) - about()->setDelegate(make_shared<AboutIndexDelegate>(indexes.front()), focus); + about()->setDelegate(std::make_shared<AboutIndexDelegate>(indexes.front()), focus); }; tx->runTasks(); } @@ -306,7 +304,7 @@ Transaction *ReaPack::setupTransaction() } }; - m_tx->setObsoleteHandler([=] (vector<Registry::Entry> &entries) { + m_tx->setObsoleteHandler([=] (std::vector<Registry::Entry> &entries) { LockDialog aboutLock(m_about.get()); LockDialog browserLock(m_browser.get()); LockDialog managerLock(m_manager.get()); @@ -316,7 +314,7 @@ Transaction *ReaPack::setupTransaction() &entries, &config()->install.promptObsolete) == IDOK; }); - m_tx->setCleanupHandler(bind(&ReaPack::teardownTransaction, this)); + m_tx->setCleanupHandler(std::bind(&ReaPack::teardownTransaction, this)); return m_tx; } @@ -339,9 +337,9 @@ void ReaPack::commitConfig(bool refresh) if(m_tx) { if(refresh) { m_tx->receipt()->setIndexChanged(); // force browser refresh - m_tx->onFinish >> bind(&ReaPack::refreshManager, this); + m_tx->onFinish >> std::bind(&ReaPack::refreshManager, this); } - m_tx->onFinish >> bind(&Config::write, &m_config); + m_tx->onFinish >> std::bind(&Config::write, &m_config); m_tx->runTasks(); } else { diff --git a/src/receipt.cpp b/src/receipt.cpp @@ -23,8 +23,6 @@ #include <boost/range/adaptor/reversed.hpp> #include <sstream> -using namespace std; - Receipt::Receipt() : m_flags(NoFlag) { @@ -111,7 +109,7 @@ InstallTicket::Type InstallTicket::deduceType(const Registry::Entry &previous) c bool InstallTicket::operator<(const InstallTicket &o) const { - string l = m_version->package()->displayName(), + std::string l = m_version->package()->displayName(), r = o.m_version->package()->displayName(); boost::algorithm::to_lower(l); @@ -120,7 +118,7 @@ bool InstallTicket::operator<(const InstallTicket &o) const return l < r; } -ostream &operator<<(ostream &os, const InstallTicket &t) +std::ostream &operator<<(std::ostream &os, const InstallTicket &t) { if(os.tellp() > 0) os << "\r\n"; diff --git a/src/registry.cpp b/src/registry.cpp @@ -27,8 +27,6 @@ #include <sqlite3.h> -using namespace std; - Registry::Registry(const Path &path) : m_db(path.join()) { @@ -145,7 +143,7 @@ void Registry::migrate() } } -auto Registry::push(const Version *ver, vector<Path> *conflicts) -> Entry +auto Registry::push(const Version *ver, std::vector<Path> *conflicts) -> Entry { m_db.savepoint(); @@ -245,9 +243,9 @@ auto Registry::getEntry(const Package *pkg) const -> Entry return entry; } -auto Registry::getEntries(const string &remoteName) const -> vector<Entry> +auto Registry::getEntries(const std::string &remoteName) const -> std::vector<Entry> { - vector<Registry::Entry> list; + std::vector<Registry::Entry> list; m_allEntries->bind(1, remoteName); m_allEntries->exec([&] { @@ -261,12 +259,12 @@ auto Registry::getEntries(const string &remoteName) const -> vector<Entry> return list; } -auto Registry::getFiles(const Entry &entry) const -> vector<File> +auto Registry::getFiles(const Entry &entry) const -> std::vector<File> { if(!entry) // skip processing for new packages return {}; - vector<File> files; + std::vector<File> files; m_getFiles->bind(1, entry.id); m_getFiles->exec([&] { @@ -288,16 +286,16 @@ auto Registry::getFiles(const Entry &entry) const -> vector<File> return files; } -auto Registry::getMainFiles(const Entry &entry) const -> vector<File> +auto Registry::getMainFiles(const Entry &entry) const -> std::vector<File> { if(!entry) return {}; - const vector<File> &allFiles = getFiles(entry); + const std::vector<File> &allFiles = getFiles(entry); - vector<File> mainFiles; - copy_if(allFiles.begin(), allFiles.end(), - back_inserter(mainFiles), [&](const File &f) { return f.sections; }); + std::vector<File> mainFiles; + std::copy_if(allFiles.begin(), allFiles.end(), + std::back_inserter(mainFiles), [&](const File &f) { return f.sections; }); return mainFiles; } @@ -332,7 +330,7 @@ void Registry::convertImplicitSections() Statement entries("SELECT id, category FROM entries", &m_db); entries.exec([&] { const auto id = entries.intColumn(0); - const string &category = entries.stringColumn(1); + const std::string &category = entries.stringColumn(1); const auto section = Source::detectSection(category); Statement update("UPDATE files SET main = ? WHERE entry = ? AND main != 0", &m_db); diff --git a/src/remote.cpp b/src/remote.cpp @@ -24,53 +24,51 @@ #include <regex> #include <sstream> -using namespace std; - static char DATA_DELIMITER = '|'; -static bool validateName(const string &name) +static bool validateName(const std::string &name) { using namespace std::regex_constants; // see https://en.wikipedia.org/wiki/Filename#Reserved%5Fcharacters%5Fand%5Fwords - static const regex validPattern("[^*\\\\:<>?/|\"[:cntrl:]]+"); - static const regex invalidPattern( + static const std::regex validPattern("[^*\\\\:<>?/|\"[:cntrl:]]+"); + static const std::regex invalidPattern( "[\\.\x20].*|.+[\\.\x20]|CLOCK\\$|COM\\d|LPT\\d", icase); - smatch valid, invalid; - regex_match(name, valid, validPattern); - regex_match(name, invalid, invalidPattern); + std::smatch valid, invalid; + std::regex_match(name, valid, validPattern); + std::regex_match(name, invalid, invalidPattern); return !valid.empty() && invalid.empty(); } -static bool validateUrl(const string &url) +static bool validateUrl(const std::string &url) { // see http://tools.ietf.org/html/rfc3986#section-2 - static const regex pattern( + static const std::regex pattern( "(?:[a-zA-Z0-9._~:/?#[\\]@!$&'()*+,;=-]|%[a-f0-9]{2})+"); - smatch match; - regex_match(url, match, pattern); + std::smatch match; + std::regex_match(url, match, pattern); return !match.empty(); } -Remote Remote::fromString(const string &data) +Remote Remote::fromString(const std::string &data) { - istringstream stream(data); + std::istringstream stream(data); - string name; - getline(stream, name, DATA_DELIMITER); + std::string name; + std::getline(stream, name, DATA_DELIMITER); - string url; - getline(stream, url, DATA_DELIMITER); + std::string url; + std::getline(stream, url, DATA_DELIMITER); - string enabled; - getline(stream, enabled, DATA_DELIMITER); + std::string enabled; + std::getline(stream, enabled, DATA_DELIMITER); - string autoInstall; - getline(stream, autoInstall, DATA_DELIMITER); + std::string autoInstall; + std::getline(stream, autoInstall, DATA_DELIMITER); if(!validateName(name) || !validateUrl(url)) return {}; @@ -95,14 +93,15 @@ Remote::Remote() { } -Remote::Remote(const string &name, const string &url, const bool enabled, const tribool &autoInstall) +Remote::Remote(const std::string &name, const std::string &url, + const bool enabled, const tribool &autoInstall) : m_enabled(enabled), m_protected(false), m_autoInstall(autoInstall) { setName(name); setUrl(url); } -void Remote::setName(const string &name) +void Remote::setName(const std::string &name) { if(!validateName(name)) throw reapack_error("invalid name"); @@ -110,7 +109,7 @@ void Remote::setName(const string &name) m_name = name; } -void Remote::setUrl(const string &url) +void Remote::setUrl(const std::string &url) { if(!validateUrl(url)) throw reapack_error("invalid url"); @@ -128,9 +127,9 @@ bool Remote::autoInstall(bool fallback) const return bool{m_autoInstall}; } -string Remote::toString() const +std::string Remote::toString() const { - ostringstream out; + std::ostringstream out; out << m_name << DATA_DELIMITER; out << m_url << DATA_DELIMITER; out << m_enabled << DATA_DELIMITER; @@ -161,7 +160,7 @@ void RemoteList::add(const Remote &remote) m_map[remote.name()] = index; } -void RemoteList::remove(const string &name) +void RemoteList::remove(const std::string &name) { const auto &it = m_map.find(name); @@ -178,7 +177,7 @@ void RemoteList::remove(const string &name) m_map.erase(it); } -Remote RemoteList::get(const string &name) const +Remote RemoteList::get(const std::string &name) const { const auto &it = m_map.find(name); @@ -188,9 +187,9 @@ Remote RemoteList::get(const string &name) const return m_remotes[it->second]; } -vector<Remote> RemoteList::getEnabled() const +std::vector<Remote> RemoteList::getEnabled() const { - vector<Remote> list; + std::vector<Remote> list; for(const Remote &remote : m_remotes) { if(remote.isEnabled()) diff --git a/src/report.cpp b/src/report.cpp @@ -22,8 +22,6 @@ #include "tabbar.hpp" #include "win32.hpp" -using namespace std; - Report::Report(const Receipt *receipt) : Dialog(IDD_REPORT_DIALOG), m_receipt(receipt), m_empty(true) { diff --git a/src/richedit-gtk.cpp b/src/richedit-gtk.cpp @@ -22,8 +22,6 @@ // Starting here and onward is the Linux implementation of RichEdit // See also richedit.mm and richedit-win32.cpp -using namespace std; - void RichEdit::Init() { } @@ -41,12 +39,12 @@ void RichEdit::onNotify(LPNMHDR, LPARAM) { } -void RichEdit::setPlainText(const string &text) +void RichEdit::setPlainText(const std::string &text) { SetWindowText(handle(), text.c_str()); } -bool RichEdit::setRichText(const string &) +bool RichEdit::setRichText(const std::string &) { return false; } diff --git a/src/richedit-win32.cpp b/src/richedit-win32.cpp @@ -28,20 +28,17 @@ #include <richedit.h> #include <sstream> -using namespace std; - static void HandleLink(ENLINK *info, HWND handle) { const CHARRANGE &range = info->chrg; - wchar_t *url = new wchar_t[(range.cpMax - range.cpMin) + 1](); - unique_ptr<wchar_t[]> ptr(url); + std::wstring url(range.cpMax - range.cpMin, 0); - TEXTRANGE tr{range, url}; + TEXTRANGE tr{range, url.data()}; SendMessage(handle, EM_GETTEXTRANGE, 0, (LPARAM)&tr); if(info->msg == WM_LBUTTONUP) - ShellExecute(nullptr, L"open", url, nullptr, nullptr, SW_SHOW); + ShellExecute(nullptr, L"open", url.c_str(), nullptr, nullptr, SW_SHOW); } void RichEdit::Init() @@ -71,19 +68,19 @@ void RichEdit::onNotify(LPNMHDR info, LPARAM lParam) }; } -void RichEdit::setPlainText(const string &text) +void RichEdit::setPlainText(const std::string &text) { Win32::setWindowText(handle(), text.c_str()); } -bool RichEdit::setRichText(const string &rtf) +bool RichEdit::setRichText(const std::string &rtf) { - stringstream stream(rtf); + std::stringstream stream(rtf); EDITSTREAM es{}; es.dwCookie = (DWORD_PTR)&stream; es.pfnCallback = [](DWORD_PTR cookie, LPBYTE buf, LONG size, LONG *pcb) -> DWORD { - stringstream *stream = reinterpret_cast<stringstream *>(cookie); + std::stringstream *stream = reinterpret_cast<std::stringstream *>(cookie); *pcb = (LONG)stream->readsome((char *)buf, size); return 0; }; diff --git a/src/richedit.mm b/src/richedit.mm @@ -19,8 +19,6 @@ #include <Cocoa/Cocoa.h> -using namespace std; - void RichEdit::Init() { } @@ -43,7 +41,7 @@ void RichEdit::onNotify(LPNMHDR, LPARAM) { } -void RichEdit::setPlainText(const string &text) +void RichEdit::setPlainText(const std::string &text) { NSString *str = [NSString stringWithCString: text.c_str() @@ -57,7 +55,7 @@ void RichEdit::setPlainText(const string &text) [attrStr release]; } -bool RichEdit::setRichText(const string &rtf) +bool RichEdit::setRichText(const std::string &rtf) { NSString *str = [NSString stringWithCString: rtf.c_str() diff --git a/src/serializer.cpp b/src/serializer.cpp @@ -24,30 +24,28 @@ static const unsigned short VERSION = 1; static const char FIELD_END = '\x20'; static const char RECORD_END = ','; -using namespace std; - -auto Serializer::read(const string &input, const int userVersion) -> Data +auto Serializer::read(const std::string &input, const int userVersion) -> Data { m_userVersion = userVersion; bool first = true; - istringstream stream(input); + std::istringstream stream(input); Data out; while(!stream.eof()) { - string line; - getline(stream, line, RECORD_END); + std::string line; + std::getline(stream, line, RECORD_END); - istringstream lineStream(line); + std::istringstream lineStream(line); Record rec; for(size_t i = 0; i < rec.size(); i++) { if(lineStream.eof()) return out; - string field; - getline(lineStream, field, FIELD_END); + std::string field; + std::getline(lineStream, field, FIELD_END); int value; @@ -74,12 +72,12 @@ auto Serializer::read(const string &input, const int userVersion) -> Data return out; } -string Serializer::write(const Data &data) const +std::string Serializer::write(const Data &data) const { if(!m_userVersion) return {}; - ostringstream stream; + std::ostringstream stream; stream << m_userVersion << FIELD_END diff --git a/src/source.cpp b/src/source.cpp @@ -22,8 +22,6 @@ #include <boost/algorithm/string/case_conv.hpp> -using namespace std; - auto Source::getSection(const char *name) -> Section { const std::pair<const char *, Section> map[]{ @@ -47,7 +45,7 @@ auto Source::detectSection(const Path &category) -> Section { // this is for compatibility with indexes made for v1.0 - string topcategory = category.front(); + std::string topcategory = category.front(); boost::algorithm::to_lower(topcategory); if(topcategory == "midi editor") @@ -56,7 +54,7 @@ auto Source::detectSection(const Path &category) -> Section return MainSection; } -Source::Source(const string &file, const string &url, const Version *ver) +Source::Source(const std::string &file, const std::string &url, const Version *ver) : m_type(Package::UnknownType), m_file(file), m_url(url), m_sections(0), m_version(ver) { @@ -72,7 +70,7 @@ Package::Type Source::type() const return m_version->package()->type(); } -const string &Source::file() const +const std::string &Source::file() const { if(!m_file.empty()) return m_file; diff --git a/src/string.cpp b/src/string.cpp @@ -21,9 +21,7 @@ #include <cstdarg> #include <sstream> -using namespace std; - -string String::format(const char *fmt, ...) +std::string String::format(const char *fmt, ...) { va_list args; @@ -31,7 +29,7 @@ string String::format(const char *fmt, ...) const int size = vsnprintf(nullptr, 0, fmt, args); va_end(args); - string buf(size, 0); + std::string buf(size, 0); va_start(args, fmt); vsnprintf(&buf[0], size + 1, fmt, args); @@ -40,11 +38,11 @@ string String::format(const char *fmt, ...) return buf; } -string String::indent(const string &text) +std::string String::indent(const std::string &text) { - string output; - istringstream input(text); - string line; + std::string output; + std::istringstream input(text); + std::string line; bool first = true; while(getline(input, line, '\n')) { @@ -65,7 +63,7 @@ string String::indent(const string &text) return output; } -void String::ImplDetail::imbueStream(ostream &stream) +void String::ImplDetail::imbueStream(std::ostream &stream) { class NumPunct : public std::numpunct<char> { @@ -74,5 +72,5 @@ void String::ImplDetail::imbueStream(ostream &stream) std::string do_grouping() const override { return "\3"; } }; - stream.imbue(locale(locale::classic(), new NumPunct)); + stream.imbue(std::locale(std::locale::classic(), new NumPunct)); } diff --git a/src/task.cpp b/src/task.cpp @@ -26,10 +26,8 @@ #include "reapack.hpp" #include "transaction.hpp" -using namespace std; - UninstallTask::UninstallTask(const Registry::Entry &re, Transaction *tx) - : Task(tx), m_entry(move(re)) + : Task(tx), m_entry(std::move(re)) { } @@ -58,7 +56,7 @@ void UninstallTask::commit() } PinTask::PinTask(const Registry::Entry &re, const bool pin, Transaction *tx) - : Task(tx), m_entry(move(re)), m_pin(pin) + : Task(tx), m_entry(std::move(re)), m_pin(pin) { } diff --git a/src/thread.cpp b/src/thread.cpp @@ -24,8 +24,6 @@ extern "C" extern const _tls_callback_type __dyn_tls_dtor_callback; #endif -using namespace std; - ThreadTask::ThreadTask() : m_state(Idle), m_abort(false) { } @@ -67,7 +65,7 @@ WorkerThread::~WorkerThread() void WorkerThread::run() { - unique_lock<mutex> lock(m_mutex); + std::unique_lock<std::mutex> lock(m_mutex); while(true) { m_wake.wait(lock, [=] { return !m_queue.empty() || m_stop; }); @@ -97,7 +95,7 @@ void WorkerThread::run() ThreadTask *WorkerThread::nextTask() { - lock_guard<mutex> guard(m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if(m_queue.empty()) return nullptr; @@ -109,7 +107,7 @@ ThreadTask *WorkerThread::nextTask() void WorkerThread::push(ThreadTask *task) { - lock_guard<mutex> guard(m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_queue.push(task); m_wake.notify_one(); @@ -144,7 +142,7 @@ void ThreadPool::push(ThreadTask *task) const size_t nextThread = m_running.size() % m_pool.size(); auto &thread = task->concurrent() ? m_pool[nextThread] : m_pool.front(); if(!thread) - thread = make_unique<WorkerThread>(); + thread = std::make_unique<WorkerThread>(); thread->push(task); } diff --git a/src/time.cpp b/src/time.cpp @@ -21,17 +21,15 @@ #include <iomanip> #include <sstream> -using namespace std; - Time::Time(const char *iso8601) : m_tm() { tm time = {}; - istringstream stream(iso8601); + std::istringstream stream(iso8601); stream >> std::get_time(&time, "%Y-%m-%dT%H:%M:%S"); if(stream.good()) - swap(m_tm, time); + std::swap(m_tm, time); } Time::Time(int year, int month, int day, int hour, int minute, int second) @@ -46,7 +44,7 @@ Time::Time(int year, int month, int day, int hour, int minute, int second) m_tm.tm_sec = second; } -string Time::toString() const +std::string Time::toString() const { if(!isValid()) return {}; @@ -58,8 +56,8 @@ string Time::toString() const int Time::compare(const Time &o) const { - const array<int, 6> l{year(), month(), day(), hour(), minute(), second()}; - const array<int, 6> r{o.year(), o.month(), o.day(), o.hour(), o.minute(), o.second()}; + const std::array<int, 6> l{year(), month(), day(), hour(), minute(), second()}; + const std::array<int, 6> r{o.year(), o.month(), o.day(), o.hour(), o.minute(), o.second()}; if(l < r) return -1; @@ -69,7 +67,7 @@ int Time::compare(const Time &o) const return 0; } -ostream &operator<<(ostream &os, const Time &time) +std::ostream &operator<<(std::ostream &os, const Time &time) { os << time.toString(); return os; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -30,8 +30,6 @@ #include <reaper_plugin_functions.h> -using namespace std; - Transaction::Transaction() : m_isCancelled(false), m_registry(Path::REGISTRY.prependRoot()) { @@ -44,11 +42,11 @@ Transaction::Transaction() m_threadPool.onAbort >> [this] { m_isCancelled = true; - queue<HostTicket>().swap(m_regQueue); + std::queue<HostTicket>().swap(m_regQueue); }; // run the next task queue when the current one is done - m_threadPool.onDone >> bind(&Transaction::runTasks, this); + m_threadPool.onDone >> std::bind(&Transaction::runTasks, this); } void Transaction::synchronize(const Remote &remote, @@ -62,18 +60,18 @@ void Transaction::synchronize(const Remote &remote, InstallOpts opts = g_reapack->config()->install; opts.autoInstall = remote.autoInstall(forceAutoInstall.value_or(opts.autoInstall)); - m_nextQueue.push(make_shared<SynchronizeTask>(remote, true, true, opts, this)); + m_nextQueue.push(std::make_shared<SynchronizeTask>(remote, true, true, opts, this)); } -void Transaction::fetchIndexes(const vector<Remote> &remotes, const bool stale) +void Transaction::fetchIndexes(const std::vector<Remote> &remotes, const bool stale) { for(const Remote &remote : remotes) - m_nextQueue.push(make_shared<SynchronizeTask>(remote, stale, false, InstallOpts{}, this)); + m_nextQueue.push(std::make_shared<SynchronizeTask>(remote, stale, false, InstallOpts{}, this)); } -vector<IndexPtr> Transaction::getIndexes(const vector<Remote> &remotes) const +std::vector<IndexPtr> Transaction::getIndexes(const std::vector<Remote> &remotes) const { - vector<IndexPtr> indexes; + std::vector<IndexPtr> indexes; for(const Remote &remote : remotes) { const auto &it = m_indexes.find(remote.name()); @@ -111,12 +109,12 @@ void Transaction::install(const Version *ver, const bool pin, void Transaction::install(const Version *ver, const Registry::Entry &oldEntry, const bool pin, const ArchiveReaderPtr &reader) { - m_nextQueue.push(make_shared<InstallTask>(ver, pin, oldEntry, reader, this)); + m_nextQueue.push(std::make_shared<InstallTask>(ver, pin, oldEntry, reader, this)); } void Transaction::setPinned(const Registry::Entry &entry, const bool pinned) { - m_nextQueue.push(make_shared<PinTask>(entry, pinned, this)); + m_nextQueue.push(std::make_shared<PinTask>(entry, pinned, this)); } void Transaction::uninstall(const Remote &remote) @@ -136,12 +134,12 @@ void Transaction::uninstall(const Remote &remote) void Transaction::uninstall(const Registry::Entry &entry) { - m_nextQueue.push(make_shared<UninstallTask>(entry, this)); + m_nextQueue.push(std::make_shared<UninstallTask>(entry, this)); } -void Transaction::exportArchive(const string &path) +void Transaction::exportArchive(const std::string &path) { - m_nextQueue.push(make_shared<ExportTask>(path, this)); + m_nextQueue.push(std::make_shared<ExportTask>(path, this)); } bool Transaction::runTasks() @@ -251,7 +249,7 @@ void Transaction::registerQueued() void Transaction::registerScript(const HostTicket &reg, const bool isLastCall) { - const pair<Source::Section, int> sectionMap[] = { + const std::pair<Source::Section, int> sectionMap[] = { {Source::MainSection, 0}, {Source::MIDIEditorSection, 32060}, {Source::MIDIEventListEditorSection, 32061}, @@ -262,9 +260,9 @@ void Transaction::registerScript(const HostTicket &reg, const bool isLastCall) if(!AddRemoveReaScript || !reg.file.sections) return; // do nothing if REAPER < v5.12 and skip non-main files - const string &fullPath = reg.file.path.prependRoot().join(); + const std::string &fullPath = reg.file.path.prependRoot().join(); - vector<int> sections; + std::vector<int> sections; for(auto &[flag, id] : sectionMap) { if(reg.file.sections & flag) @@ -312,7 +310,7 @@ void Transaction::promptObsolete() if(!g_reapack->config()->install.promptObsolete || m_obsolete.empty()) return; - vector<Registry::Entry> selected; + std::vector<Registry::Entry> selected; selected.insert(selected.end(), m_obsolete.begin(), m_obsolete.end()); m_obsolete.clear(); @@ -323,5 +321,5 @@ void Transaction::promptObsolete() m_taskQueues.push(TaskQueue()); for(const auto &entry : selected) - m_taskQueues.back().push(make_shared<UninstallTask>(entry, this)); + m_taskQueues.back().push(std::make_shared<UninstallTask>(entry, this)); } diff --git a/src/version.cpp b/src/version.cpp @@ -25,9 +25,7 @@ #include <cctype> #include <regex> -using namespace std; - -string Version::displayAuthor(const string &author) +std::string Version::displayAuthor(const std::string &author) { if(author.empty()) return "Unknown"; @@ -35,7 +33,7 @@ string Version::displayAuthor(const string &author) return author; } -Version::Version(const string &str, const Package *pkg) +Version::Version(const std::string &str, const Package *pkg) : m_name(str), m_time(), m_package(pkg) { } @@ -46,9 +44,9 @@ Version::~Version() delete source; } -string Version::fullName() const +std::string Version::fullName() const { - string name = m_package->fullName(); + std::string name = m_package->fullName(); name += " v"; name += m_name.toString(); @@ -73,7 +71,7 @@ bool Version::addSource(const Source *source) return true; } -ostream &operator<<(ostream &os, const Version &ver) +std::ostream &operator<<(std::ostream &os, const Version &ver) { os << 'v' << ver.name().toString(); @@ -85,7 +83,7 @@ ostream &operator<<(ostream &os, const Version &ver) os << "\r\n"; - const string &changelog = ver.changelog(); + const std::string &changelog = ver.changelog(); os << String::indent(changelog.empty() ? "No changelog" : changelog); return os; @@ -94,7 +92,7 @@ ostream &operator<<(ostream &os, const Version &ver) VersionName::VersionName() : m_stable(true) {} -VersionName::VersionName(const string &str) +VersionName::VersionName(const std::string &str) { parse(str); } @@ -104,18 +102,18 @@ VersionName::VersionName(const VersionName &o) { } -void VersionName::parse(const string &str) +void VersionName::parse(const std::string &str) { - static const regex pattern("\\d+|[a-zA-Z]+"); + static const std::regex pattern("\\d+|[a-zA-Z]+"); - const auto &begin = sregex_iterator(str.begin(), str.end(), pattern); - const sregex_iterator end; + const auto &begin = std::sregex_iterator(str.begin(), str.end(), pattern); + const std::sregex_iterator end; size_t letters = 0; - vector<Segment> segments; + std::vector<Segment> segments; - for(sregex_iterator it = begin; it != end; it++) { - const string &match = it->str(0); + for(std::sregex_iterator it = begin; it != end; it++) { + const std::string &match = it->str(0); if(isalpha(match[0])) { if(segments.empty()) // got leading letters @@ -142,7 +140,7 @@ void VersionName::parse(const string &str) m_stable = letters < 1; } -bool VersionName::tryParse(const string &str, string *errorOut) +bool VersionName::tryParse(const std::string &str, std::string *errorOut) { try { parse(str); @@ -166,7 +164,7 @@ auto VersionName::segment(const size_t index) const -> Segment int VersionName::compare(const VersionName &o) const { - const size_t biggest = max(size(), o.size()); + const size_t biggest = std::max(size(), o.size()); switch(m_segments.empty() + o.m_segments.empty()) { case 1: @@ -177,12 +175,12 @@ int VersionName::compare(const VersionName &o) const for(size_t i = 0; i < biggest; i++) { const Segment &lseg = segment(i); - const Numeric *lnum = get_if<Numeric>(&lseg); - const string *lstr = get_if<string>(&lseg); + const Numeric *lnum = std::get_if<Numeric>(&lseg); + const std::string *lstr = std::get_if<std::string>(&lseg); const Segment &rseg = o.segment(i); - const Numeric *rnum = get_if<Numeric>(&rseg); - const string *rstr = get_if<string>(&rseg); + const Numeric *rnum = std::get_if<Numeric>(&rseg); + const std::string *rstr = std::get_if<std::string>(&rseg); if(lnum && rnum) { if(*lnum < *rnum) diff --git a/src/win32.cpp b/src/win32.cpp @@ -24,25 +24,23 @@ # define widen_cstr(cstr) cstr #endif -using namespace std; - #ifdef _WIN32 -wstring Win32::widen(const char *input, const UINT codepage) +std::wstring Win32::widen(const char *input, const UINT codepage) { const int size = MultiByteToWideChar(codepage, 0, input, -1, nullptr, 0) - 1; - wstring output(size, 0); + std::wstring output(size, 0); MultiByteToWideChar(codepage, 0, input, -1, &output[0], size); return output; } -string Win32::narrow(const wchar_t *input) +std::string Win32::narrow(const wchar_t *input) { const int size = WideCharToMultiByte(CP_UTF8, 0, input, -1, nullptr, 0, nullptr, nullptr) - 1; - string output(size, 0); + std::string output(size, 0); WideCharToMultiByte(CP_UTF8, 0, input, -1, &output[0], size, nullptr, nullptr); return output; @@ -55,10 +53,10 @@ int Win32::messageBox(const HWND handle, const char *text, return MessageBox(handle, widen_cstr(text), widen_cstr(title), buttons); } -string Win32::getWindowText(const HWND handle) +std::string Win32::getWindowText(const HWND handle) { char_type buffer[4096]; - GetWindowText(handle, buffer, static_cast<int>(size(buffer))); + GetWindowText(handle, buffer, static_cast<int>(std::size(buffer))); return narrow(buffer); } @@ -74,7 +72,7 @@ void Win32::shellExecute(const char *what, const char *arg) arg ? widen_cstr(arg) : nullptr, nullptr, SW_SHOW); } -HANDLE Win32::globalCopy(const string &text) +HANDLE Win32::globalCopy(const std::string &text) { // calculate the size in bytes including the null terminator const size_t size = (text.size() + 1) * sizeof(char_type); @@ -94,12 +92,12 @@ bool Win32::writePrivateProfileString(const char *group, const char *key, value ? widen_cstr(value) : nullptr, widen_cstr(path)); } -string Win32::getPrivateProfileString(const char *group, const char *key, +std::string Win32::getPrivateProfileString(const char *group, const char *key, const char *fallback, const char *path) { char_type buffer[4096]; GetPrivateProfileString(widen_cstr(group), widen_cstr(key), widen_cstr(fallback), - buffer, static_cast<DWORD>(size(buffer)), widen_cstr(path)); + buffer, static_cast<DWORD>(std::size(buffer)), widen_cstr(path)); return narrow(buffer); } diff --git a/test/api.cpp b/test/api.cpp @@ -4,8 +4,6 @@ #include <api.hpp> -using namespace std; - static const char *M = "[api]"; TEST_CASE("CompareVersions", M) { diff --git a/test/database.cpp b/test/database.cpp @@ -6,8 +6,6 @@ #include <sqlite3.h> -using namespace std; - static const char *M = "[database]"; TEST_CASE("open bad sqlite file path", M) { @@ -16,7 +14,7 @@ TEST_CASE("open bad sqlite file path", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "unable to open database file"); + REQUIRE(std::string{e.what()} == "unable to open database file"); } } @@ -28,7 +26,7 @@ TEST_CASE("execute invalid sql", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "near \"WHERE\": syntax error"); + REQUIRE(std::string{e.what()} == "near \"WHERE\": syntax error"); } } @@ -40,7 +38,7 @@ TEST_CASE("prepare invalid sql", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "near \"WHERE\": syntax error"); + REQUIRE(std::string{e.what()} == "near \"WHERE\": syntax error"); } } @@ -52,7 +50,7 @@ TEST_CASE("get rows from prepared statement", M) { "INSERT INTO test VALUES (\"世界\");" ); - vector<string> values; + std::vector<std::string> values; Statement *stmt = db.prepare("SELECT value FROM test"); @@ -91,7 +89,7 @@ TEST_CASE("bind values and clear", M) { FAIL("bindings not cleared"); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "NOT NULL constraint failed: test.value"); + REQUIRE(std::string{e.what()} == "NOT NULL constraint failed: test.value"); } } @@ -161,13 +159,13 @@ TEST_CASE("bind temporary strings", M) { Statement *insert = db.prepare("INSERT INTO a VALUES(?)"); - string str("hello"); + std::string str("hello"); insert->bind(1, str); str = "world"; insert->exec(); - string got; + std::string got; Statement *select = db.prepare("SELECT text FROM a LIMIT 1"); select->exec([&] { got = select->stringColumn(0); @@ -188,7 +186,7 @@ TEST_CASE("get integers from sqlite", M) { insert->bind(1, 4294967295); insert->exec(); - vector<sqlite3_int64> signedVals; + std::vector<sqlite3_int64> signedVals; Statement *select = db.prepare("SELECT test FROM a"); select->exec([&] { signedVals.push_back(select->intColumn(0)); diff --git a/test/event.cpp b/test/event.cpp @@ -4,7 +4,7 @@ #include <reaper_plugin_functions.h> -constexpr const char *M = "[event]"; +static const char *M = "[event]"; TEST_CASE("check whether an event has handlers subscribed to it", M) { Event<void()> e; diff --git a/test/filter.cpp b/test/filter.cpp @@ -2,8 +2,6 @@ #include <filter.hpp> -using namespace std; - static const char *M = "[filter]"; TEST_CASE("basic matching", M) { diff --git a/test/helper.cpp b/test/helper.cpp @@ -4,9 +4,7 @@ #include <path.hpp> #include <version.hpp> -using namespace std; - -ostream &operator<<(ostream &os, const set<Path> &list) +std::ostream &operator<<(std::ostream &os, const std::set<Path> &list) { os << '{'; diff --git a/test/index.cpp b/test/index.cpp @@ -3,8 +3,6 @@ #include <errors.hpp> #include <index.hpp> -using namespace std; - static const char *M = "[index]"; static const Path RIPATH("test/indexes"); @@ -16,7 +14,7 @@ TEST_CASE("index file not found", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "No such file or directory"); + REQUIRE(std::string{e.what()} == "No such file or directory"); } } @@ -31,7 +29,7 @@ TEST_CASE("load index from raw data", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "Error reading end tag."); + REQUIRE(std::string{e.what()} == "Error reading end tag."); } } } @@ -44,7 +42,7 @@ TEST_CASE("broken index", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "Error reading end tag."); + REQUIRE(std::string{e.what()} == "Error reading end tag."); } } @@ -56,7 +54,7 @@ TEST_CASE("wrong root tag name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid index"); + REQUIRE(std::string{e.what()} == "invalid index"); } } @@ -68,7 +66,7 @@ TEST_CASE("invalid version", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "index version not found"); + REQUIRE(std::string{e.what()} == "index version not found"); } } @@ -80,7 +78,7 @@ TEST_CASE("future version", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "index version is unsupported"); + REQUIRE(std::string{e.what()} == "index version is unsupported"); } } @@ -117,7 +115,7 @@ TEST_CASE("add owned category", M) { } catch(const reapack_error &e) { delete cat; - REQUIRE(string(e.what()) == "category belongs to another index"); + REQUIRE(std::string{e.what()} == "category belongs to another index"); } } @@ -158,7 +156,7 @@ TEST_CASE("add owned package", M) { } catch(const reapack_error &e) { delete pack; - REQUIRE(string(e.what()) == "package belongs to another category"); + REQUIRE(std::string{e.what()} == "package belongs to another category"); } } @@ -182,7 +180,7 @@ TEST_CASE("empty category name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty category name"); + REQUIRE(std::string{e.what()} == "empty category name"); } } @@ -206,7 +204,7 @@ TEST_CASE("set index name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "index name is already set"); + REQUIRE(std::string{e.what()} == "index name is already set"); } REQUIRE(ri.name() == "hello"); } diff --git a/test/index_v1.cpp b/test/index_v1.cpp @@ -3,8 +3,6 @@ #include <index.hpp> #include <errors.hpp> -using namespace std; - static const char *M = "[reapack_v1]"; static const Path RIPATH("test/indexes/v1"); @@ -16,7 +14,7 @@ TEST_CASE("unnamed category", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty category name"); + REQUIRE(std::string{e.what()} == "empty category name"); } } @@ -44,7 +42,7 @@ TEST_CASE("null package name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty package name"); + REQUIRE(std::string{e.what()} == "empty package name"); } } @@ -102,7 +100,7 @@ TEST_CASE("null package version", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid version name ''"); + REQUIRE(std::string{e.what()} == "invalid version name ''"); } } @@ -114,7 +112,7 @@ TEST_CASE("null source url", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty source url"); + REQUIRE(std::string{e.what()} == "empty source url"); } } diff --git a/test/metadata.cpp b/test/metadata.cpp @@ -2,8 +2,6 @@ #include <metadata.hpp> -using namespace std; - static const char *M = "[metadata]"; TEST_CASE("repository links", M) { diff --git a/test/package.cpp b/test/package.cpp @@ -4,12 +4,10 @@ #include <index.hpp> #include <package.hpp> -using namespace std; - static const char *M = "[package]"; TEST_CASE("package type from string", M) { - const pair<const char *, Package::Type> tests[] = { + const std::pair<const char *, Package::Type> tests[] = { {"yoyo", Package::UnknownType}, {"script", Package::ScriptType}, {"extension", Package::ExtensionType}, @@ -29,7 +27,7 @@ TEST_CASE("package type from string", M) { } TEST_CASE("package type to string", M) { - const pair<Package::Type, string> tests[] = { + const std::pair<Package::Type, std::string> tests[] = { {Package::UnknownType, "Unknown"}, {Package::ScriptType, "Script"}, {Package::ExtensionType, "Extension"}, @@ -56,7 +54,7 @@ TEST_CASE("invalid package name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty package name"); + REQUIRE(std::string{e.what()} == "empty package name"); } } @@ -66,7 +64,7 @@ TEST_CASE("invalid package name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid package name 'hello/world'"); + REQUIRE(std::string{e.what()} == "invalid package name 'hello/world'"); } } @@ -76,7 +74,7 @@ TEST_CASE("invalid package name", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid package name 'hello\\world'"); + REQUIRE(std::string{e.what()} == "invalid package name 'hello\\world'"); } } } @@ -187,7 +185,7 @@ TEST_CASE("add owned version", M) { } catch(const reapack_error &e) { delete ver; - REQUIRE(string(e.what()) == "version belongs to another package"); + REQUIRE(std::string{e.what()} == "version belongs to another package"); } } @@ -205,7 +203,7 @@ TEST_CASE("add duplicate version", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "duplicate version 'r/c/p v1'"); + REQUIRE(std::string{e.what()} == "duplicate version 'r/c/p v1'"); } } diff --git a/test/path.cpp b/test/path.cpp @@ -4,8 +4,6 @@ using Catch::Matchers::StartsWith; -using namespace std; - static const char *M = "[path]"; TEST_CASE("compare paths", M) { @@ -24,7 +22,7 @@ TEST_CASE("append path segments", M) { REQUIRE(path.empty()); REQUIRE(path.size() == 0); - path.append(string()); + path.append(std::string{}); REQUIRE(path.empty()); REQUIRE(path.size() == 0); @@ -215,16 +213,16 @@ TEST_CASE("append absolute path to empty path", M) { TEST_CASE("extended absolute paths", M) { #ifdef _WIN32 Path abs("C:\\"); - abs.append(string(260, 'a')); + abs.append(std::string(260, 'a')); CHECK(abs.absolute()); REQUIRE_THAT(abs.join(), StartsWith("\\\\?\\")); - const Path path(string(500, 'a')); + const Path path(std::string(500, 'a')); CHECK_FALSE(path.absolute()); #else Path path("/hello"); - path.append(string(260, 'a')); + path.append(std::string(260, 'a')); #endif REQUIRE_THAT(path.join(), !StartsWith("\\\\?\\")); diff --git a/test/platform.cpp b/test/platform.cpp @@ -4,8 +4,6 @@ #include <utility> -using namespace std; - static const char *M = "[platform]"; TEST_CASE("default platform", M) { @@ -50,7 +48,7 @@ TEST_CASE("platform from string", M) { } TEST_CASE("test platform", M) { - const pair<Platform, bool> tests[] = { + const std::pair<Platform, bool> tests[] = { {Platform::GenericPlatform, true}, #ifdef __APPLE__ diff --git a/test/receipt.cpp b/test/receipt.cpp @@ -7,16 +7,14 @@ using Catch::Matchers::Contains; using Catch::Matchers::EndsWith; -using namespace std; - -static constexpr const char *M = "[receipt]"; +static const char *M = "[receipt]"; TEST_CASE("non-empty receipt", M) { Receipt r; REQUIRE(r.empty()); SECTION("install") { - IndexPtr ri = make_shared<Index>("Index Name"); + IndexPtr ri = std::make_shared<Index>("Index Name"); Category cat("Category Name", ri.get()); Package pkg(Package::ScriptType, "Package Name", &cat); Version ver("1.0", &pkg); @@ -41,7 +39,7 @@ TEST_CASE("set receipt flags", M) { Receipt::Flag expected; SECTION("install") { - IndexPtr ri = make_shared<Index>("Index Name"); + IndexPtr ri = std::make_shared<Index>("Index Name"); Category cat("Category Name", ri.get()); Package pkg(Package::ScriptType, "Package Name", &cat); Version ver("1.0", &pkg); @@ -77,7 +75,7 @@ TEST_CASE("set receipt flags", M) { } TEST_CASE("set restart needed flag", M) { - IndexPtr ri = make_shared<Index>("Index Name"); + IndexPtr ri = std::make_shared<Index>("Index Name"); Category cat("Category Name", ri.get()); Package script(Package::ScriptType, "Package Name", &cat); Package ext(Package::ExtensionType, "Package Name", &cat); @@ -116,38 +114,38 @@ TEST_CASE("set package changed flag", M) { TEST_CASE("format receipt page title", M) { SECTION("singular") { - ReceiptPage page{vector<int>{1}, "Singular", "Plural"}; + ReceiptPage page{std::vector<int>{1}, "Singular", "Plural"}; REQUIRE(page.title() == "Singular (1)"); } SECTION("plural") { - ReceiptPage page{vector<int>{1, 2, 3}, "Singular", "Plural"}; + ReceiptPage page{std::vector<int>{1, 2, 3}, "Singular", "Plural"}; REQUIRE(page.title() == "Plural (3)"); } SECTION("zero is plural") { - ReceiptPage page{vector<int>{}, "Singular", "Plural"}; + ReceiptPage page{std::vector<int>{}, "Singular", "Plural"}; REQUIRE(page.title() == "Plural (0)"); } SECTION("no plural") { - ReceiptPage page{vector<int>{1, 2, 3}, "Fallback"}; + ReceiptPage page{std::vector<int>{1, 2, 3}, "Fallback"}; REQUIRE(page.title() == "Fallback (3)"); } SECTION("thousand divider") { - ReceiptPage page{vector<int>(42'000, 42), "Singular", "Plural"}; + ReceiptPage page{std::vector<int>(42'000, 42), "Singular", "Plural"}; REQUIRE(page.title() == "Plural (42,000)"); } } TEST_CASE("format receipt page contents", M) { - ReceiptPage page{vector<int>{1, 2, 3}, "", ""}; + ReceiptPage page{std::vector<int>{1, 2, 3}, "", ""}; REQUIRE(page.contents() == "1\r\n2\r\n3"); } TEST_CASE("format install ticket", M) { - IndexPtr ri = make_shared<Index>("Index Name"); + IndexPtr ri = std::make_shared<Index>("Index Name"); Category cat("Category Name", ri.get()); Package pkg(Package::ScriptType, "Package Name", &cat); @@ -163,7 +161,7 @@ TEST_CASE("format install ticket", M) { v3->addSource(new Source({}, "https://google.com", v3)); pkg.addVersion(v3); - ostringstream stream; + std::ostringstream stream; Registry::Entry entry{1}; SECTION("contains fullname") { @@ -207,7 +205,7 @@ TEST_CASE("format install ticket", M) { } TEST_CASE("sort InstallTickets (case insensitive)", M) { - IndexPtr ri = make_shared<Index>("Index Name"); + IndexPtr ri = std::make_shared<Index>("Index Name"); Category cat("Category Name", ri.get()); Package pkg1(Package::ScriptType, "a test", &cat); Version ver1("1.0", &pkg1); @@ -229,7 +227,7 @@ TEST_CASE("sort InstallTickets (case insensitive)", M) { r.addInstall(&ver3, {}); // z is the last letter r.addInstall(&ver1, {}); // a test (duplicate) r.addInstall(&ver2, {}); // Uppercase Name - const string page = r.installedPage().contents(); + const std::string page = r.installedPage().contents(); REQUIRE(page.find(pkg1.name()) < page.find(pkg2.name())); REQUIRE(page.find(pkg2.name()) < page.find(pkg3.name())); diff --git a/test/registry.cpp b/test/registry.cpp @@ -7,8 +7,6 @@ #include <package.hpp> #include <remote.hpp> -using namespace std; - static const char *M = "[registry]"; #define MAKE_PACKAGE \ @@ -87,7 +85,7 @@ TEST_CASE("get file list", M) { reg.push(&ver); - const vector<Registry::File> &files = reg.getFiles(reg.getEntry(&pkg)); + const std::vector<Registry::File> &files = reg.getFiles(reg.getEntry(&pkg)); REQUIRE(files.size() == 1); REQUIRE(files[0].path == src->targetPath()); REQUIRE(files[0].sections == 0); @@ -97,14 +95,14 @@ TEST_CASE("get file list", M) { TEST_CASE("query all packages", M) { MAKE_PACKAGE - const string remote = "Remote Name"; + const std::string remote = "Remote Name"; Registry reg; REQUIRE(reg.getEntries(remote).empty()); reg.push(&ver); - const vector<Registry::Entry> &entries = reg.getEntries(remote); + const std::vector<Registry::Entry> &entries = reg.getEntries(remote); REQUIRE(entries.size() == 1); REQUIRE(entries[0].id == 1); REQUIRE(entries[0].remote == "Remote Name"); @@ -152,7 +150,7 @@ TEST_CASE("file conflicts", M) { CHECK(reg.getEntry(&pkg).id == 0); // still uninstalled - vector<Path> conflicts; + std::vector<Path> conflicts; const auto &pushResult = reg.push(&ver, &conflicts); CHECK(pushResult.id == 0); @@ -180,7 +178,7 @@ TEST_CASE("get main files", M) { const Registry::Entry &entry = reg.push(&ver); - const vector<Registry::File> &current = reg.getMainFiles(entry); + const std::vector<Registry::File> &current = reg.getMainFiles(entry); REQUIRE(current.size() == 1); REQUIRE(current[0].path == main1->targetPath()); REQUIRE(current[0].sections == Source::MIDIEditorSection); diff --git a/test/remote.cpp b/test/remote.cpp @@ -3,8 +3,6 @@ #include <errors.hpp> #include <remote.hpp> -using namespace std; - static const char *M = "[remote]"; TEST_CASE("construct remote", M) { @@ -17,7 +15,7 @@ TEST_CASE("construct remote", M) { TEST_CASE("remote name validation", M) { SECTION("invalid") { - const string invalidNames[] = { + const std::string invalidNames[] = { "", "ab/cd", "ab\\cd", @@ -37,19 +35,19 @@ TEST_CASE("remote name validation", M) { "lpt1", }; - for(const string &name : invalidNames) { + for(const std::string &name : invalidNames) { try { Remote remote(name, "url"); FAIL("'" + name + "' was allowed"); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid name"); + REQUIRE(std::string{e.what()} == "invalid name"); } } } SECTION("valid") { - const string validNames[] = { + const std::string validNames[] = { "1234", "hello world", "hello_world", @@ -58,7 +56,7 @@ TEST_CASE("remote name validation", M) { "Repository #1", }; - for(const string &name : validNames) { + for(const std::string &name : validNames) { try { Remote remote(name, "url"); } @@ -71,18 +69,18 @@ TEST_CASE("remote name validation", M) { TEST_CASE("remote url validation", M) { SECTION("invalid") { - const string invalidUrls[] = { + const std::string invalidUrls[] = { "", "hello world", // space should be %20 }; - for(const string &url : invalidUrls) { + for(const std::string &url : invalidUrls) { try { Remote remote("hello", url); FAIL("'" + url + "' was allowed"); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid url"); + REQUIRE(std::string{e.what()} == "invalid url"); } } } @@ -97,7 +95,7 @@ TEST_CASE("set invalid values", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid name"); + REQUIRE(std::string{e.what()} == "invalid name"); } } @@ -107,7 +105,7 @@ TEST_CASE("set invalid values", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid url"); + REQUIRE(std::string{e.what()} == "invalid url"); } } } @@ -164,7 +162,8 @@ TEST_CASE("protect remote", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "cannot change the URL of a protected repository"); + REQUIRE(std::string{e.what()} == + "cannot change the URL of a protected repository"); } remote.setUrl(remote.url()); // this should work for AddSetRepository API @@ -286,7 +285,7 @@ TEST_CASE("get enabled remotes", M) { list.add({"hello", "url1", true}); list.add({"world", "url2", false}); - const vector<Remote> array = list.getEnabled(); + const std::vector<Remote> array = list.getEnabled(); REQUIRE(array.size() == 1); REQUIRE(array[0].name() == "hello"); diff --git a/test/source.cpp b/test/source.cpp @@ -6,8 +6,6 @@ #include <errors.hpp> -using namespace std; - static const char *M = "[source]"; #define MAKE_VERSION \ @@ -121,19 +119,18 @@ TEST_CASE("implicit section detection from source (v1.0 compatibility)") { TEST_CASE("empty source url", M) { MAKE_VERSION; - try { + auto test = [ver] { const Source source("filename", {}, &ver); - FAIL(); - } - catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "empty source url"); - } + }; + + CHECK_THROWS_AS(test(), reapack_error); + REQUIRE_THROWS_WITH(test(), "empty source url"); } TEST_CASE("source target path", M) { MAKE_VERSION; - const pair<Package::Type, string> tests[] = { + const std::pair<Package::Type, std::string> tests[] = { {Package::ScriptType, "Scripts/Index Name/Category Name/file.name"}, {Package::EffectType, "Effects/Index Name/Category Name/file.name"}, {Package::ExtensionType, "UserPlugins/file.name"}, diff --git a/test/string.cpp b/test/string.cpp @@ -2,18 +2,16 @@ #include <string.hpp> -static constexpr const char *M = "[string]"; - -using namespace std; +static const char *M = "[string]"; TEST_CASE("string format", M) { - const string &formatted = String::format("%d%% Hello %s!", 100, "World"); + const std::string &formatted = String::format("%d%% Hello %s!", 100, "World"); CHECK(formatted.size() == 17); REQUIRE(formatted == "100% Hello World!"); } TEST_CASE("indent string", M) { - string actual; + std::string actual; SECTION("simple") actual = String::indent("line1\nline2"); diff --git a/test/time.cpp b/test/time.cpp @@ -2,8 +2,6 @@ #include <time.hpp> -using namespace std; - static const char *M = "[time]"; TEST_CASE("valid time", M) { @@ -24,7 +22,7 @@ TEST_CASE("garbage time string", M) { REQUIRE_FALSE(time.isValid()); REQUIRE_FALSE(time); REQUIRE(time == Time()); - REQUIRE(time.toString() == string()); + REQUIRE(time.toString() == ""); } TEST_CASE("out of range time string", M) { @@ -32,7 +30,7 @@ TEST_CASE("out of range time string", M) { REQUIRE_FALSE(time.isValid()); REQUIRE_FALSE(time); REQUIRE(time == Time()); - REQUIRE(time.toString() == string()); + REQUIRE(time.toString() == ""); } TEST_CASE("compare times", M) { diff --git a/test/version.cpp b/test/version.cpp @@ -8,8 +8,6 @@ #include <sstream> -using namespace std; - #define MAKE_PACKAGE \ Index ri("Index Name"); \ Category cat("Category Name", &ri); \ @@ -54,7 +52,7 @@ TEST_CASE("parse valid versions", M) { TEST_CASE("parse invalid versions", M) { VersionName ver; - string name; + std::string name; SECTION("only letters") name = "hello"; @@ -70,7 +68,7 @@ TEST_CASE("parse invalid versions", M) { FAIL("'" + name + "' was accepted"); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "invalid version name '" + name + "'"); + REQUIRE(std::string{e.what()} == "invalid version name '" + name + "'"); } REQUIRE(ver.toString().empty()); @@ -90,7 +88,7 @@ TEST_CASE("parse version failsafe", M) { SECTION("invalid") { REQUIRE_FALSE(ver.tryParse("hello")); - string error; + std::string error; REQUIRE_FALSE(ver.tryParse("world", &error)); REQUIRE(ver.toString().empty()); @@ -118,7 +116,7 @@ TEST_CASE("version segment overflow", M) { FAIL(); } catch(const reapack_error &e) { - REQUIRE(string(e.what()) == "version segment overflow in '9999999999999999999999'"); + REQUIRE(std::string{e.what()} == "version segment overflow in '9999999999999999999999'"); } } @@ -230,7 +228,7 @@ TEST_CASE("add owned source", M) { } catch(const reapack_error &e) { delete src; - REQUIRE(string(e.what()) == "source belongs to another version"); + REQUIRE(std::string{e.what()} == "source belongs to another version"); } } @@ -259,7 +257,7 @@ TEST_CASE("list files", M) { path1.append("Category Name"); path1.append("file"); - const set<Path> expected{path1}; + const std::set<Path> expected{path1}; REQUIRE(ver.files() == expected); } @@ -296,7 +294,7 @@ TEST_CASE("version date", M) { } TEST_CASE("output version", M) { - ostringstream stream; + std::ostringstream stream; Version ver("1.2.3", nullptr); SECTION("empty version") { diff --git a/test/win32.cpp b/test/win32.cpp @@ -2,8 +2,6 @@ #include <win32.hpp> -using namespace std; - static const char *M = "[win32]"; TEST_CASE("widen string", M) { diff --git a/win32.tup b/win32.tup @@ -11,8 +11,8 @@ VCPKG = vendor/vcpkg/installed/@(VCPKG_TRIPLET) CXXFLAGS := /nologo /std:c++17 /W3 /WX /wd4996 /EHsc /MT /O2 /Z7 /Zo CXXFLAGS += /Ivendor /I$(VCPKG)/include /Ivendor/WDL /Ivendor/WDL/WDL -CXXFLAGS += /DWDL_NO_DEFINE_MINMAX /DCURL_STATICLIB /DUNICODE /DNDEBUG -CXXFLAGS += /DREAPACK_FILE#\"$(REAPACK_FILE).dll\" +CXXFLAGS += /DNOMINMAX /DWDL_NO_DEFINE_MINMAX /DCURL_STATICLIB /DUNICODE +CXXFLAGS += /DNDEBUG /DREAPACK_FILE#\"$(REAPACK_FILE).dll\" LD := $(WRAP) link LDFLAGS := /nologo User32.lib Shell32.lib Gdi32.lib Comdlg32.lib Comctl32.lib Bcrypt.lib