Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
File Class Reference

#include <file.hpp>

Public Member Functions

 ~File ()
 
void flush () const
 
void close ()
 
void seek (int offset, Whence whence) const
 
int getSize () const
 
std::string getAsText ()
 
std::string getAbsolutePath ()
 
int getPosition ()
 
std::string getLine ()
 
bool eofReached () const
 
void storeString (const std::string &str)
 
void storeLine (const std::string &str)
 

Static Public Member Functions

static std::string getAbsoluteFilePath (const std::string &path)
 
static Fileopen (std::string path, const std::string &mode)
 
static int getFileSize (const std::string &path)
 
static bool fileExists (const std::string &path)
 
static std::string getFileAsText (std::string path)
 
static void fileCopy (const std::string &path1, const std::string &path2)
 
static void fileDelete (const std::string &path)
 
static void directoryCreate (const std::string &path)
 
static std::vector< std::string > directoryEnumerate (const std::string &path)
 

Public Attributes

std::string mode
 
std::string path
 

Detailed Description

File

Can be used to access the host filesystem. Generally, you would only want access to an app-specific folder (for save data, for example) or to the root of the app. So, that's exactly what you get!

When trying to access a file anywhere in calamity engine, you can use the user:// and res:// prefixes to access the user folder and the base folder of the app respectively:

File *save = File::open("user://savedata.txt", "r");
std::string saveText = save->getAsText();
Logger::info("save data: {}", saveText);
// Output: yeah
Definition file.hpp:47
static File * open(std::string path, const std::string &mode)
Definition file.cpp:56
std::string getAsText()
Definition file.cpp:131
static void info(fmt::format_string< Args... > fmt, Args &&...args)
Definition logger.hpp:28

You can also write to files:

File *save = File::open("user://savedata.txt", "a+");
save->seek(0, Whence::END);
save->storeString("yeah 2");
Logger::info("{}", save->getAsText());
// Output: yeah
// Output: yeah 2
void storeString(const std::string &str)
Definition file.cpp:183
void seek(int offset, Whence whence) const
Definition file.cpp:96

If you structured your project like was recommended in the getting started guide, you access your game assets like so:

Constructor & Destructor Documentation

◆ ~File()

File::~File ( )

Member Function Documentation

◆ close()

void File::close ( )

◆ directoryCreate()

void File::directoryCreate ( const std::string &  path)
static

◆ directoryEnumerate()

std::vector< std::string > File::directoryEnumerate ( const std::string &  path)
static

◆ eofReached()

bool File::eofReached ( ) const

◆ fileCopy()

void File::fileCopy ( const std::string &  path1,
const std::string &  path2 
)
static

◆ fileDelete()

void File::fileDelete ( const std::string &  path)
static

◆ fileExists()

bool File::fileExists ( const std::string &  path)
static

◆ flush()

void File::flush ( ) const

◆ getAbsoluteFilePath()

std::string File::getAbsoluteFilePath ( const std::string &  path)
static

◆ getAbsolutePath()

std::string File::getAbsolutePath ( )

◆ getAsText()

std::string File::getAsText ( )

◆ getFileAsText()

std::string File::getFileAsText ( std::string  path)
static

◆ getFileSize()

int File::getFileSize ( const std::string &  path)
static

◆ getLine()

std::string File::getLine ( )

◆ getPosition()

int File::getPosition ( )

◆ getSize()

int File::getSize ( ) const

◆ open()

File * File::open ( std::string  path,
const std::string &  mode 
)
static

◆ seek()

void File::seek ( int  offset,
Whence  whence 
) const

◆ storeLine()

void File::storeLine ( const std::string &  str)

◆ storeString()

void File::storeString ( const std::string &  str)

Member Data Documentation

◆ mode

std::string File::mode

◆ path

std::string File::path

The documentation for this class was generated from the following files: