Reflex C++

Reflex File

Higher-level file operations built on top of System::FileHandle. Provides path manipulation, file I/O helpers, and virtual filesystem support.

Path Utilities

Path checking, manipulation, splitting, and resolution functions, plus directory operations and system path lookup.

Path Constants

const kPathDelimiter; // Platform path separator

Path Checking

bool Exists(const WString& path);
bool IsDirectory(const WString& path);
bool CheckExtension(const WString::View& path, const WString::View& extension);

Path Manipulation

WString CorrectExtension(const WString::View& path, const WString::View& extension);
WString CorrectStrokes(const WString::View& path); // Normalize separators
WString CorrectTrailingStroke(const WString::View& path); // Ensure trailing separator
WString RemoveDuplicateStrokes(const WString::View& path);
WString::View RemoveTrailingStroke(const WString::View& path);

Path Splitting

Split a path into its constituent parts. Each returns a pair of views into the original string, avoiding allocation.

Pair<ArrayView<WChar>, ArrayView<WChar>> SplitExtension(const WString::View& path);
Pair<ArrayView<WChar>, ArrayView<WChar>> SplitFilename(const WString::View& path);

Path Resolution

WString MakeRelativePath(const WString::View& base_dir, const WString::View& path);
WString ResolveRelativePath(const WString::View& path);
WString::View ResolveExistingFolder(const WString::View& path);

System Paths

WString GetSystemPath(System::Path path);
Array<Pair<Array<WChar>, Array<WChar>>> GetVolumes(); // List mounted drives/volumes

Directory Operations

bool MakeDirectory(const WString& path);
void MakePath(const WString& path); // Create full directory chain
void DeleteDirectoryContent(const WString& path);
void DeletePath(const WString& path); // Recursive delete
bool Delete(const WString& path);
bool Rename(const WString& from, const WString& to);
bool Copy(const WString& from, const WString& to);

File I/O

Read and write files as whole buffers, streams, lines, or typed values. All stream-based functions operate on System::FileHandle.

Simple Read & Write

Load an entire file into memory or write a buffer to disk in a single call.

Data::Archive Open(const WString& path); // Read entire file
bool Save(const WString& filename, const Data::Archive::View& data); // Write entire file

Stream-Based I/O

Data::Archive ReadBytes(System::FileHandle& file_handle);
Data::Archive ReadBytes(System::FileHandle& file_handle, UInt32 bytes);
UInt32 WriteBytes(System::FileHandle& file_handle, const Data::Archive::View& bytes);
Data::Archive Peek(System::FileHandle& file_handle, UInt32 bytes); // Read without advancing
UInt64 GetRemainder(const System::FileHandle& file_handle); // Bytes remaining

Line-Based I/O

bool ReadLine(System::FileHandle& file_handle, CString& line_out);
bool ReadLine(System::FileHandle& file_handle, WString& line_out);
void WriteLine(System::FileHandle& file_handle, const CString::View& line);
void WriteLine(System::FileHandle& file_handle, const WString::View& line);

Typed Value I/O

bool ReadValue(System::FileHandle& file_handle, TYPE& value_out);
TYPE ReadValue(System::FileHandle& file_handle);
bool WriteValue(System::FileHandle& file_handle, TYPE value);

Copy & Memory Handles

Copy data between file handles, or create in-memory handles backed by Data::ArchiveObject.

bool Copy(System::FileHandle& from, System::FileHandle& to, UInt32 chunksize_opt);
TRef<System::FileHandle> CreateMemoryReader(ConstTRef<Data::ArchiveObject> data);
TRef<System::FileHandle> CreateMemoryWriter(TRef<Data::ArchiveObject> data);

Example

// Load a JSON config
auto jsonData = File::Open(L"settings.json");
auto config = Data::DecodePropertySet(Data::kJsonFormat, jsonData, 0);
// Save binary data
Data::Archive output;
Data::Serialize(output, myData);
File::Save(L"data.bin", output);

File Classes

Virtual filesystem classes that layer on top of the physical file system, providing resource bundling and path abstraction.

ClassInheritsPurpose
ResourcePoolObjectVirtual file system for bundled resources
VirtualFileSystemObjectLayered virtual filesystem