OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
multidircollection.hpp
Go to the documentation of this file.
1 #ifndef COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
2 #define COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
3 
4 #include <map>
5 #include <vector>
6 #include <string>
7 #include <cctype>
8 
9 #include <boost/filesystem/path.hpp>
10 
12 
13 namespace Files
14 {
15  typedef std::vector<boost::filesystem::path> PathContainer;
16 
17  struct NameLess
18  {
19  bool mStrict;
20 
21  NameLess (bool strict) : mStrict (strict) {}
22 
23  bool operator() (const std::string& left, const std::string& right) const
24  {
25  if (mStrict)
26  return left<right;
27 
28  std::size_t min = std::min (left.length(), right.length());
29 
30  for (std::size_t i=0; i<min; ++i)
31  {
32  char l = Misc::StringUtils::toLower (left[i]);
33  char r = Misc::StringUtils::toLower (right[i]);
34 
35  if (l<r)
36  return true;
37  if (l>r)
38  return false;
39  }
40 
41  return left.length()<right.length();
42  }
43  };
44 
51  {
52  public:
53 
54  typedef std::map<std::string, boost::filesystem::path, NameLess> TContainer;
55  typedef TContainer::const_iterator TIter;
56 
57  private:
58 
60 
61  public:
62 
63  MultiDirCollection (const Files::PathContainer& directories,
64  const std::string& extension, bool foldCase);
69 
70  boost::filesystem::path getPath (const std::string& file) const;
75 
76  bool doesExist (const std::string& file) const;
78 
79  TIter begin() const;
81 
82  TIter end() const;
84 
85  };
86 }
87 
88 #endif
File collection across several directories.
Definition: multidircollection.hpp:50
static char toLower(char c)
Definition: stringops.hpp:24
NameLess(bool strict)
Definition: multidircollection.hpp:21
bool doesExist(const std::string &file) const
Definition: multidircollection.cpp:99
TIter begin() const
Return iterator pointing to the first file.
Definition: multidircollection.cpp:104
std::map< std::string, boost::filesystem::path, NameLess > TContainer
Definition: multidircollection.hpp:54
bool operator()(const std::string &left, const std::string &right) const
Definition: multidircollection.hpp:23
TIter end() const
Return iterator pointing past the last file.
Definition: multidircollection.cpp:109
bool mStrict
Definition: multidircollection.hpp:19
TContainer::const_iterator TIter
Definition: multidircollection.hpp:55
boost::filesystem::path getPath(const std::string &file) const
Definition: multidircollection.cpp:89
Definition: multidircollection.hpp:17
TContainer mFiles
Definition: multidircollection.hpp:59
MultiDirCollection(const Files::PathContainer &directories, const std::string &extension, bool foldCase)
Definition: multidircollection.cpp:44
std::vector< boost::filesystem::path > PathContainer
Definition: gamesettings.hpp:14