sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGXFile

see header file

see source file

class SGXFile;

part of SGEXTN module SG_FileSystem

file access in the form of reading and writing

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGXFile.h›

CMake target for BuildLah: SGEXTN::SG_FileSystem

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member variables

enum OpenStatus { NotOpen, ReadOnly, WriteOnly, FullAccess };

SGXFile::OpenStatus openStatus;

instance member functions

SGXFile(const SGXString& s, SGXFile::OpenStatus openMode);

[[nodiscard]] bool canRead() const;

[[nodiscard]] bool canWrite() const;

[[nodiscard]] long long getPointerLocation() const;

[[nodiscard]] SGLArray‹char› readAllBytes() const;

[[nodiscard]] bool readBool() const;

[[nodiscard]] SGLArray‹char› readBytes(long long n) const;

[[nodiscard]] char readChar() const;

[[nodiscard]] SGXColourHSLA readColourHSLA() const;

[[nodiscard]] SGXColourRGBA readColourRGBA() const;

[[nodiscard]] double readDouble() const;

[[nodiscard]] float readFloat() const;

[[nodiscard]] SGXIdentifier readIdentifier() const;

[[nodiscard]] int readInt() const;

[[nodiscard]] long long readLongLong() const;

[[nodiscard]] SGXChar readSGEXTNChar() const;

[[nodiscard]] SGXString readString() const;

[[nodiscard]] SGXTimeStamp readTimeStamp() const;

[[nodiscard]] unsigned int readUnsignedInt() const;

[[nodiscard]] unsigned long long readUnsignedLongLong() const;

[[nodiscard]] SGXVector2 readVector2() const;

void setPointerLocation(long long x) const;

void writeBool(bool x) const;

void writeBytes(const SGLArray‹char›& x) const;

void writeChar(char x) const;

void writeColourHSLA(SGXColourHSLA x) const;

void writeColourRGBA(SGXColourRGBA x) const;

void writeDouble(double x) const;

void writeFloat(float x) const;

void writeIdentifier(SGXIdentifier x) const;

void writeInt(int x) const;

void writeLongLong(long long x) const;

void writeSGEXTNChar(SGXChar x) const;

void writeString(const SGXString& x) const;

void writeTimeStamp(SGXTimeStamp x) const;

void writeUnsignedInt(unsigned int x) const;

void writeUnsignedLongLong(unsigned long long x) const;

void writeVector2(SGXVector2 x) const;

static member functions

static SGXString readAllText(const SGXString& filePath);

static void writeAllText(const SGXString& filePath, const SGXString& contents);

Detailed Description

SGXFile provides access to the file system by mainly reading from and writing into binary files. Support for text files exist but you can only read the whole file at a time. You should use binary files to store user data. The current location of the SGXFile pointer within the file is maintained and is moved automatically when reading or writing. This pointer can also be moved manually to follow offsets provided in the file.

Implementation Details

SGXFile wraps QFile and QDataStream with custom handling for SGEXTN structs.

enum OpenStatus { NotOpen, ReadOnly, WriteOnly, FullAccess };

Modes in which the file can be opened in. ReadOnly and FullAccess are read capable, WriteOnly and FullAccess are write capable.

Reading from the file in a non read capable mode or writing to the file in a non write capable mode will crash. Using the file in any way, including moving to a certain pointer offset, when it is in NotOpen mode will crash.

SGXFile::OpenStatus openStatus;

The mode that the file is currently open in.

Reading from, writing to, and modifying the pointer in a SGXFile with SGXFile::openStatus being NotOpen will crash.

SGXFile(const SGXString& s, SGXFile::OpenStatus openMode);

Creates a SGXFile object pointing to the file at path s and attempts to open it using the mode openMode.

If the file does not exist or cannot be opened due to a file system error, its SGXFile::openStatus will be set to NotOpen.

[[nodiscard]] bool canRead() const;

Returns if the file is open in a read capable mode.

