openMSX
Filename.hh
Go to the documentation of this file.
1#ifndef FILENAME_HH
2#define FILENAME_HH
3
4#include "FileContext.hh"
5#include "FileOperations.hh"
6#include <string>
7
8namespace openmsx {
9
18{
19public:
20 // dummy constructor, to be able to serialize vector<Filename>
21 Filename() = default;
22 Filename(Filename&&) = default;
24 Filename& operator=(const Filename&) = default;
25
26 //workaround msvc bug(?)
27 //Filename(const Filename&) = default;
29 : originalFilename(f.originalFilename)
30 , resolvedFilename(f.resolvedFilename) {}
31
32 // needed because the template below hides this version
33 Filename(Filename& f) : Filename(const_cast<const Filename&>(f)) {}
34
35 template<typename String>
36 explicit Filename(String&& filename)
37 : originalFilename(std::forward<String>(filename))
38 , resolvedFilename(originalFilename) {}
39
40 template<typename String>
42 : originalFilename(std::forward<String>(filename))
43 , resolvedFilename(FileOperations::getAbsolutePath(
44 context.resolve(originalFilename))) {}
45
46 [[nodiscard]] const std::string& getOriginal() const { return originalFilename; }
47 [[nodiscard]] const std::string& getResolved() const & { return resolvedFilename; }
48 [[nodiscard]] std::string getResolved() && { return std::move(resolvedFilename); }
49
56
61 [[nodiscard]] bool empty() const;
62
67 void setResolved(std::string resolved) {
68 resolvedFilename = std::move(resolved);
69 }
70
71 // Do both Filename objects point to the same file?
72 [[nodiscard]] bool operator==(const Filename& other) const {
73 return resolvedFilename == other.resolvedFilename;
74 }
75
76 template<typename Archive>
77 void serialize(Archive& ar, unsigned version);
78
79private:
80 // non-const because we want this class to be assignable
81 // (to be able to store them in std::vector)
82 std::string originalFilename;
83 std::string resolvedFilename;
84};
85
86} // namespace openmsx
87
88#endif
This class represents a filename.
Definition: Filename.hh:18
void setResolved(std::string resolved)
Change the resolved part of this filename E.g.
Definition: Filename.hh:67
Filename()=default
const std::string & getOriginal() const
Definition: Filename.hh:46
Filename(Filename &f)
Definition: Filename.hh:33
bool empty() const
Convenience method to test for empty filename.
Definition: Filename.cc:21
Filename(String &&filename, const FileContext &context)
Definition: Filename.hh:41
Filename(const Filename &f)
Definition: Filename.hh:28
Filename & operator=(const Filename &)=default
void serialize(Archive &ar, unsigned version)
Definition: Filename.cc:28
const std::string & getResolved() const &
Definition: Filename.hh:47
Filename(Filename &&)=default
bool operator==(const Filename &other) const
Definition: Filename.hh:72
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition: Filename.cc:8
Filename(String &&filename)
Definition: Filename.hh:36
std::string getResolved() &&
Definition: Filename.hh:48
Filename & operator=(Filename &&)=default
std::optional< Context > context
Definition: GLContext.cc:9
string getAbsolutePath(string_view path)
Transform given path into an absolute path.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
STL namespace.