Use forward declaration for some VFS types

This will allow to save on preprocessed code size in the future changes.
ini_importer_tests
elsid 12 months ago
parent 5ae878c248
commit a2147d70cc
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -17,6 +17,7 @@
#include <components/vfs/bsaarchive.hpp> #include <components/vfs/bsaarchive.hpp>
#include <components/vfs/filesystemarchive.hpp> #include <components/vfs/filesystemarchive.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>

@ -11,6 +11,7 @@
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
CSMWorld::Resources::Resources( CSMWorld::Resources::Resources(
const VFS::Manager* vfs, const std::string& baseDirectory, UniversalId::Type type, const char* const* extensions) const VFS::Manager* vfs, const std::string& baseDirectory, UniversalId::Type type, const char* const* extensions)

@ -18,6 +18,7 @@
#include <components/resource/resourcesystem.hpp> #include <components/resource/resourcesystem.hpp>
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp" #include "../mwbase/inputmanager.hpp"

@ -29,6 +29,7 @@
#include <components/sceneutil/lightmanager.hpp> #include <components/sceneutil/lightmanager.hpp>
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include <components/widgets/sharedstatebutton.hpp> #include <components/widgets/sharedstatebutton.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"

@ -5,6 +5,7 @@
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp> #include <components/vfs/pathutil.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"

@ -33,6 +33,7 @@
#include <components/sceneutil/keyframe.hpp> #include <components/sceneutil/keyframe.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include <components/sceneutil/lightmanager.hpp> #include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/lightutil.hpp> #include <components/sceneutil/lightutil.hpp>

@ -23,6 +23,7 @@
#include <components/stereo/multiview.hpp> #include <components/stereo/multiview.hpp>
#include <components/stereo/stereomanager.hpp> #include <components/stereo/stereomanager.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"

@ -13,6 +13,7 @@
#include <components/settings/values.hpp> #include <components/settings/values.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp> #include <components/vfs/pathutil.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"

@ -6,6 +6,7 @@
#include <components/misc/strings/conversion.hpp> #include <components/misc/strings/conversion.hpp>
#include <components/vfs/archive.hpp> #include <components/vfs/archive.hpp>
#include <components/vfs/file.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp> #include <components/vfs/pathutil.hpp>

