Apply clang-format to code base

This commit is contained in:
clang-format-bot 2022-09-22 21:26:05 +03:00 committed by ζeh Matt
parent f37d0be806
commit ddb0522bbf
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0
2199 changed files with 118692 additions and 114392 deletions

View file

@ -1,8 +1,8 @@
#ifndef OPENMW_COMPONENTS_RESOURCE_ARCHIVE_H
#define OPENMW_COMPONENTS_RESOURCE_ARCHIVE_H
#include <map>
#include <filesystem>
#include <map>
#include <components/files/istreamptr.hpp>
@ -24,11 +24,12 @@ namespace VFS
public:
virtual ~Archive() {}
/// List all resources contained in this archive, and run the resource names through the given normalize function.
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) = 0;
/// List all resources contained in this archive, and run the resource names through the given normalize
/// function.
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function)(char)) = 0;
/// True if this archive contains the provided normalized file.
virtual bool contains(const std::string& file, char (*normalize_function) (char)) const = 0;
virtual bool contains(const std::string& file, char (*normalize_function)(char)) const = 0;
virtual std::string getDescription() const = 0;
};

View file

@ -1,125 +1,121 @@
#include "bsaarchive.hpp"
#include <memory>
#include <algorithm>
#include <istream>
#include <memory>
namespace VFS
{
BsaArchive::BsaArchive(const std::filesystem::path &filename)
{
mFile = std::make_unique<Bsa::BSAFile>();
mFile->open(filename);
const Bsa::BSAFile::FileList &filelist = mFile->getList();
for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it)
BsaArchive::BsaArchive(const std::filesystem::path& filename)
{
mResources.emplace_back(&*it, mFile.get());
mFile = std::make_unique<Bsa::BSAFile>();
mFile->open(filename);
const Bsa::BSAFile::FileList& filelist = mFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
{
mResources.emplace_back(&*it, mFile.get());
}
}
}
BsaArchive::BsaArchive()
{
}
BsaArchive::BsaArchive() {}
BsaArchive::~BsaArchive() {
}
BsaArchive::~BsaArchive() {}
void BsaArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
{
for (std::vector<BsaArchiveFile>::iterator it = mResources.begin(); it != mResources.end(); ++it)
void BsaArchive::listResources(std::map<std::string, File*>& out, char (*normalize_function)(char))
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
for (std::vector<BsaArchiveFile>::iterator it = mResources.begin(); it != mResources.end(); ++it)
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
out[ent] = &*it;
out[ent] = &*it;
}
}
}
bool BsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
for (const auto& it : mResources)
bool BsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
std::string ent = it.mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if(file == ent)
return true;
for (const auto& it : mResources)
{
std::string ent = it.mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if (file == ent)
return true;
}
return false;
}
return false;
}
std::string BsaArchive::getDescription() const
{
return std::string{"BSA: "} + mFile->getFilename();
}
// ------------------------------------------------------------------------------
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::BSAFile* bsa)
: mInfo(info)
, mFile(bsa)
{
}
Files::IStreamPtr BsaArchiveFile::open()
{
return mFile->getFile(mInfo);
}
CompressedBsaArchive::CompressedBsaArchive(const std::filesystem::path &filename)
: Archive()
{
mCompressedFile = std::make_unique<Bsa::CompressedBSAFile>();
mCompressedFile->open(filename);
const Bsa::BSAFile::FileList &filelist = mCompressedFile->getList();
for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it)
std::string BsaArchive::getDescription() const
{
mCompressedResources.emplace_back(&*it, mCompressedFile.get());
return std::string{ "BSA: " } + mFile->getFilename();
}
}
void CompressedBsaArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
{
for (std::vector<CompressedBsaArchiveFile>::iterator it = mCompressedResources.begin(); it != mCompressedResources.end(); ++it)
// ------------------------------------------------------------------------------
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct* info, Bsa::BSAFile* bsa)
: mInfo(info)
, mFile(bsa)
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
out[ent] = &*it;
}
}
bool CompressedBsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
for (const auto& it : mCompressedResources)
Files::IStreamPtr BsaArchiveFile::open()
{
std::string ent = it.mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if(file == ent)
return true;
return mFile->getFile(mInfo);
}
return false;
}
std::string CompressedBsaArchive::getDescription() const
{
return std::string{"BSA: "} + mCompressedFile->getFilename();
}
CompressedBsaArchive::CompressedBsaArchive(const std::filesystem::path& filename)
: Archive()
{
mCompressedFile = std::make_unique<Bsa::CompressedBSAFile>();
mCompressedFile->open(filename);
const Bsa::BSAFile::FileList& filelist = mCompressedFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
{
mCompressedResources.emplace_back(&*it, mCompressedFile.get());
}
}
CompressedBsaArchiveFile::CompressedBsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::CompressedBSAFile* bsa)
: mInfo(info)
, mCompressedFile(bsa)
{
}
Files::IStreamPtr CompressedBsaArchiveFile::open()
{
return mCompressedFile->getFile(mInfo);
}
void CompressedBsaArchive::listResources(std::map<std::string, File*>& out, char (*normalize_function)(char))
{
for (std::vector<CompressedBsaArchiveFile>::iterator it = mCompressedResources.begin();
it != mCompressedResources.end(); ++it)
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
out[ent] = &*it;
}
}
bool CompressedBsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
for (const auto& it : mCompressedResources)
{
std::string ent = it.mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if (file == ent)
return true;
}
return false;
}
std::string CompressedBsaArchive::getDescription() const
{
return std::string{ "BSA: " } + mCompressedFile->getFilename();
}
CompressedBsaArchiveFile::CompressedBsaArchiveFile(
const Bsa::BSAFile::FileStruct* info, Bsa::CompressedBSAFile* bsa)
: mInfo(info)
, mCompressedFile(bsa)
{
}
Files::IStreamPtr CompressedBsaArchiveFile::open()
{
return mCompressedFile->getFile(mInfo);
}
}

