diff --git a/AudioUnit/AudioGroupFilePresenter.hpp b/AudioUnit/AudioGroupFilePresenter.hpp index bad2933..28970bb 100644 --- a/AudioUnit/AudioGroupFilePresenter.hpp +++ b/AudioUnit/AudioGroupFilePresenter.hpp @@ -64,7 +64,7 @@ struct AudioGroupDataCollection bool loadSamp(AudioGroupFilePresenter* presenter); bool loadMeta(AudioGroupFilePresenter* presenter); - AudioGroupDataCollection(const std::string& name, NSURL* proj, NSURL* pool, NSURL* sdir, NSURL* samp, NSURL* meta); + AudioGroupDataCollection(std::string_view name, NSURL* proj, NSURL* pool, NSURL* sdir, NSURL* samp, NSURL* meta); bool isDataComplete() const { return m_projData.size() && m_poolData.size() && m_sdirData.size() && m_sampData.size() && m_metaData; @@ -88,7 +88,7 @@ struct AudioGroupCollection void addCollection(AudioGroupFilePresenter* presenter, std::vector>&& collection); void update(AudioGroupFilePresenter* presenter); - bool doSearch(const std::string& str); + bool doSearch(std::string_view str); bool doActiveFilter(); void addSFX(std::vector& vecOut); void addSamples(std::vector& vecOut); diff --git a/AudioUnit/AudioGroupFilePresenter.mm b/AudioUnit/AudioGroupFilePresenter.mm index 4febcc3..a75c30c 100644 --- a/AudioUnit/AudioGroupFilePresenter.mm +++ b/AudioUnit/AudioGroupFilePresenter.mm @@ -161,13 +161,13 @@ void AudioGroupCollection::update(AudioGroupFilePresenter* presenter) } } -bool AudioGroupCollection::doSearch(const std::string& str) +bool AudioGroupCollection::doSearch(std::string_view str) { bool ret = false; m_filterGroups.clear(); m_filterGroups.reserve(m_groups.size()); for (auto it = m_groups.begin() ; it != m_groups.end() ; ++it) - if (str.empty() || StrToLower(it->first).find(str) != std::string::npos) + if (str.empty() || StrToLower(it->first).find(str.data()) != std::string::npos) { m_filterGroups.push_back(it); ret = true; diff --git a/CMakeLists.txt b/CMakeLists.txt index c2e08f2..5a8d6aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDAR project(amuse) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT MSVC) diff --git a/VST/AudioGroupFilePresenter.cpp b/VST/AudioGroupFilePresenter.cpp index 8fce8ad..0dd172a 100644 --- a/VST/AudioGroupFilePresenter.cpp +++ b/VST/AudioGroupFilePresenter.cpp @@ -217,7 +217,7 @@ bool AudioGroupDataCollection::loadMeta() return ret.operator bool(); } -AudioGroupDataCollection::AudioGroupDataCollection(const std::wstring& path, const std::wstring& name) +AudioGroupDataCollection::AudioGroupDataCollection(std::wstring_view path, std::wstring_view name) : m_path(path), m_name(name) { } @@ -295,7 +295,7 @@ void AudioGroupDataCollection::addToEngine(amuse::Engine& engine) void AudioGroupDataCollection::removeFromEngine(amuse::Engine& engine) const { engine.removeAudioGroup(*m_loadedData); } -AudioGroupCollection::AudioGroupCollection(const std::wstring& path, const std::wstring& name) +AudioGroupCollection::AudioGroupCollection(std::wstring_view path, std::wstring_view name) : m_path(path), m_name(name) { } @@ -398,7 +398,7 @@ void AudioGroupFilePresenter::update() } void AudioGroupFilePresenter::addCollection( - const std::wstring& name, std::vector>&& collection) + std::wstring_view name, std::vector>&& collection) { std::wstring path = m_backend.getUserDir() + L'\\' + name; AudioGroupCollection& insert = diff --git a/VST/AudioGroupFilePresenter.hpp b/VST/AudioGroupFilePresenter.hpp index 2b23f6f..618adc1 100644 --- a/VST/AudioGroupFilePresenter.hpp +++ b/VST/AudioGroupFilePresenter.hpp @@ -61,7 +61,7 @@ struct AudioGroupDataCollection bool loadSamp(); bool loadMeta(); - AudioGroupDataCollection(const std::wstring& path, const std::wstring& name); + AudioGroupDataCollection(std::wstring_view path, std::wstring_view name); bool isDataComplete() const { return m_projData.size() && m_poolData.size() && m_sdirData.size() && m_sampData.size() && m_metaData; @@ -82,7 +82,7 @@ struct AudioGroupCollection std::map> m_groups; std::vector m_iteratorVec; - AudioGroupCollection(const std::wstring& path, const std::wstring& name); + AudioGroupCollection(std::wstring_view path, std::wstring_view name); void addCollection(std::vector>&& collection); void update(AudioGroupFilePresenter& presenter); void populateFiles(VSTEditor& editor, HTREEITEM colHandle, size_t parentIdx); @@ -106,7 +106,7 @@ public: void populateCollectionColumn(VSTEditor& editor); void populateGroupColumn(VSTEditor& editor, int collectionIdx, int fileIdx); void populatePageColumn(VSTEditor& editor, int collectionIdx, int fileIdx, int groupIdx); - void addCollection(const std::wstring& name, + void addCollection(std::wstring_view name, std::vector>&& collection); void removeCollection(unsigned idx); VSTBackend& getBackend() { return m_backend; } diff --git a/VST/VSTBackend.hpp b/VST/VSTBackend.hpp index cd14e02..2db8f20 100644 --- a/VST/VSTBackend.hpp +++ b/VST/VSTBackend.hpp @@ -59,7 +59,7 @@ public: void setBlockSize(VstInt32 blockSize); amuse::Engine& getAmuseEngine() { return *m_engine; } - const std::wstring& getUserDir() const { return m_userDir; } + std::wstring_view getUserDir() const { return m_userDir; } AudioGroupFilePresenter& getFilePresenter() { return m_filePresenter; } void loadGroupFile(int collectionIdx, int fileIdx); diff --git a/driver/amuseconv.cpp b/driver/amuseconv.cpp index e9a899e..e8272cb 100644 --- a/driver/amuseconv.cpp +++ b/driver/amuseconv.cpp @@ -31,22 +31,22 @@ static void ReportConvType(ConvType tp) } } -static bool BuildAudioGroup(const amuse::SystemString& groupBase, const amuse::SystemString& targetPath) +static bool BuildAudioGroup(amuse::SystemStringView groupBase, amuse::SystemStringView targetPath) { return true; } -static bool ExtractAudioGroup(const amuse::SystemString& inPath, const amuse::SystemString& targetPath) +static bool ExtractAudioGroup(amuse::SystemStringView inPath, amuse::SystemStringView targetPath) { amuse::ContainerRegistry::Type type; - auto groups = amuse::ContainerRegistry::LoadContainer(inPath.c_str(), type); + auto groups = amuse::ContainerRegistry::LoadContainer(inPath.data(), type); if (groups.size()) { Log.report(logvisor::Info, _S("Found '%s'"), amuse::ContainerRegistry::TypeToName(type)); - amuse::Mkdir(targetPath.c_str(), 0755); - Log.report(logvisor::Info, _S("Established directory at %s"), targetPath.c_str()); + amuse::Mkdir(targetPath.data(), 0755); + Log.report(logvisor::Info, _S("Established directory at %s"), targetPath.data()); for (auto& group : groups) { @@ -54,14 +54,14 @@ static bool ExtractAudioGroup(const amuse::SystemString& inPath, const amuse::Sy } } - auto songs = amuse::ContainerRegistry::LoadSongs(inPath.c_str()); + auto songs = amuse::ContainerRegistry::LoadSongs(inPath.data()); amuse::SystemString songsDir = targetPath + _S("/midifiles"); bool madeDir = false; for (auto& pair : songs) { if (!madeDir) { - amuse::Mkdir(targetPath.c_str(), 0755); + amuse::Mkdir(targetPath.data(), 0755); amuse::Mkdir(songsDir.c_str(), 0755); madeDir = true; } @@ -83,9 +83,9 @@ static bool ExtractAudioGroup(const amuse::SystemString& inPath, const amuse::Sy return true; } -static bool BuildSNG(const amuse::SystemString& inPath, const amuse::SystemString& targetPath, int version, bool big) +static bool BuildSNG(amuse::SystemStringView inPath, amuse::SystemStringView targetPath, int version, bool big) { - FILE* fp = amuse::FOpen(inPath.c_str(), _S("rb")); + FILE* fp = amuse::FOpen(inPath.data(), _S("rb")); if (!fp) return false; @@ -100,16 +100,16 @@ static bool BuildSNG(const amuse::SystemString& inPath, const amuse::SystemStrin if (out.empty()) return false; - fp = amuse::FOpen(targetPath.c_str(), _S("wb")); + fp = amuse::FOpen(targetPath.data(), _S("wb")); fwrite(out.data(), 1, out.size(), fp); fclose(fp); return true; } -static bool ExtractSNG(const amuse::SystemString& inPath, const amuse::SystemString& targetPath) +static bool ExtractSNG(amuse::SystemStringView inPath, amuse::SystemStringView targetPath) { - FILE* fp = amuse::FOpen(inPath.c_str(), _S("rb")); + FILE* fp = amuse::FOpen(inPath.data(), _S("rb")); if (!fp) return false; @@ -126,7 +126,7 @@ static bool ExtractSNG(const amuse::SystemString& inPath, const amuse::SystemStr if (out.empty()) return false; - fp = amuse::FOpen(targetPath.c_str(), _S("wb")); + fp = amuse::FOpen(targetPath.data(), _S("wb")); fwrite(out.data(), 1, out.size(), fp); fclose(fp); diff --git a/include/amuse/Common.hpp b/include/amuse/Common.hpp index d49738e..0bcd17e 100644 --- a/include/amuse/Common.hpp +++ b/include/amuse/Common.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifndef _WIN32 @@ -47,6 +48,7 @@ static inline int Mkdir(const wchar_t* path, int) { return _wmkdir(path); } static inline int Stat(const wchar_t* path, Sstat* statout) { return _wstat(path, statout); } #else using SystemString = std::string; +using SystemStringView = std::string_view; using SystemChar = char; #ifndef _S #define _S(val) val diff --git a/include/amuse/DirectoryEnumerator.hpp b/include/amuse/DirectoryEnumerator.hpp index df82dee..af94fa0 100644 --- a/include/amuse/DirectoryEnumerator.hpp +++ b/include/amuse/DirectoryEnumerator.hpp @@ -9,21 +9,21 @@ namespace amuse struct CaseInsensitiveCompare { - bool operator()(const std::string& lhs, const std::string& rhs) const + bool operator()(std::string_view lhs, std::string_view rhs) const { #if _WIN32 - if (_stricmp(lhs.c_str(), rhs.c_str()) < 0) + if (_stricmp(lhs.data(), rhs.data()) < 0) #else - if (strcasecmp(lhs.c_str(), rhs.c_str()) < 0) + if (strcasecmp(lhs.data(), rhs.data()) < 0) #endif return true; return false; } #if _WIN32 - bool operator()(const std::wstring& lhs, const std::wstring& rhs) const + bool operator()(std::wstring_view lhs, std::wstring_view rhs) const { - if (_wcsicmp(lhs.c_str(), rhs.c_str()) < 0) + if (_wcsicmp(lhs.data(), rhs.data()) < 0) return true; return false; } @@ -59,12 +59,7 @@ private: std::vector m_entries; public: - DirectoryEnumerator(const SystemString& path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false, - bool reverse = false, bool noHidden = false) - : DirectoryEnumerator(path.c_str(), mode, sizeSort, reverse, noHidden) - { - } - DirectoryEnumerator(const SystemChar* path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false, + DirectoryEnumerator(SystemStringView path, Mode mode = Mode::DirsThenFilesSorted, bool sizeSort = false, bool reverse = false, bool noHidden = false); operator bool() const { return m_entries.size() != 0; } diff --git a/lib/DirectoryEnumerator.cpp b/lib/DirectoryEnumerator.cpp index ff6ead6..c21c8fc 100644 --- a/lib/DirectoryEnumerator.cpp +++ b/lib/DirectoryEnumerator.cpp @@ -22,10 +22,10 @@ namespace amuse { -DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode, bool sizeSort, bool reverse, bool noHidden) +DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode, bool sizeSort, bool reverse, bool noHidden) { Sstat theStat; - if (Stat(path, &theStat) || !S_ISDIR(theStat.st_mode)) + if (Stat(path.data(), &theStat) || !S_ISDIR(theStat.st_mode)) return; #if _WIN32 @@ -160,7 +160,7 @@ DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode, bool #else - DIR* dir = opendir(path); + DIR* dir = opendir(path.data()); if (!dir) return; const dirent* d;