@ -1,27 +1,13 @@
#ifndef OPENMW_COMPONENTS_RESOURCE_ARCHIVE_H #ifndef OPENMW_COMPONENTS_VFS_ARCHIVE_H
#define OPENMW_COMPONENTS_RESOURCE_ARCHIVE_H #define OPENMW_COMPONENTS_VFS_ARCHIVE_H
#include <filesystem> #include <string>
#include <map>
#include <string_view> #include <string_view>
#include <components/files/istreamptr.hpp> #include "filemap.hpp"
namespace VFS namespace VFS
{ {
class File
{
public:
virtual ~File() = default;
virtual Files::IStreamPtr open() = 0;
virtual std::filesystem::path getPath() = 0;
};
using FileMap = std::map<std::string, File*, std::less<>>;
class Archive class Archive
{ {
public: public:

@ -2,6 +2,7 @@
#define VFS_BSAARCHIVE_HPP_ #define VFS_BSAARCHIVE_HPP_
#include "archive.hpp" #include "archive.hpp"
#include "file.hpp"
#include "pathutil.hpp" #include "pathutil.hpp"
#include <components/bsa/ba2dx10file.hpp> #include <components/bsa/ba2dx10file.hpp>

@ -0,0 +1,21 @@
#ifndef OPENMW_COMPONENTS_VFS_FILE_H
#define OPENMW_COMPONENTS_VFS_FILE_H
#include <filesystem>
#include <components/files/istreamptr.hpp>
namespace VFS
{
class File
{
public:
virtual ~File() = default;
virtual Files::IStreamPtr open() = 0;
virtual std::filesystem::path getPath() = 0;
};
}
#endif

@ -0,0 +1,14 @@
#ifndef OPENMW_COMPONENTS_VFS_FILEMAP_H
#define OPENMW_COMPONENTS_VFS_FILEMAP_H
#include <map>
#include <string>
namespace VFS
{
class File;
using FileMap = std::map<std::string, File*, std::less<>>;
}
#endif

@ -2,8 +2,9 @@
#define OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H #define OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H
#include "archive.hpp" #include "archive.hpp"
#include <filesystem> #include "file.hpp"
#include <filesystem>
#include <string> #include <string>
namespace VFS namespace VFS

@ -5,12 +5,19 @@
#include <components/files/conversion.hpp> #include <components/files/conversion.hpp>
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include <components/vfs/recursivedirectoryiterator.hpp>
#include "archive.hpp" #include "archive.hpp"
#include "file.hpp"
#include "pathutil.hpp" #include "pathutil.hpp"
#include "recursivedirectoryiterator.hpp"
namespace VFS namespace VFS
{ {
Manager::Manager() = default;
Manager::~Manager() = default;
void Manager::reset() void Manager::reset()
{ {
mIndex.clear(); mIndex.clear();
@ -70,7 +77,7 @@ namespace VFS
return found->second->getPath(); return found->second->getPath();
} }
Manager::RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(std::string_view path) const RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(std::string_view path) const
{ {
if (path.empty()) if (path.empty())
return { mIndex.begin(), mIndex.end() }; return { mIndex.begin(), mIndex.end() };

@ -4,32 +4,17 @@
#include <components/files/istreamptr.hpp> #include <components/files/istreamptr.hpp>
#include <filesystem> #include <filesystem>
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include "archive.hpp" #include "filemap.hpp"
namespace VFS namespace VFS
{ {
class Archive;
template <typename Iterator> class RecursiveDirectoryRange;
class IteratorPair
{
public:
IteratorPair(Iterator first, Iterator last)
: mFirst(first)
, mLast(last)
{
}
Iterator begin() const { return mFirst; }
Iterator end() const { return mLast; }
private:
Iterator mFirst;
Iterator mLast;
};
/// @brief The main class responsible for loading files from a virtual file system. /// @brief The main class responsible for loading files from a virtual file system.
/// @par Various archive types (e.g. directories on the filesystem, or compressed archives) /// @par Various archive types (e.g. directories on the filesystem, or compressed archives)
@ -37,30 +22,12 @@ namespace VFS
/// contained in multiple archives, the last added archive will have priority. /// contained in multiple archives, the last added archive will have priority.
/// @par Most of the methods in this class are considered thread-safe, see each method documentation for details. /// @par Most of the methods in this class are considered thread-safe, see each method documentation for details.
class Manager class Manager
{
class RecursiveDirectoryIterator
{ {
public: public:
RecursiveDirectoryIterator(FileMap::const_iterator it) Manager();
: mIt(it)
{
}
const std::string& operator*() const { return mIt->first; }
const std::string* operator->() const { return &mIt->first; }
bool operator!=(const RecursiveDirectoryIterator& other) { return mIt != other.mIt; }
RecursiveDirectoryIterator& operator++()
{
++mIt;
return *this;
}
private: ~Manager();
FileMap::const_iterator mIt;
};
using RecursiveDirectoryRange = IteratorPair<RecursiveDirectoryIterator>;
public:
// Empty the file index and unregister archives. // Empty the file index and unregister archives.
void reset(); void reset();

@ -0,0 +1,53 @@
#ifndef OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#define OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#include <string>
#include "filemap.hpp"
namespace VFS
{
class RecursiveDirectoryIterator
{
public:
RecursiveDirectoryIterator(FileMap::const_iterator it)
: mIt(it)
{
}
const std::string& operator*() const { return mIt->first; }
const std::string* operator->() const { return &mIt->first; }
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
Loading…
Cancel
Save