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