First implementation of custom path type.

This commit is contained in:
2025-07-11 01:13:23 +02:00
parent 33bc48dd58
commit 018c75a5ed
11 changed files with 616 additions and 226 deletions

View File

@@ -31,40 +31,20 @@ namespace mijin
// public functions
//
fs::path StackedFileSystemAdapter::getHomeFolder()
std::vector<FolderEntry> StackedFileSystemAdapter::listFiles(PathView folder)
{
if (adapters_.empty()) {
return fs::path();
}
#if MIJIN_COMPILER == MIJIN_COMPILER_MSVC
#pragma warning(push)
#pragma warning(disable : 4996) // yeah, we're using a deprecated function here, in order to implement another deprecated function ¯\_(ツ)_/¯
#elif MIJIN_COMPILER == MIJIN_COMPILER_GCC || MIJIN_COMPILER == MIJIN_COMPILER_CLANG
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
return adapters_.front()->getHomeFolder();
#if MIJIN_COMPILER == MIJIN_COMPILER_MSVC
#pragma warning(pop)
#elif MIJIN_COMPILER == MIJIN_COMPILER_GCC || MIJIN_COMPILER == MIJIN_COMPILER_CLANG
#pragma GCC diagnostic pop
#endif
}
std::vector<FileInfo> StackedFileSystemAdapter::listFiles(const fs::path& folder)
{
std::vector<FileInfo> files;
std::vector<FolderEntry> files;
for (auto& adapter : adapters_)
{
for (const FileInfo& file : adapter->listFiles(folder))
for (const FolderEntry& entry : adapter->listFiles(folder))
{
auto it = std::find_if(files.begin(), files.end(), [&](const FileInfo& existing)
auto it = std::ranges::find_if(files, [&](const FolderEntry& existing)
{
return existing.path == file.path;
return existing.path == entry.path;
});
if (it == files.end()) {
files.push_back(file);
files.push_back(entry);
}
}
}
@@ -72,7 +52,7 @@ std::vector<FileInfo> StackedFileSystemAdapter::listFiles(const fs::path& folder
return files;
}
FileInfo StackedFileSystemAdapter::getFileInfo(const fs::path& file)
FileInfo StackedFileSystemAdapter::getFileInfo(PathView file)
{
for (auto& adapter : adapters_)
{
@@ -85,11 +65,11 @@ FileInfo StackedFileSystemAdapter::getFileInfo(const fs::path& file)
return {};
}
Optional<fs::path> StackedFileSystemAdapter::getNativePath(const fs::path& file)
Optional<NativePath> StackedFileSystemAdapter::getNativePath(PathView file)
{
for (auto& adapter : adapters_)
{
Optional<fs::path> result = adapter->getNativePath(file);
Optional<NativePath> result = adapter->getNativePath(file);
if (!result.empty())
{
return result;
@@ -98,7 +78,7 @@ Optional<fs::path> StackedFileSystemAdapter::getNativePath(const fs::path& file)
return NULL_OPTIONAL;
}
StreamError StackedFileSystemAdapter::open(const fs::path& path, FileOpenMode mode, std::unique_ptr<Stream>& outStream)
StreamError StackedFileSystemAdapter::open(PathView path, FileOpenMode mode, std::unique_ptr<Stream>& outStream)
{
// try to open existing files first
for (auto& adapter : adapters_)
@@ -125,7 +105,7 @@ StreamError StackedFileSystemAdapter::open(const fs::path& path, FileOpenMode mo
return StreamError::IO_ERROR;
}
void StackedFileSystemAdapter::getAllPaths(const fs::path& path, std::vector<PathReference>& outPaths)
void StackedFileSystemAdapter::getAllPaths(PathView path, std::vector<PathReference>& outPaths)
{
for (auto& adapter : adapters_)
{