MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / BinaryFileStream

Class BinaryFileStream

Source/Falcor/Utils/BinaryFileStream.h:37–188  ·  view source on GitHub ↗

* Helper class to manage file I/O with binary files */

Source from the content-addressed store, hash-verified

35 * Helper class to manage file I/O with binary files
36 */
37class BinaryFileStream
38{
39public:
40 /**
41 * Mode to open file as
42 */
43 enum class Mode
44 {
45 Read = 0x1, ///< Open file for reading
46 Write = 0x2, ///< Open file for writing
47 ReadWrite = 0x3 ///< Open file for both reading and writing
48 };
49
50 /**
51 * Default constructor.
52 */
53 BinaryFileStream(){};
54
55 /**
56 * Constructor that opens a file
57 * @param[in] path Path of file to open or create
58 * @param[in] mode Mode to open file as
59 */
60 BinaryFileStream(const std::filesystem::path& path, Mode mode = Mode::ReadWrite) { open(path, mode); }
61
62 /**
63 * Destructor
64 */
65 ~BinaryFileStream() { close(); }
66
67 /**
68 * Opens a file stream. Fails if a file is already open.
69 * @param[in] path Path of file to open or create
70 * @param[in] mode Mode to open file as
71 */
72 void open(const std::filesystem::path& path, Mode mode = Mode::ReadWrite)
73 {
74 std::ios::openmode iosMode = std::ios::binary;
75 iosMode |= ((mode == Mode::Read) || (mode == Mode::ReadWrite)) ? std::ios::in : (std::ios::openmode)0;
76 iosMode |= ((mode == Mode::Write) || (mode == Mode::ReadWrite)) ? std::ios::out : (std::ios::openmode)0;
77 mStream.open(path, iosMode);
78 mPath = path;
79 }
80
81 /**
82 * Close the file stream.
83 */
84 void close() { mStream.close(); }
85
86 /**
87 * Skip data in an input stream. Advances file stream without reading.
88 * @param[in] count Bytes to skip
89 */
90 void skip(uint32_t count) { mStream.ignore(count); }
91
92 /**
93 * Deletes the managed file.
94 */

Callers

nothing calls this directly

Calls 3

writeFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected