2011-05-05 17:00:00 +00:00
|
|
|
#ifndef COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
|
|
|
|
#define COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
|
|
|
namespace Files
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
std::size_t min = std::min (left.length(), right.length());
|
|
|
|
|
|
|
|
for (std::size_t i=0; i<min; ++i)
|
|
|
|
{
|
|
|
|
char l = std::tolower (left[i]);
|
|
|
|
char r = std::tolower (right[i]);
|
|
|
|
|
2011-05-05 19:39:52 +00:00
|
|
|
if (l<r)
|
|
|
|
return true;
|
|
|
|
if (l>r)
|
2011-05-05 17:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return left.length()<right.length();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \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:
|
|
|
|
|
|
|
|
typedef std::map<std::string, boost::filesystem::path, NameLess> TContainer;
|
|
|
|
typedef TContainer::const_iterator TIter;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
TContainer mFiles;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MultiDirCollection (const std::vector<boost::filesystem::path>& directories,
|
|
|
|
const std::string& extension, bool foldCase);
|
|
|
|
///< 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
|
|
|
|
|
|
|
|
boost::filesystem::path getPath (const std::string& file) const;
|
|
|
|
///< Return full path (including filename) of \æ file.
|
|
|
|
///
|
|
|
|
/// If the file does not exist, an exception is thrown. \a file must include
|
|
|
|
/// the extension.
|
|
|
|
|
|
|
|
TIter begin() const;
|
|
|
|
///< Return iterator pointing to the first file.
|
|
|
|
|
|
|
|
TIter end() const;
|
|
|
|
///< Return iterator pointing past the last file.
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|