|
UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
|
RAII wrapper around a C std::FILE* handle.
More...
#include <lib/io/include/ufo/io/file_handler.hpp>
Public Member Functions | |
| FileHandler ()=default | |
| Constructs an empty (closed) file handler. | |
| FileHandler (FileHandler &&other) noexcept | |
| Move-constructs by transferring ownership of the file handle. | |
| FileHandler (FileHandler const &)=delete | |
Copying a FILE* handle has no meaningful semantics. | |
| FileHandler (std::filesystem::path const &file, std::string_view modes) | |
Opens file in the given modes. | |
| ~FileHandler () | |
| Closes the managed file handle (if open). | |
| void | close () noexcept |
| Closes the managed file handle and resets the pointer to null. | |
| std::FILE * | get () const noexcept |
Returns the underlying FILE*. | |
| void | open (std::filesystem::path const &file, std::string_view modes) |
Closes any currently open file, then opens file in modes. | |
| operator bool () const noexcept | |
Returns true if the file is currently open (handle is non-null). | |
| FileHandler & | operator= (FileHandler &&other) noexcept |
| Move-assigns by closing any currently open file, then taking ownership. | |
| FileHandler & | operator= (FileHandler const &)=delete |
| char * | readline () |
| Reads one line from the file into the internal buffer. | |
Static Public Attributes | |
| static constexpr std::size_t | buffer_size = 1024 |
Maximum number of characters (including the null terminator) read by readline(). | |
RAII wrapper around a C std::FILE* handle.
FileHandler manages the lifetime of a C file pointer obtained via std::fopen, ensuring the file is properly closed when the handler goes out of scope or is reassigned. It is move-only — copying a FILE* has no meaningful semantics.
A fixed-size internal buffer supports line-by-line reading via readline().
Definition at line 72 of file file_handler.hpp.
| ufo::FileHandler::FileHandler | ( | std::filesystem::path const & | file, |
| std::string_view | modes | ||
| ) |
Opens file in the given modes.
| file | Path to the file to open. |
| modes | Null-terminated fopen mode string (e.g. "r", "wb"). |
Definition at line 51 of file file_handler.cpp.
|
noexcept |
Move-constructs by transferring ownership of the file handle.
other is left in the closed (null) state. Definition at line 56 of file file_handler.cpp.
| ufo::FileHandler::~FileHandler | ( | ) |
Closes the managed file handle (if open).
Definition at line 70 of file file_handler.cpp.
|
noexcept |
Closes the managed file handle and resets the pointer to null.
No-op if the handle is already closed.
Definition at line 78 of file file_handler.cpp.
|
noexcept |
Returns the underlying FILE*.
nullptr if not open. Definition at line 86 of file file_handler.cpp.
| void ufo::FileHandler::open | ( | std::filesystem::path const & | file, |
| std::string_view | modes | ||
| ) |
Closes any currently open file, then opens file in modes.
| file | Path to the file to open. |
| modes | Null-terminated fopen mode string (e.g. "r", "wb"). |
Definition at line 72 of file file_handler.cpp.
|
explicitnoexcept |
Returns true if the file is currently open (handle is non-null).
Definition at line 93 of file file_handler.cpp.
|
noexcept |
Move-assigns by closing any currently open file, then taking ownership.
Self-assignment is handled safely.
other is left in the closed (null) state. Definition at line 61 of file file_handler.cpp.
| char * ufo::FileHandler::readline | ( | ) |
Reads one line from the file into the internal buffer.
Wraps std::fgets. Reads at most buffer_size - 1 characters (plus a null terminator). The newline character, if present, is retained in the buffer.
nullptr at EOF or on error. The returned pointer is valid until the next call to readline() or until the handler is destroyed / closed. Definition at line 88 of file file_handler.cpp.
|
staticconstexpr |
Maximum number of characters (including the null terminator) read by readline().
Definition at line 76 of file file_handler.hpp.