2011-05-05 17:00:00 +00:00
|
|
|
#ifndef COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
|
|
|
|
#define COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
|
|
|
|
|
2011-06-01 03:55:08 +00:00
|
|
|
#include <cctype>
|
2022-06-08 21:25:50 +00:00
|
|
|
#include <filesystem>
|
2011-05-05 17:00:00 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
2015-12-07 20:58:30 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
namespace Files
|
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
typedef std::vector<std::filesystem::path> PathContainer;
|
2011-09-02 20:45:21 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
struct NameLess
|
|
|
|
{
|
|
|
|
bool mStrict;
|
|
|
|
|
|
|
|
NameLess(bool strict)
|
|
|
|
: mStrict(strict)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator()(const std::string& left, const std::string& right) const
|
|
|
|
{
|
|
|
|
if (mStrict)
|
|
|
|
return left < right;
|
2022-06-01 20:09:13 +00:00
|
|
|
return Misc::StringUtils::ciLess(left, right);
|
2011-05-05 17:00:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief File collection across several directories
|
|
|
|
///
|
|
|
|
/// This class lists all files with one specific extensions within one or more
|
|
|
|
/// directories. If the same file appears more than once, the file in the directory
|
|
|
|
/// with the higher priority is used.
|
|
|
|
class MultiDirCollection
|
|
|
|
{
|
|
|
|
public:
|
2022-06-08 21:25:50 +00:00
|
|
|
typedef std::map<std::string, std::filesystem::path, NameLess> TContainer;
|
2011-05-05 17:00:00 +00:00
|
|
|
typedef TContainer::const_iterator TIter;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
private:
|
|
|
|
TContainer mFiles;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
public:
|
2011-09-02 20:45:21 +00:00
|
|
|
MultiDirCollection(const Files::PathContainer& directories, const std::string& extension, bool foldCase);
|
2011-05-05 17:00:00 +00:00
|
|
|
///< Directories are listed with increasing priority.
|
|
|
|
/// \param extension The extension that should be listed in this collection. Must
|
|
|
|
/// contain the leading dot.
|
|
|
|
/// \param foldCase Ignore filename case
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path getPath(const std::string& file) const;
|
2012-01-29 19:27:03 +00:00
|
|
|
///< Return full path (including filename) of \a file.
|
2011-05-05 17:00:00 +00:00
|
|
|
///
|
|
|
|
/// If the file does not exist, an exception is thrown. \a file must include
|
|
|
|
/// the extension.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2012-12-26 16:15:53 +00:00
|
|
|
bool doesExist(const std::string& file) const;
|
|
|
|
///< \return Does a file with the given name exist?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
TIter begin() const;
|
|
|
|
///< Return iterator pointing to the first file.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2011-05-05 17:00:00 +00:00
|
|
|
TIter end() const;
|
|
|
|
///< Return iterator pointing past the last file.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|