YourGameLib
Loading...
Searching...
No Matches
Functions
yourgame::file Namespace Reference

file and path related functions More...

Functions

int readFile (const std::string &filename, std::vector< uint8_t > &dst)
 reads an entire file and returns it as a vector of bytes
 
int readAssetFile (const std::string &filename, std::vector< uint8_t > &dst)
 reads an entire file (from asset file location) and returns it as a vector of bytes
 
int readProjectFile (const std::string &filename, std::vector< uint8_t > &dst)
 reads an entire file (from project file location) and returns it as a vector of bytes
 
int writeFile (const std::string &filename, const void *data, size_t numBytes)
 writes numBytes bytes from data to a file called filename, destination path determined by prefix ("a//", etc.), see readFile(). overwrites the file if it exists.
 
int writeAssetFile (const std::string &filename, const void *data, size_t numBytes)
 writes numBytes bytes from data to a file called filename in the asset file location. overwrites the file if it exists
 
int writeProjectFile (const std::string &filename, const void *data, size_t numBytes)
 writes numBytes bytes from data to a file called filename in the project file location. overwrites the file if it exists
 
void setProjectPath (const std::string &path)
 sets path as current project directory
 
std::string getBasePath (const std::string &pathRelative="")
 returns the full (absolut) path to the executable (base), extended by pathRelative
 
std::string getAssetFilePath (const std::string &pathRelative="")
 returns the full (absolut) path to the assets directory, extended by pathRelative
 
std::string getProjectFilePath (const std::string &pathRelative="")
 returns the full (absolut) path to the current project directory, extended by pathRelative
 
std::string getFileLocation (const std::string &filepath)
 returns the location (path or prefix, such as a//) of a file, filepath points to
 
std::string getFileName (const std::string &filepath)
 returns the actual file name of a file, filepath points to
 
std::string getFileNameWithoutExtension (const std::string &filepath)
 returns the actual file name (w/o file extension) of a file, filepath points to
 
std::string getFileExtension (const std::string &filepath)
 returns the file extension
 
std::vector< std::string > ls (const std::string &pattern)
 returns list of directory content. accepts prefixes like readFile() does. accepts wildcard "*" for files (after last / in pattern)
 

Detailed Description

file and path related functions

Function Documentation

◆ getAssetFilePath()

std::string yourgame::file::getAssetFilePath ( const std::string &  pathRelative = "")

returns the full (absolut) path to the assets directory, extended by pathRelative

◆ getBasePath()

std::string yourgame::file::getBasePath ( const std::string &  pathRelative = "")

returns the full (absolut) path to the executable (base), extended by pathRelative

◆ getFileExtension()

std::string yourgame::file::getFileExtension ( const std::string &  filepath)

returns the file extension

  • example: "file1.bin" returns "bin"
  • example: "a//texture.png" returns "png"
  • example: ".gitignore" returns "gitignore"
  • example: "Makefile" returns ""

◆ getFileLocation()

std::string yourgame::file::getFileLocation ( const std::string &  filepath)

returns the location (path or prefix, such as a//) of a file, filepath points to

  • example: "file1.bin" returns ""
  • example: "a//file2.bin" returns "a//"
  • example: "/home/user/file3.bin" returns "/home/user/"

◆ getFileName()

std::string yourgame::file::getFileName ( const std::string &  filepath)

returns the actual file name of a file, filepath points to

  • example: "file1.bin" returns "file1.bin"
  • example: "a//file2.bin" returns "file2.bin"
  • example: "/home/user/file3.bin" returns "file3.bin"

◆ getFileNameWithoutExtension()

std::string yourgame::file::getFileNameWithoutExtension ( const std::string &  filepath)

returns the actual file name (w/o file extension) of a file, filepath points to

  • example: "file1.bin" returns "file1"
  • example: "a//file2.bin" returns "file2"
  • example: "/home/user/file3.bin" returns "file3"
  • example: "file4" returns "file4"
  • example: ".file5" returns ".file5"
  • example: "a//file6.tar.gz" returns "file6"
  • example: "a//file7" returns "file7"
  • example: "/home/user.a/file8.txt" returns "file8"

◆ getProjectFilePath()

std::string yourgame::file::getProjectFilePath ( const std::string &  pathRelative = "")

returns the full (absolut) path to the current project directory, extended by pathRelative

◆ ls()

std::vector< std::string > yourgame::file::ls ( const std::string &  pattern)

returns list of directory content. accepts prefixes like readFile() does. accepts wildcard "*" for files (after last / in pattern)

◆ readAssetFile()

int yourgame::file::readAssetFile ( const std::string &  filename,
std::vector< uint8_t > &  dst 
)

reads an entire file (from asset file location) and returns it as a vector of bytes

◆ readFile()

int yourgame::file::readFile ( const std::string &  filename,
std::vector< uint8_t > &  dst 
)

reads an entire file and returns it as a vector of bytes

  • prepend a// to load a file from asset file location
  • prepend p// to load a file from project file location
  • prepend none of the above to load a file with unchanged filename as path
  • example: loadFile("a//file1.bin" ...) // loads file1.bin from assets
  • example: loadFile("p//file3.bin" ...) // loads file3.bin from project file location
  • example: loadFile("file4.bin" ...) // loads file4.bin from working directory

◆ readProjectFile()

int yourgame::file::readProjectFile ( const std::string &  filename,
std::vector< uint8_t > &  dst 
)

reads an entire file (from project file location) and returns it as a vector of bytes

◆ setProjectPath()

void yourgame::file::setProjectPath ( const std::string &  path)

sets path as current project directory

◆ writeAssetFile()

int yourgame::file::writeAssetFile ( const std::string &  filename,
const void *  data,
size_t  numBytes 
)

writes numBytes bytes from data to a file called filename in the asset file location. overwrites the file if it exists

◆ writeFile()

int yourgame::file::writeFile ( const std::string &  filename,
const void *  data,
size_t  numBytes 
)

writes numBytes bytes from data to a file called filename, destination path determined by prefix ("a//", etc.), see readFile(). overwrites the file if it exists.

Attention
filename requires a prefix, such as "a//". otherwise, writing is omitted.

◆ writeProjectFile()

int yourgame::file::writeProjectFile ( const std::string &  filename,
const void *  data,
size_t  numBytes 
)

writes numBytes bytes from data to a file called filename in the project file location. overwrites the file if it exists