mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-25 16:43:33 +00:00
Merge branch 'vfs_string_view' into 'master'
Use std::string_view in VFS::Manager See merge request OpenMW/openmw!2148
This commit is contained in:
commit
b032a643f9
@ -58,9 +58,9 @@ namespace VFS
|
|||||||
archive->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char);
|
archive->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
Files::IStreamPtr Manager::get(const std::string &name) const
|
Files::IStreamPtr Manager::get(std::string_view name) const
|
||||||
{
|
{
|
||||||
std::string normalized = name;
|
std::string normalized(name);
|
||||||
normalize_path(normalized, mStrict);
|
normalize_path(normalized, mStrict);
|
||||||
|
|
||||||
return getNormalized(normalized);
|
return getNormalized(normalized);
|
||||||
@ -74,24 +74,24 @@ namespace VFS
|
|||||||
return found->second->open();
|
return found->second->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::exists(const std::string &name) const
|
bool Manager::exists(std::string_view name) const
|
||||||
{
|
{
|
||||||
std::string normalized = name;
|
std::string normalized(name);
|
||||||
normalize_path(normalized, mStrict);
|
normalize_path(normalized, mStrict);
|
||||||
|
|
||||||
return mIndex.find(normalized) != mIndex.end();
|
return mIndex.find(normalized) != mIndex.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Manager::normalizeFilename(const std::string& name) const
|
std::string Manager::normalizeFilename(std::string_view name) const
|
||||||
{
|
{
|
||||||
std::string result = name;
|
std::string result(name);
|
||||||
normalize_path(result, mStrict);
|
normalize_path(result, mStrict);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Manager::getArchive(const std::string& name) const
|
std::string Manager::getArchive(std::string_view name) const
|
||||||
{
|
{
|
||||||
std::string normalized = name;
|
std::string normalized(name);
|
||||||
normalize_path(normalized, mStrict);
|
normalize_path(normalized, mStrict);
|
||||||
for(auto it = mArchives.rbegin(); it != mArchives.rend(); ++it)
|
for(auto it = mArchives.rbegin(); it != mArchives.rend(); ++it)
|
||||||
{
|
{
|
||||||
@ -101,9 +101,9 @@ namespace VFS
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Manager::getAbsoluteFileName(const std::string& name) const
|
std::string Manager::getAbsoluteFileName(std::string_view name) const
|
||||||
{
|
{
|
||||||
std::string normalized = name;
|
std::string normalized(name);
|
||||||
normalize_path(normalized, mStrict);
|
normalize_path(normalized, mStrict);
|
||||||
|
|
||||||
std::map<std::string, File*>::const_iterator found = mIndex.find(normalized);
|
std::map<std::string, File*>::const_iterator found = mIndex.find(normalized);
|
||||||
@ -120,7 +120,7 @@ namespace VFS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(const std::string& path) const
|
Manager::RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(std::string_view path) const
|
||||||
{
|
{
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
return { mIndex.begin(), mIndex.end() };
|
return { mIndex.begin(), mIndex.end() };
|
||||||
|
@ -67,34 +67,34 @@ namespace VFS
|
|||||||
|
|
||||||
/// Does a file with this name exist?
|
/// Does a file with this name exist?
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
bool exists(const std::string& name) const;
|
bool exists(std::string_view name) const;
|
||||||
|
|
||||||
/// Normalize the given filename, making slashes/backslashes consistent, and lower-casing if mStrict is false.
|
/// Normalize the given filename, making slashes/backslashes consistent, and lower-casing if mStrict is false.
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
[[nodiscard]] std::string normalizeFilename(const std::string& name) const;
|
[[nodiscard]] std::string normalizeFilename(std::string_view name) const;
|
||||||
|
|
||||||
/// Retrieve a file by name.
|
/// Retrieve a file by name.
|
||||||
/// @note Throws an exception if the file can not be found.
|
/// @note Throws an exception if the file can not be found.
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
Files::IStreamPtr get(const std::string& name) const;
|
Files::IStreamPtr get(std::string_view name) const;
|
||||||
|
|
||||||
/// Retrieve a file by name (name is already normalized).
|
/// Retrieve a file by name (name is already normalized).
|
||||||
/// @note Throws an exception if the file can not be found.
|
/// @note Throws an exception if the file can not be found.
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
Files::IStreamPtr getNormalized(const std::string& normalizedName) const;
|
Files::IStreamPtr getNormalized(const std::string& normalizedName) const;
|
||||||
|
|
||||||
std::string getArchive(const std::string& name) const;
|
std::string getArchive(std::string_view name) const;
|
||||||
|
|
||||||
/// Recursivly iterate over the elements of the given path
|
/// Recursivly iterate over the elements of the given path
|
||||||
/// In practice it return all files of the VFS starting with the given path
|
/// In practice it return all files of the VFS starting with the given path
|
||||||
/// @note the path is normalized
|
/// @note the path is normalized
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
RecursiveDirectoryRange getRecursiveDirectoryIterator(const std::string& path) const;
|
RecursiveDirectoryRange getRecursiveDirectoryIterator(std::string_view path) const;
|
||||||
|
|
||||||
/// Retrieve the absolute path to the file
|
/// Retrieve the absolute path to the file
|
||||||
/// @note Throws an exception if the file can not be found.
|
/// @note Throws an exception if the file can not be found.
|
||||||
/// @note May be called from any thread once the index has been built.
|
/// @note May be called from any thread once the index has been built.
|
||||||
std::string getAbsoluteFileName(const std::string& name) const;
|
std::string getAbsoluteFileName(std::string_view name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mStrict;
|
bool mStrict;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user