2011-05-05 19:00:00 +02:00
|
|
|
|
|
|
|
#include "collections.hpp"
|
|
|
|
|
|
|
|
namespace Files
|
|
|
|
{
|
2011-08-19 21:06:09 +02:00
|
|
|
Collections::Collections()
|
|
|
|
: mDirectories()
|
|
|
|
, mFoldCase(false)
|
|
|
|
, mCollections()
|
|
|
|
{
|
|
|
|
}
|
2011-05-05 19:00:00 +02:00
|
|
|
|
2011-09-02 22:45:21 +02:00
|
|
|
Collections::Collections(const Files::PathContainer& directories, bool foldCase)
|
2011-08-19 21:06:09 +02:00
|
|
|
: mDirectories(directories)
|
|
|
|
, mFoldCase(foldCase)
|
|
|
|
, mCollections()
|
2011-05-05 19:00:00 +02:00
|
|
|
{
|
2011-08-19 21:06:09 +02:00
|
|
|
}
|
2011-05-05 19:00:00 +02:00
|
|
|
|
2011-08-19 21:06:09 +02:00
|
|
|
const MultiDirCollection& Collections::getCollection(const std::string& extension) const
|
|
|
|
{
|
|
|
|
MultiDirCollectionContainer::iterator iter = mCollections.find(extension);
|
2011-05-05 19:00:00 +02:00
|
|
|
if (iter==mCollections.end())
|
|
|
|
{
|
2011-08-19 21:06:09 +02:00
|
|
|
std::pair<MultiDirCollectionContainer::iterator, bool> result =
|
|
|
|
mCollections.insert(std::make_pair(extension, MultiDirCollection(mDirectories, extension, mFoldCase)));
|
2011-05-05 19:00:00 +02:00
|
|
|
|
|
|
|
iter = result.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
}
|
2012-03-30 14:45:32 +02:00
|
|
|
|
2013-03-09 21:08:08 +01:00
|
|
|
boost::filesystem::path Collections::getPath(const std::string& file) const
|
|
|
|
{
|
|
|
|
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
|
|
|
|
iter != mDirectories.end(); ++iter)
|
|
|
|
{
|
|
|
|
const boost::filesystem::path path = *iter / file;
|
|
|
|
if (boost::filesystem::exists(path))
|
|
|
|
return path.string();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw std::runtime_error ("file " + file + " not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Collections::doesExist(const std::string& file) const
|
|
|
|
{
|
|
|
|
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
|
|
|
|
iter != mDirectories.end(); ++iter)
|
|
|
|
{
|
|
|
|
const boost::filesystem::path path = *iter / file;
|
|
|
|
if (boost::filesystem::exists(path))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-30 14:45:32 +02:00
|
|
|
const Files::PathContainer& Collections::getPaths() const
|
|
|
|
{
|
|
|
|
return mDirectories;
|
|
|
|
}
|
2011-05-05 19:00:00 +02:00
|
|
|
}
|