File: fixedpath.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (113 lines) | stat: -rw-r--r-- 3,267 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef COMPONENTS_FILES_FIXEDPATH_HPP
#define COMPONENTS_FILES_FIXEDPATH_HPP

#include <filesystem>
#include <string>

#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#ifndef ANDROID
#include <components/files/linuxpath.hpp>
namespace Files
{
    typedef LinuxPath TargetPathType;
}
#else
#include <components/files/androidpath.hpp>
namespace Files
{
    typedef AndroidPath TargetPathType;
}
#endif
#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WIN32)
#include <components/files/windowspath.hpp>
namespace Files
{
    typedef WindowsPath TargetPathType;
}

#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <components/files/macospath.hpp>
namespace Files
{
    typedef MacOsPath TargetPathType;
}

#else
#error "Unknown platform!"
#endif

/**
 * \namespace Files
 */
namespace Files
{

    /**
     * \struct Path
     *
     * \tparam P - Path strategy class type (depends on target system)
     *
     */
    template <class P = TargetPathType>
    struct FixedPath
    {
        typedef P PathType;

        /**
         * \brief Path constructor.
         *
         * \param [in] application_name - Name of the application
         */
        FixedPath(const std::string& application_name)
            : mPath(application_name + "/")
            , mUserConfigPath(mPath.getUserConfigPath())
            , mUserDataPath(mPath.getUserDataPath())
            , mGlobalConfigPath(mPath.getGlobalConfigPath())
            , mLocalPath(mPath.getLocalPath())
            , mGlobalDataPath(mPath.getGlobalDataPath())
            , mCachePath(mPath.getCachePath())
            , mInstallPath(mPath.getInstallPath())
        {
        }

        /**
         * \brief Return path pointing to the user local configuration directory.
         */
        const std::filesystem::path& getUserConfigPath() const { return mUserConfigPath; }

        const std::filesystem::path& getUserDataPath() const { return mUserDataPath; }

        /**
         * \brief Return path pointing to the global (system) configuration directory.
         */
        const std::filesystem::path& getGlobalConfigPath() const { return mGlobalConfigPath; }

        /**
         * \brief Return path pointing to the directory where application was started.
         */
        const std::filesystem::path& getLocalPath() const { return mLocalPath; }

        const std::filesystem::path& getInstallPath() const { return mInstallPath; }

        const std::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; }

        const std::filesystem::path& getCachePath() const { return mCachePath; }

    private:
        PathType mPath;

        std::filesystem::path mUserConfigPath; /**< User path  */
        std::filesystem::path mUserDataPath;
        std::filesystem::path mGlobalConfigPath; /**< Global path */
        std::filesystem::path mLocalPath; /**< It is the same directory where application was run */

        std::filesystem::path mGlobalDataPath; /**< Global application data path */

        std::filesystem::path mCachePath;

        std::filesystem::path mInstallPath;
    };

} /* namespace Files */

#endif /* COMPONENTS_FILES_FIXEDPATH_HPP */