File: multidircollection.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (54 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
#define COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP

#include <cctype>
#include <filesystem>
#include <map>
#include <string>
#include <vector>

#include <components/misc/strings/algorithm.hpp>

namespace Files
{
    typedef std::vector<std::filesystem::path> PathContainer;

    /// \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, std::filesystem::path, Misc::StringUtils::CiComp> TContainer;
        typedef TContainer::const_iterator TIter;

    private:
        TContainer mFiles;

    public:
        MultiDirCollection(const Files::PathContainer& directories, const std::string& extension);
        ///< 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

        std::filesystem::path getPath(const std::string& file) const;
        ///< Return full path (including filename) of \a file.
        ///
        /// If the file does not exist, an exception is thrown. \a file must include
        /// the extension.

        bool doesExist(const std::string& file) const;
        ///< \return Does a file with the given name exist?

        TIter begin() const;
        ///< Return iterator pointing to the first file.

        TIter end() const;
        ///< Return iterator pointing past the last file.
    };
}

#endif