1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00
OpenMW/components/vfs/recursivedirectoryiterator.hpp
elsid 35d9b18b4c
Add type for normalized VFS path and use for VFS::Manager file map key
This will reduce the number of path normalizations while more places will use
this type. In some cases it also will reduce number of temporary allocations for
new strings.

For now make conversion from and to std::string_view implicit to allow gradual
migration to this type.
2024-01-18 00:03:06 +01:00

55 lines
1.3 KiB
C++

#ifndef OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#define OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#include <string>
#include "filemap.hpp"
#include "pathutil.hpp"
namespace VFS
{
class RecursiveDirectoryIterator
{
public:
RecursiveDirectoryIterator(FileMap::const_iterator it)
: mIt(it)
{
}
const std::string& operator*() const { return mIt->first.value(); }
const std::string* operator->() const { return &mIt->first.value(); }
RecursiveDirectoryIterator& operator++()
{
++mIt;
return *this;
}
friend bool operator==(const RecursiveDirectoryIterator& lhs, const RecursiveDirectoryIterator& rhs) = default;
private:
FileMap::const_iterator mIt;
};
class RecursiveDirectoryRange
{
public:
RecursiveDirectoryRange(RecursiveDirectoryIterator first, RecursiveDirectoryIterator last)
: mBegin(first)
, mEnd(last)
{
}
RecursiveDirectoryIterator begin() const { return mBegin; }
RecursiveDirectoryIterator end() const { return mEnd; }
private:
RecursiveDirectoryIterator mBegin;
RecursiveDirectoryIterator mEnd;
};
}
#endif