Skip to content

Commit 80f0d49

Browse files
authored
Breaking: Remove file::rdbuf (#173)
`file` (which extends `std::iostream`) still provides `rdbuf() -> std::streambuf` which can be used for lower level I/O `std::filebuf` (and `tmp::filebuf`) only provides `open`, `is_open` and `close` methods: - `open` - we don't want the user to be able to reopen another file from the temporary file - `close` - we don't want `file` to exist in a closed state - `is_open` - will only return `false` for relocated `file` objects
1 parent 462aeec commit 80f0d49

File tree

3 files changed

+2
-9
lines changed

3 files changed

+2
-9
lines changed

include/tmp/file

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public:
6868
/// @returns The underlying implementation-defined handle
6969
native_handle_type native_handle() const noexcept;
7070

71-
/// Returns pointer to the underlying raw file device object
72-
/// @returns A pointer to the underlying raw file device
73-
std::filebuf* rdbuf() const noexcept;
74-
7571
/// Moves the managed file to a given target, releasing
7672
/// ownership of the managed file; behaves like `std::filesystem::rename`
7773
/// even when moving between filesystems

src/file.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ file::native_handle_type file::native_handle() const noexcept {
3939
return sb.native_handle();
4040
}
4141

42-
std::filebuf* file::rdbuf() const noexcept {
43-
return const_cast<filebuf*>(std::addressof(sb)); // NOLINT(*-const-cast)
44-
}
45-
4642
void file::move(const fs::path& to) {
4743
sb.close();
4844

tests/file.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace fs = std::filesystem;
2323

2424
/// Returns whether the underlying raw file device object is open
2525
bool is_open(const file& file) {
26-
return file.rdbuf()->is_open();
26+
std::filebuf* filebuf = dynamic_cast<std::filebuf*>(file.rdbuf());
27+
return filebuf != nullptr && filebuf->is_open();
2728
}
2829

2930
/// Checks if the given file handle is valid

0 commit comments

Comments
 (0)