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
7#include <concepts>
8#include <string>
9
10namespace openmsx {
11
20{
21public:
22 // dummy constructor, to be able to serialize vector<Filename>
23 Filename() = default;
24
25 template<typename String>
26 requires(!std::same_as<Filename, std::remove_cvref_t<String>>) // don't block copy-constructor
27 explicit Filename(String&& filename)
28 : originalFilename(std::forward<String>(filename))
29 , resolvedFilename(originalFilename) {}
30
31 template<typename String>
32 Filename(String&& filename, const FileContext& context)
33 : originalFilename(std::forward<String>(filename))
34 , resolvedFilename(FileOperations::getAbsolutePath(
35 context.resolve(originalFilename))) {}
36
37 [[nodiscard]] const std::string& getOriginal() const { return originalFilename; }
38 [[nodiscard]] const std::string& getResolved() const & { return resolvedFilename; }
39 [[nodiscard]] std::string getResolved() && { return std::move(resolvedFilename); }
40
47
52 [[nodiscard]] bool empty() const;
53
58 void setResolved(std::string resolved) {
59 resolvedFilename = std::move(resolved);
60 }
61
62 // Do both Filename objects point to the same file?
63 [[nodiscard]] bool operator==(const Filename& other) const {
64 return resolvedFilename == other.resolvedFilename;
65 }
66
67 template<typename Archive>
68 void serialize(Archive& ar, unsigned version);
69
70private:
71 // non-const because we want this class to be assignable
72 // (to be able to store them in std::vector)
73 std::string originalFilename;
74 std::string resolvedFilename;
75};
76
77} // namespace openmsx
78
79#endif
This class represents a filename.
Definition Filename.hh:20
void setResolved(std::string resolved)
Change the resolved part of this filename E.g.
Definition Filename.hh:58
Filename()=default
const std::string & getOriginal() const
Definition Filename.hh:37
bool empty() const
Convenience method to test for empty filename.
Definition Filename.cc:21
Filename(String &&filename, const FileContext &context)
Definition Filename.hh:32
void serialize(Archive &ar, unsigned version)
Definition Filename.cc:28
const std::string & getResolved() const &
Definition Filename.hh:38
bool operator==(const Filename &other) const
Definition Filename.hh:63
Filename(String &&filename)
Definition Filename.hh:27
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition Filename.cc:8
std::string getResolved() &&
Definition Filename.hh:39
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.