UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
file_handler.cpp
1
42// UFO
43#include <ufo/io/file_handler.hpp>
44
45// STL
46#include <string>
47#include <utility>
48
49namespace ufo
50{
51FileHandler::FileHandler(std::filesystem::path const& file, std::string_view modes)
52 : fp_(std::fopen(file.c_str(), std::string(modes).c_str()))
53{
54}
55
57 : fp_(std::exchange(other.fp_, nullptr))
58{
59}
60
61FileHandler& FileHandler::operator=(FileHandler&& other) noexcept
62{
63 if (this != &other) {
64 close();
65 fp_ = std::exchange(other.fp_, nullptr);
66 }
67 return *this;
68}
69
71
72void FileHandler::open(std::filesystem::path const& file, std::string_view modes)
73{
74 close();
75 fp_ = std::fopen(file.c_str(), std::string(modes).c_str());
76}
77
78void FileHandler::close() noexcept
79{
80 if (nullptr != fp_) {
81 std::fclose(fp_);
82 fp_ = nullptr;
83 }
84}
85
86std::FILE* FileHandler::get() const noexcept { return fp_; }
87
89{
90 return std::fgets(buffer_.data(), static_cast<int>(buffer_size), fp_);
91}
92
93FileHandler::operator bool() const noexcept { return nullptr != fp_; }
94} // namespace ufo
RAII wrapper around a C std::FILE* handle.
std::FILE * get() const noexcept
Returns the underlying FILE*.
static constexpr std::size_t buffer_size
Maximum number of characters (including the null terminator) read by readline().
void open(std::filesystem::path const &file, std::string_view modes)
Closes any currently open file, then opens file in modes.
char * readline()
Reads one line from the file into the internal buffer.
void close() noexcept
Closes the managed file handle and resets the pointer to null.
FileHandler()=default
Constructs an empty (closed) file handler.
~FileHandler()
Closes the managed file handle (if open).
STL namespace.
All vision-related classes and functions.
Definition cloud.hpp:49