openMSX
FileContext.hh
Go to the documentation of this file.
1 #ifndef FILECONTEXT_HH
2 #define FILECONTEXT_HH
3 
4 #include <string>
5 #include <string_view>
6 #include <vector>
7 
8 namespace openmsx {
9 
10 class FileContext final
11 {
12 public:
13  FileContext() = default;
14  FileContext(std::vector<std::string>&& paths,
15  std::vector<std::string>&& savePaths);
16 
17  [[nodiscard]] std::string resolve (std::string_view filename) const;
18  [[nodiscard]] std::string resolveCreate(std::string_view filename) const;
19 
20  [[nodiscard]] const std::vector<std::string>& getPaths() const;
21  [[nodiscard]] bool isUserContext() const;
22 
23  template<typename Archive>
24  void serialize(Archive& ar, unsigned version);
25 
26 private:
27  std::vector<std::string> paths;
28  mutable std::vector<std::string> paths2; // calculated from paths
29  std::vector<std::string> savePaths;
30  mutable std::vector<std::string> savePaths2; // calc from savePaths
31 };
32 
33 [[nodiscard]] FileContext configFileContext(std::string_view path, std::string_view hwDescr, std::string_view userName);
34 [[nodiscard]] FileContext userDataFileContext(std::string_view subdir);
35 [[nodiscard]] FileContext userFileContext(std::string_view savePath);
36 [[nodiscard]] const FileContext& userFileContext();
37 [[nodiscard]] const FileContext& systemFileContext();
38 [[nodiscard]] const FileContext& preferSystemFileContext();
39 [[nodiscard]] const FileContext& currentDirFileContext();
40 
41 } // namespace openmsx
42 
43 #endif
void serialize(Archive &ar, unsigned version)
Definition: FileContext.cc:123
std::string resolveCreate(std::string_view filename) const
Definition: FileContext.cc:87
bool isUserContext() const
Definition: FileContext.cc:117
const std::vector< std::string > & getPaths() const
Definition: FileContext.cc:109
std::string resolve(std::string_view filename) const
Definition: FileContext.cc:80
This file implemented 3 utility functions:
Definition: Autofire.cc:5
const FileContext & systemFileContext()
Definition: FileContext.cc:156
FileContext configFileContext(string_view path, string_view hwDescr, string_view userName)
Definition: FileContext.cc:150
const FileContext & currentDirFileContext()
Definition: FileContext.cc:190
constexpr const char *const filename
FileContext userFileContext(string_view savePath)
Definition: FileContext.cc:172
FileContext userDataFileContext(string_view subDir)
Definition: FileContext.cc:184
const FileContext & preferSystemFileContext()
Definition: FileContext.cc:164