openMSX
Filename.cc
Go to the documentation of this file.
1 #include "Filename.hh"
2 #include "MSXException.hh"
3 #include "serialize.hh"
4 #include <cassert>
5 
6 using std::string;
7 
8 namespace openmsx {
9 
11 {
12  if (empty()) return;
13  if (FileOperations::exists(resolvedFilename)) return;
14 
15  try {
16  resolvedFilename = FileOperations::getAbsolutePath(
17  userFileContext().resolve(originalFilename));
18  } catch (MSXException&) {
19  // nothing
20  }
21 }
22 
23 bool Filename::empty() const
24 {
25  assert(getOriginal().empty() == getResolved().empty());
26  return getOriginal().empty();
27 }
28 
29 template<typename Archive>
30 void Filename::serialize(Archive& ar, unsigned /*version*/)
31 {
32  ar.serialize("original", originalFilename,
33  "resolved", resolvedFilename);
34 }
36 
37 } // namespace openmsx
This class represents a filename.
Definition: Filename.hh:18
bool empty() const
Convenience method to test for empty filename.
Definition: Filename.cc:23
void serialize(Archive &ar, unsigned version)
Definition: Filename.cc:30
const std::string & getResolved() const &
Definition: Filename.hh:47
const std::string & getOriginal() const
Definition: Filename.hh:46
void updateAfterLoadState()
After a loadstate we prefer to use the exact same file as before savestate.
Definition: Filename.cc:10
bool exists(zstring_view filename)
Does this file (directory) exists?
string getAbsolutePath(string_view path)
Transform given path into an absolute path.
This file implemented 3 utility functions:
Definition: Autofire.cc:5
FileContext userFileContext(string_view savePath)
Definition: FileContext.cc:172
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983