13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
19#if HX_CPLUSPLUS >= 202302L
110 hxfile(const
char* file_, uint8_t mode_=0) = delete;
124 operator
bool(
void) const;
196 template<typename T_>
199#if HX_CPLUSPLUS >= 202302L
202 template<
typename T_>
205 const bool error_ = this->
read(&t_,
sizeof(T_),
sizeof(T_)) !=
sizeof(T_);
212 template<
typename T_>
217 template<
typename T_>
219 this->
read(&t_,
sizeof t_,
sizeof t_);
225 template<
typename T_>
227 this->
write(&t_,
sizeof t_);
234 template<
size_t string_length_>
236 this->
write(str_, string_length_-1);
245 bool openv_(uint8_t mode_,
const char* format_, va_list args_);
247 intptr_t m_file_pimpl_;
248 uint8_t m_open_mode_;
hxexpected<T, E=bool> - Holds either a value of type T or an error of type E.
Definition hxexpected.hpp:67
hxfile - Single-ownership C++ RAII abstraction for file I/O.
Definition hxfile.hpp:70
hxexpected< T > expect(void)
Reads a single unformatted native-endian object from the file, returning it or an error if the read f...
Definition hxfile.hpp:203
bool fail(void) const
Checks if an error has been encountered, EOF set or set_fail called.
Definition hxfile.hpp:141
void operator=(hxfile &&file_) noexcept
Move assignment. No copy assignment operator is provided.
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:197
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:235
hxfile & operator>>(T &t_)
Reads a single unformatted native-endian object from a stream.
Definition hxfile.hpp:218
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:148
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:226
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:74
@ open_mode_in
Open for binary reading. e.g., "rb".
Definition hxfile.hpp:78
@ open_mode_out
Open for binary writing.
Definition hxfile.hpp:81
@ open_mode_asserts
By default, any unexpected failure is reported only through the failure flag.
Definition hxfile.hpp:86
@ open_mode_none
No flags.
Definition hxfile.hpp:76
uint8_t mode(void) const
Returns the current open mode of the file.
Definition hxfile.hpp:155
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:213
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:145
constexpr char hxendl[]
hxendl - Equivalent to std::endl without the flush.
Definition hxfile.hpp:42
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
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:125
#define hxinline_constexpr
hxinline_constexpr - Enables C++17 compatable "inline constexpr" usage for variables so they can be e...
Definition hxsettings.h:275
#define hxattr_printf(...)
hxattr_printf - Indicates to gcc that a function uses printf-style formatting so it can type-check th...
Definition hxsettings.h:117
#define hxattr_nonnull(...)
hxattr_nonnull - Indicates that a function has args that should not be null.
Definition hxsettings.h:106
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:98
#define hxattr_hot
hxattr_hot - Optimize a function more aggressively.
Definition hxsettings.h:94
Provides core macros, memory management and feature detection.