If this is false, reading from the file will crash.

[[nodiscard]] bool canWrite() const;

Returns if the file is open in a write capable mode.

If this is false, writing to the file will crash.

[[nodiscard]] long long getPointerLocation() const;

Returns the current location of the file pointer as a byte offset from the start of the file.

If SGXFile::openStatus is NotOpen, this will crash.

[[nodiscard]] SGLArray‹char› readAllBytes() const;

Reads all data in the file as bytes.

This ignores the file pointer.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] bool readBool() const;

Reads a bool from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGLArray‹char› readBytes(long long n) const;

Reads n bytes at the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

This will crash if n is negative.

[[nodiscard]] char readChar() const;

Reads a C++ char from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXColourHSLA readColourHSLA() const;

Reads a SGXColourHSLA from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXColourRGBA readColourRGBA() const;

Reads a SGXColourRGBA from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] double readDouble() const;

Reads a double precision floating point number from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] float readFloat() const;

Reads a floating point number from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXIdentifier readIdentifier() const;

Reads a SGXIdentifier from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] int readInt() const;

Reads a int from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] long long readLongLong() const;

Reads a long long from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXChar readSGEXTNChar() const;

Reads a SGXChar from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXString readString() const;

Reads a SGXString from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXTimeStamp readTimeStamp() const;

Reads a SGXTimeStamp from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] unsigned int readUnsignedInt() const;

Reads a unsigned int from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] unsigned long long readUnsignedLongLong() const;

Reads a unsigned long long from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

[[nodiscard]] SGXVector2 readVector2() const;

Reads a SGXVector2 from the current position in the file.

This moves the file pointer forward.

If the file is not open in a read capable mode, this will crash.

void setPointerLocation(long long x) const;

Moves the file pointer to x bytes from the start of the file.

If x is more than the length of the file, the file will be extended as necessary.

If SGXFile::openStatus is NotOpen, this will crash.

Negative x will crash.

void writeBool(bool x) const;

Writes the bool x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeBytes(const SGLArray‹char›& x) const;

Writes all bytes in x at the current position in the file

This moves the file pointer forwards.

If the file is not open in a write capable mode, this will crash.

void writeChar(char x) const;

Writes the C++ char x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeColourHSLA(SGXColourHSLA x) const;

Writes the SGXColourHSLA x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeColourRGBA(SGXColourRGBA x) const;

Writes the SGXColourRGBA x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeDouble(double x) const;

Writes the double precision floating point number x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeFloat(float x) const;

Writes the floating point number x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeIdentifier(SGXIdentifier x) const;

Writes the SGXIdentifier x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeInt(int x) const;

Writes the int x at the current position in the file.

This moves the file pointer forward.

IIf the file is not open in a write capable mode, this will crash.

void writeLongLong(long long x) const;

Writes the long long x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeSGEXTNChar(SGXChar x) const;

Writes the SGXChar x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeString(const SGXString& x) const;

Writes the SGXString x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeTimeStamp(SGXTimeStamp x) const;

Writes the SGXTimeStamp x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeUnsignedInt(unsigned int x) const;

Writes the unsigned int x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeUnsignedLongLong(unsigned long long x) const;

Writes the unsigned long long x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

void writeVector2(SGXVector2 x) const;

Writes the SGXVector2 x at the current position in the file.

This moves the file pointer forward.

If the file is not open in a write capable mode, this will crash.

static SGXString readAllText(const SGXString& filePath);

Reads all text in the file at filePath and returns the text as a SGXString.

You are strongly encouraged to use binary files instead for better support and simplicity.

If filePath cannot be opened in a read only mode, this returns an empty string.

static void writeAllText(const SGXString& filePath, const SGXString& contents);

Overwrite the contents of the file at filePath with contents.

You are strongly encouraged to use binary files instead for better support and simplicity.

If filePath cannot be opened in a write only mode, this does nothing.

This irreversibly overwrites all data previously stored in the file.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects