13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
104 hxfile(const
char* file_, uint8_t mode_=0) = delete;
118 operator
bool(
void) const;
177#if (HX_USE_FILE_IO) != 2
184 template<
size_t buffer_size_>
186 return this->
getline(buffer_, buffer_size_);
217 template<typename T_>
218 bool read1(T_& t_) {
return this->
read(&t_,
sizeof t_,
sizeof t_) ==
sizeof t_; }
222 template<
typename T_>
223 bool write1(
const T_& t_) {
return this->
write(&t_,
sizeof t_) ==
sizeof t_; }
227 template<
typename T_>
229 this->
read(&t_,
sizeof t_,
sizeof t_);
235 template<
typename T_>
237 this->
write(&t_,
sizeof t_);
244 template<
size_t string_length_>
246 this->
write(str_, string_length_-1);
255 bool openv_(uint8_t mode_,
const char* format_, va_list args_);
257 intptr_t m_file_pimpl_;
258 uint8_t m_open_mode_;
hxfile - Single-ownership C++ RAII abstraction for file I/O.
Definition hxfile.hpp:66
bool fail(void) const
Checks if an error has been encountered, EOF set or set_fail called.
Definition hxfile.hpp:133
void operator=(hxfile &&file_) noexcept
Move assignment. No copy assignment operator is provided.
bool getline(char(&buffer_)[buffer_size_])
Reads a \n or EOF terminated character sequence.
Definition hxfile.hpp:185
int scan(const char *format_,...)
Reads a formatted UTF-8 string from the file.
bool flush(void)
Flushes buffered output to the underlying file.
void close(void)
Closes the currently open file.
bool read1(T &t_)
Reads a single unformatted native-endian object from the file.
Definition hxfile.hpp:218
bool set_pos(size_t position_)
Sets the current position in the file.
hxfile(uint8_t mode_, const char *filename_,...)
Constructs and opens a file with a formatted filename.
hxfile & operator<<(const char(&str_)[string_length_])
Writes a string literal to the file.
Definition hxfile.hpp:245
hxfile & operator>>(T &t_)
Reads a single unformatted native-endian object from a stream.
Definition hxfile.hpp:228
size_t get_pos(void) const
Returns the current position in the file if open, 0 otherwise.
bool is_open(void) const
Checks if the file is open.
bool eof(void) const
Checks if EOF has been reached.
Definition hxfile.hpp:140
size_t read(void *bytes_, size_t buffer_size_, size_t count_)
Reads a specified number of bytes from the file into the provided buffer.
hxfile & operator<<(const T &t_)
Writes a single unformatted native-endian object to a stream.
Definition hxfile.hpp:236
hxfile(void)
Default-constructs as a closed file.
bool print(const char *format_,...)
Writes a formatted UTF-8 string to the file.
open_mode
open_mode - Flags indicating how the file is to be used.
Definition hxfile.hpp:70
@ open_mode_in
Open for binary reading. e.g., "rb".
Definition hxfile.hpp:74
@ open_mode_out
Open for binary writing.
Definition hxfile.hpp:77
@ open_mode_asserts
By default, any unexpected failure is reported only through the failure flag.
Definition hxfile.hpp:82
@ open_mode_none
No flags.
Definition hxfile.hpp:72
bool getline(char *buffer_, int buffer_size_)
Reads a \n or EOF terminated character sequence.
uint8_t mode(void) const
Returns the current open mode of the file.
Definition hxfile.hpp:147
void clear(void)
Resets the failure and EOF flags.
bool write1(const T &t_)
Writes a single unformatted native-endian object to the file.
Definition hxfile.hpp:223
size_t write(const void *bytes_, size_t count_)
Writes a specified number of bytes from the provided buffer to the file.
bool open(uint8_t mode_, const char *filename_,...)
Opens a file with the specified mode and formatted filename.
void set_fail(void)
Marks the file as having encountered a failure.
Definition hxfile.hpp:137
constexpr char hxendl[]
hxendl - Equivalent to std::endl without the flush.
Definition hxfile.hpp:38
hxfile hxin
hxin - Global reference to stdin or equivalent.
hxfile hxerr
hxerr - Global reference to stderr or equivalent.
hxfile hxout
hxout - Global reference to stdout or equivalent.
hxfile hxdev_null
hxdev_null - Global equivalent to /dev/null.
#define hxinline_constexpr
hxinline_constexpr - Enables C++17 compatable "inline constexpr" usage for variables so they can be e...
Definition hxsettings.h:272
#define hxattr_printf(...)
hxattr_printf - Indicates to gcc that a function uses printf-style formatting so it can type-check th...
Definition hxsettings.h:108
#define hxattr_scanf(...)
hxattr_scanf - Indicates to gcc that a function uses scanf-style formatting so it can type-check the ...
Definition hxsettings.h:116
#define hxattr_nonnull(...)
hxattr_nonnull - Indicates that a function has args that should not be null.
Definition hxsettings.h:97
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:89
#define hxattr_hot
hxattr_hot - Optimize a function more aggressively.
Definition hxsettings.h:86
Provides core macros, memory management and feature detection.