View file

@ -34,15 +34,14 @@ namespace VFS
Bsa::CompressedBSAFile* mCompressedFile;
};
class BsaArchive : public Archive
{
public:
BsaArchive(const std::filesystem::path &filename);
BsaArchive(const std::filesystem::path& filename);
BsaArchive();
virtual ~BsaArchive();
void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) override;
bool contains(const std::string& file, char (*normalize_function) (char)) const override;
void listResources(std::map<std::string, File*>& out, char (*normalize_function)(char)) override;
bool contains(const std::string& file, char (*normalize_function)(char)) const override;
std::string getDescription() const override;
protected:
@ -53,10 +52,10 @@ namespace VFS
class CompressedBsaArchive : public Archive
{
public:
CompressedBsaArchive(const std::filesystem::path &filename);
CompressedBsaArchive(const std::filesystem::path& filename);
virtual ~CompressedBsaArchive() {}
void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) override;
bool contains(const std::string& file, char (*normalize_function) (char)) const override;
void listResources(std::map<std::string, File*>& out, char (*normalize_function)(char)) override;
bool contains(const std::string& file, char (*normalize_function)(char)) const override;
std::string getDescription() const override;
private:

View file

@ -11,41 +11,42 @@
namespace VFS
{
FileSystemArchive::FileSystemArchive(const std::filesystem::path &path)
FileSystemArchive::FileSystemArchive(const std::filesystem::path& path)
: mBuiltIndex(false)
, mPath(path)
{
}
void FileSystemArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
void FileSystemArchive::listResources(std::map<std::string, File*>& out, char (*normalize_function)(char))
{
if (!mBuiltIndex)
{
const auto str = mPath.u8string();
size_t prefix = str.size ();
size_t prefix = str.size();
if (!mPath.empty() && str [prefix - 1] != '\\' && str [prefix - 1] != '/')
if (!mPath.empty() && str[prefix - 1] != '\\' && str[prefix - 1] != '/')
++prefix;
for (const auto& i :
std::filesystem::recursive_directory_iterator(mPath))
for (const auto& i : std::filesystem::recursive_directory_iterator(mPath))
{
if(std::filesystem::is_directory (i))
if (std::filesystem::is_directory(i))
continue;
const auto& path = i.path ();
const auto& path = i.path();
const auto& proper = Files::pathToUnicodeString(path);
FileSystemArchiveFile file(path);
std::string searchable;
std::transform(std::next(proper.begin(), static_cast<std::string::difference_type>(prefix)), proper.end(), std::back_inserter(searchable), normalize_function);
std::transform(std::next(proper.begin(), static_cast<std::string::difference_type>(prefix)),
proper.end(), std::back_inserter(searchable), normalize_function);
const auto inserted = mIndex.insert(std::make_pair(searchable, file));
if (!inserted.second)
Log(Debug::Warning) << "Warning: found duplicate file for '" << proper << "', please check your file system for two files with the same name in different cases.";
Log(Debug::Warning)
<< "Warning: found duplicate file for '" << proper
<< "', please check your file system for two files with the same name in different cases.";
else
out[inserted.first->first] = &inserted.first->second;
}
@ -72,7 +73,7 @@ namespace VFS
// ----------------------------------------------------------------------------------
FileSystemArchiveFile::FileSystemArchiveFile(const std::filesystem::path &path)
FileSystemArchiveFile::FileSystemArchiveFile(const std::filesystem::path& path)
: mPath(path)
{
}

View file

@ -1,8 +1,8 @@
#ifndef OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H
#define OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H
#include <filesystem>
#include "archive.hpp"
#include <filesystem>
#include <string>
@ -12,7 +12,7 @@ namespace VFS
class FileSystemArchiveFile : public File
{
public:
FileSystemArchiveFile(const std::filesystem::path &path);
FileSystemArchiveFile(const std::filesystem::path& path);
Files::IStreamPtr open() override;
@ -20,27 +20,25 @@ namespace VFS
private:
std::filesystem::path mPath;
};
class FileSystemArchive : public Archive
{
public:
FileSystemArchive(const std::filesystem::path &path);
FileSystemArchive(const std::filesystem::path& path);
void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) override;
void listResources(std::map<std::string, File*>& out, char (*normalize_function)(char)) override;
bool contains(const std::string& file, char (*normalize_function) (char)) const override;
bool contains(const std::string& file, char (*normalize_function)(char)) const override;
std::string getDescription() const override;
private:
typedef std::map <std::string, FileSystemArchiveFile> index;
typedef std::map<std::string, FileSystemArchiveFile> index;
index mIndex;
bool mBuiltIndex;
std::filesystem::path mPath;
};
}

View file

@ -1,12 +1,12 @@
#include "manager.hpp"
#include <stdexcept>
#include <istream>
#include <algorithm>
#include <istream>
#include <stdexcept>
#include <components/misc/strings/lower.hpp>
#include <components/files/configurationmanager.hpp>
#include <components/files/conversion.hpp>
#include <components/misc/strings/lower.hpp>
#include "archive.hpp"
@ -37,7 +37,6 @@ namespace VFS
Manager::Manager(bool strict)
: mStrict(strict)
{
}
Manager::~Manager() {}
@ -69,7 +68,7 @@ namespace VFS
return getNormalized(normalized);
}
Files::IStreamPtr Manager::getNormalized(const std::string &normalizedName) const
Files::IStreamPtr Manager::getNormalized(const std::string& normalizedName) const
{
std::map<std::string, File*>::const_iterator found = mIndex.find(normalizedName);
if (found == mIndex.end())
@ -96,15 +95,15 @@ namespace VFS
{
std::string normalized(name);
normalize_path(normalized, mStrict);
for(auto it = mArchives.rbegin(); it != mArchives.rend(); ++it)
for (auto it = mArchives.rbegin(); it != mArchives.rend(); ++it)
{
if((*it)->contains(normalized, mStrict ? &strict_normalize_char : &nonstrict_normalize_char))
if ((*it)->contains(normalized, mStrict ? &strict_normalize_char : &nonstrict_normalize_char))
return (*it)->getDescription();
}
return {};
}
std::filesystem::path Manager::getAbsoluteFileName(const std::filesystem::path &name) const
std::filesystem::path Manager::getAbsoluteFileName(const std::filesystem::path& name) const
{
std::string normalized = Files::pathToUnicodeString(name);
normalize_path(normalized, mStrict);

View file

@ -3,11 +3,11 @@
#include <components/files/istreamptr.hpp>
#include <vector>
#include <filesystem>
#include <map>
#include <memory>
#include <string>
#include <filesystem>
#include <vector>
namespace VFS
{
@ -19,7 +19,11 @@ namespace VFS
class IteratorPair
{
public:
IteratorPair(Iterator first, Iterator last) : mFirst(first), mLast(last) {}
IteratorPair(Iterator first, Iterator last)
: mFirst(first)
, mLast(last)
{
}
Iterator begin() const { return mFirst; }
Iterator end() const { return mLast; }
@ -38,11 +42,18 @@ namespace VFS
class RecursiveDirectoryIterator
{
public:
RecursiveDirectoryIterator(std::map<std::string, File*>::const_iterator it) : mIt(it) {}
RecursiveDirectoryIterator(std::map<std::string, File*>::const_iterator it)
: 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; }
RecursiveDirectoryIterator& operator++()
{
++mIt;
return *this;
}
private:
std::map<std::string, File*>::const_iterator mIt;
@ -60,7 +71,8 @@ namespace VFS
// Empty the file index and unregister archives.
void reset();
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex() call.
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex()
/// call.
void addArchive(std::unique_ptr<Archive>&& archive);
/// Build the file index. Should be called when all archives have been registered.
@ -95,7 +107,7 @@ namespace VFS
/// Retrieve the absolute path to the file
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
std::filesystem::path getAbsoluteFileName(const std::filesystem::path &name) const;
std::filesystem::path getAbsoluteFileName(const std::filesystem::path& name) const;
private:
bool mStrict;

View file

@ -1,19 +1,20 @@
#include "registerarchives.hpp"
#include <set>
#include <filesystem>
#include <set>
#include <stdexcept>
#include <components/debug/debuglog.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/bsaarchive.hpp>
#include <components/vfs/filesystemarchive.hpp>
#include <components/vfs/manager.hpp>
namespace VFS
{
void registerArchives(VFS::Manager *vfs, const Files::Collections &collections, const std::vector<std::string> &archives, bool useLooseFiles)
void registerArchives(VFS::Manager* vfs, const Files::Collections& collections,
const std::vector<std::string>& archives, bool useLooseFiles)
{
const Files::PathContainer& dataDirs = collections.getPaths();
@ -40,7 +41,7 @@ namespace VFS
if (useLooseFiles)
{
std::set<std::filesystem::path> seen;
for (const auto &dataDir : dataDirs)
for (const auto& dataDir : dataDirs)
{
if (seen.insert(dataDir).second)
{

View file

@ -8,7 +8,7 @@ namespace VFS
class Manager;
/// @brief Register BSA and file system archives based on the given OpenMW configuration.
void registerArchives (VFS::Manager* vfs, const Files::Collections& collections,
void registerArchives(VFS::Manager* vfs, const Files::Collections& collections,
const std::vector<std::string>& archives, bool useLooseFiles);
}