[#AutoFile] = AutoFile :mrdocs: Non‐refcounted RAII wrapper for FILE* == Synopsis Declared in `<streams.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class AutoFile; ---- == Description Will automatically close the file when it goes out of scope if not null. If you're returning the file pointer, return file.release(). If you need to close the file early, use autofile.fclose() instead of fclose(underlying_FILE). [NOTE] ==== If the file has been written to, then the caller must close it explicitly with the `fclose()` method, check if it returns an error and treat such an error as if the `write()` method failed. The OS's `fclose(3)` may fail to flush to disk data that has been previously written, rendering the file corrupt. ==== == Member Functions [cols="1,4"] |=== | Name| Description | xref:AutoFile/2constructor-0e.adoc[`AutoFile`] [.small]#[constructor]# | Constructors | xref:AutoFile/2destructor.adoc[`~AutoFile`] [.small]#[destructor]# | Close the wrapped file if still open, logging any close error. | xref:AutoFile/operator_assign.adoc[`operator=`] [.small]#[deleted]# | Deleted copy assignment; AutoFile is non‐copyable. | xref:AutoFile/Commit.adoc[`Commit`] | Wrapper around FileCommit(). | xref:AutoFile/IsNull.adoc[`IsNull`] | Return true if the wrapped FILE* is nullptr, false otherwise. | xref:AutoFile/SetObfuscation.adoc[`SetObfuscation`] | Continue with a different XOR key | xref:AutoFile/Truncate.adoc[`Truncate`] | Wrapper around TruncateFile(). | xref:AutoFile/detail_fread.adoc[`detail_fread`] | Implementation detail, only used internally. | xref:AutoFile/fclose.adoc[`fclose`] | Close the wrapped file early and return the C `fclose` result. | xref:AutoFile/feof.adoc[`feof`] | Return true if the end‐of‐file indicator is set on the wrapped file. | xref:AutoFile/ignore.adoc[`ignore`] | Skip `nSize` bytes from the file. | xref:AutoFile/operator_rshift.adoc[`operator>>`] | Deserialize an object from the file and return this wrapper. | xref:AutoFile/read.adoc[`read`] | Read raw bytes from the file into `dst`, applying deobfuscation. | xref:AutoFile/release.adoc[`release`] | Get wrapped FILE* with transfer of ownership. | xref:AutoFile/seek.adoc[`seek`] | Wrapper around fseek(). Will throw if seeking is not possible. | xref:AutoFile/size.adoc[`size`] | Return the size of the file. Will throw if unknown. | xref:AutoFile/tell.adoc[`tell`] | Find position within the file. Will throw if unknown. | xref:AutoFile/write.adoc[`write`] | Write raw bytes from `src` to the file, applying obfuscation. | xref:AutoFile/write_buffer.adoc[`write_buffer`] | Write a mutable buffer more efficiently than write(), obfuscating the buffer in‐place. | xref:AutoFile/operator_lshift.adoc[`operator<<`] | Serialize an object to the file and return this wrapper. |=== == Protected Data Members [cols="1,4"] |=== | Name| Description | xref:AutoFile/m_file.adoc[`m_file`] | Wrapped C file handle, or nullptr once released or closed. | xref:AutoFile/m_obfuscation.adoc[`m_obfuscation`] | XOR key applied to data as it is read or written. | xref:AutoFile/m_position.adoc[`m_position`] | Cached current file position, if known. | xref:AutoFile/m_was_written.adoc[`m_was_written`] | True once any data has been written through this wrapper. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#