UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
file_handler.hpp
1
42#ifndef UFO_IO_FILE_HANDLER_HPP
43#define UFO_IO_FILE_HANDLER_HPP
44
45// STL
46#include <array>
47#include <cstddef>
48#include <cstdio>
49#include <filesystem>
50#include <string_view>
51
52namespace ufo
53{
73{
74 public:
76 static constexpr std::size_t buffer_size = 1024;
77
79 FileHandler() = default;
80
87 FileHandler(std::filesystem::path const& file, std::string_view modes);
88
90 FileHandler(FileHandler const&) = delete;
91 FileHandler& operator=(FileHandler const&) = delete;
92
98 FileHandler(FileHandler&& other) noexcept;
99
107 FileHandler& operator=(FileHandler&& other) noexcept;
108
110 ~FileHandler();
111
118 void open(std::filesystem::path const& file, std::string_view modes);
119
125 void close() noexcept;
126
132 [[nodiscard]] std::FILE* get() const noexcept;
133
144 [[nodiscard]] char* readline();
145
149 [[nodiscard]] explicit operator bool() const noexcept;
150
151 private:
152 std::FILE* fp_ = nullptr;
153 std::array<char, buffer_size> buffer_;
154};
155} // namespace ufo
156
157#endif // UFO_IO_FILE_HANDLER_HPP
RAII wrapper around a C std::FILE* handle.
std::FILE * get() const noexcept
Returns the underlying FILE*.
FileHandler(FileHandler const &)=delete
Copying a FILE* handle has no meaningful semantics.
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