Use a special name for stdin/stdout in diagnostics

This commit is contained in:
ISSOtm
2022-11-12 12:29:28 +01:00
committed by Eldred Habert
parent 6902387991
commit 3e5cd8ce1a
5 changed files with 41 additions and 21 deletions

View File

@@ -78,6 +78,7 @@ public:
// See the `operator*` equivalent.
return const_cast<File *>(this)->operator->();
}
File *close() {
return std::visit(Visitor{[this](std::filebuf &file) {
// This is called by the destructor, and an explicit `close`
@@ -90,6 +91,14 @@ public:
? this
: nullptr;
}
char const *c_str(std::string const &path) const {
return std::visit(Visitor{[&path](std::filebuf const &) { return path.c_str(); },
[](std::streambuf const *buf) {
return buf == std::cin.rdbuf() ? "<stdin>" : "<stdout>";
}},
_file);
}
};
#endif // RGBDS_FILE_HPP